Deprecated: Required parameter $query follows optional parameter $post in /var/www/html/wp-content/plugins/elementor-extras/modules/breadcrumbs/widgets/breadcrumbs.php on line 1215
Programming Quarky Humanoid Using Python in PictoBlox
[Humanoid]

Programming the Humanoid with Python in PictoBlox

Description
Learn how to install PictoBlox and program the Quarky Humanoid using Python in both Stage and Upload Modes. Understand how to use the Humanoid Python Library, and program the Humanoid to do predefined motions.

PictoBlox also provides the ability to program the Quarky Humanoid using Python in Desktop / Laptop versions. Let’s see how you can do it in this lesson.

PictoBlox

With PictoBlox, you can program the Humanoid to walk, dance, and make other cool moves! You can also create your own actions with special servo motors and servo oscillators.

If you haven’t installed PictoBlox, please follow the instructions:

Windows Installer (.exe)

STEP 1: Download the Pictoblox Installer (.exe) for Windows 7 and above (Release Notes).

STEP 2: Run the .exe file.

Some of the device gives the warning popup. You don’t have to worry, this software is harmless. Click on More info and then click on Run anyway.

STEP 3: Rest of the installation is straight forward, you can follow the popup and check on the option appropriate for your need.

 

Your software is now installed!

macOS Installer

STEP 1: Download the Pictoblox Installer (.dmg).

STEP 2: Run the .dmg file.

Mobile App Installer

STEP 1: Open Google Play Store on your Smartphone and and search for PictoBlox or visit the link here to head over to the Google Play Store. You can even scan the QR Code below from your Smartphone to head to the PictoBlox App.

STEP 2: Install the PictoBlox App.

Connecting Quarky with PictoBlox

Let’s begin by first connecting Quarky to PictoBlox. Follow the steps below for connecting Quarky to PictoBlox:

    1. First, connect Quarky to your laptop using a USB cable.
    2. Next, open PictoBlox on your desktop.
    3. After that, select Python Coding as your coding environment.
    4. Then, click the Board button in the toolbar and select Board as Quarky.
    5. Next, select the appropriate Serial port if the Quarky is connected via USB or the Bluetooth Port if you want to connect Quarky via Bluetooth and press Connect.
      COM Port
    6. Click on the Upload Firmware button. This will upload the latest firmware in Quarky.
      Note: If your device already has the latest firmware, then PictoBlox will show the message – Firmware is already updated. For learning more you can refer to this tutorial: https://ai.thestempedia.com/docs/quarky/quarky-toubleshooting/updating-quarky-firmaware-with-pictoblox/
    7. Once the firmware is uploaded, Quarky starts the Getting Started program. This runs only for the first time. Run through it.

And voila! Quarky is now connected to PictoBlox.

Humanoid Python Library for Stage Mode

Stage mode is one of the two modes you can write your programs in PictoBlox. In this mode, you can write scripts for the sprite and boards to interact with sprites in real-time. If you disconnect the board with PictoBlox, you cannot interact with the board anymore.

You can toggle between the upload mode and stage mode using the button on the top right side of PictoBlox.

In Python, use the following object declaration to use Python functions in Stage Mode:

humanoid = Humanoid(6, 1, 8, 3, 7, 2) 

Humanoid Python Library for Upload Mode

Upload mode allows you to write scripts and upload them to the board so that you can use them even when it is not connected to your computer, for example, you need to upload a script for making moving robots. In this case, Quarky will run offline according to the program and it cannot interact with the stage.

In Python, use the following object declaration to use Python functions in Upload Mode:

from quarky import *
from expansion_addon import Humanoid
rover = MarsRover(6, 1, 8, 3, 7, 2)

Python Functions

The following functions are available for use in the Humanoid library:


Warning: Undefined array key "pp_wrapper_link" in /var/www/html/wp-content/plugins/powerpack-elements/extensions/wrapper-link.php on line 194

Warning: Undefined array key "pp_wrapper_link_enable" in /var/www/html/wp-content/plugins/powerpack-elements/extensions/wrapper-link.php on line 196

Warning: Undefined array key "pp_custom_cursor_icon" in /var/www/html/wp-content/plugins/powerpack-elements/extensions/custom-cursor.php on line 350

Warning: Undefined array key "pp_custom_cursor_text" in /var/www/html/wp-content/plugins/powerpack-elements/extensions/custom-cursor.php on line 351

Warning: Undefined array key "pp_custom_cursor_target" in /var/www/html/wp-content/plugins/powerpack-elements/extensions/custom-cursor.php on line 352

Warning: Undefined array key "pp_custom_cursor_css_selector" in /var/www/html/wp-content/plugins/powerpack-elements/extensions/custom-cursor.php on line 353

Warning: Undefined array key "pp_custom_cursor_enable" in /var/www/html/wp-content/plugins/powerpack-elements/extensions/custom-cursor.php on line 355
The function creates an object to connect Quarky with Wi-Fi.
Syntax: wifi()
The function reads the analog value of the sensors connected to the specified pin. The function returns the int value between 0 to 4096.
Syntax: readanaloginput(pin = “A1”)
The function is used to control the state of the camera.
Syntax: video(video_state = “on”, transparency = 1)
The function moves its sprite forward the specified amount of steps in the direction it is facing. A step is equal to one-pixel length.
Syntax: move(steps = 10)
The function gives its sprite a speech bubble with the specified text — the speech bubble stays until another speech or thought block is activated, or the stop sign is pressed.
Syntax: say(message = “Hello!”, time = 0)
The function will play the specified sound, pausing its script until the sound has finished playing.
Syntax: playuntildone(sound_name = “Grunt”)
The function checks if its sprite is touching the mouse-pointer, edge, or another sprite. If the sprite is touching the selected object, the block returns true; if it is not, it returns false.
Syntax: istouching(object_name = “_edge_”)
The function is used when the sprite needs to produce a bitmap image of itself which is stamped onto the stage. (Because it is merely a picture of the sprite and not a sprite itself, it cannot be programmed). The function will not draw over sprites. 
Syntax: stamp()
The function sets the specified RGB LED of Quarky (specified with X and Y position of the LED) to the specified RGB color and brightness value.
Syntax: setled(x_position = 1, y_position = 1, color = [0, 0 , 0], brightness = 20)
The function returns the state of the specified push button. If the button is pressed it returns True or else False.
Syntax: readpushbutton(button = “L”)
The function moves the Quarky robot in the specified direction. The direction can be “FORWARD”, “BACKWARD”, “LEFT”, and “RIGHT”.
Syntax: runrobot(direction = “FORWARD”, speed = 100)
The function plays the specified audio on the Quarky speaker. The function does not have any callbacks, so other functions can be executed while this function is running.
Syntax: playsound(audio = “QuarkyIntro”)
This function helps turn the video on/off on the stage with a defined level of transparency.
Syntax: video(video_state = “on”, transparency = 1)
This function helps turn the video on/off on the stage with a defined level of transparency.
Syntax: video(video_state = “on”, transparency = 1)
The function sets a loudness filter threshold to remove the background noise from the audio file which is being analyzed.
Syntax: setthreshold(loudness = 30)
The function initializes the pick and place robot with the specified orientation.
Syntax: initialisepickplace(orientation = “HORIZONTAL”)
The function loads a model saved via model.save().
Syntax: tf.keras.models.load_model(filepath = ‘saved_model.h5’, custom_objects = None, compile = True, options = None)
The function initializes the quadruped robot object in Python and maps the 8 servos to the specified pins.
Syntax: Quadruped(Front Right Hip = 4, Front Left Hip = 1, Front Right Leg = 8, Front Left Leg = 5, Back Right Hip = 3, Back Left Hip = 2, Back Right Leg = 7, Back Left Leg = 6)
The function set the state of the relay connected to the selected pin to High or Low. A high state means that the pin will have 3.3V and for Low, the pin will be 0 V.
Syntax: setrelay(state = 1, pin = “D3”)
The function connects the Quarky or ESP32 to the specified Wi-Fi and password. The block is only available in the Upload Mode when the code is uploaded to Quarky.
Syntax: wifi.connecttowifi(WIFI = “Wi-Fi Name”, PASSWORD = “password”)
The function reports if the Wi-Fi is connected to the Quarky or ESP32 or not. This block is only available in Upload Mode.
Syntax: wifi.iswificonnected()
The function initializes the Mars Rover object in Python and maps the 5 servos to the specified pins.
Syntax: MarsRover(Head = 4, Front Left = 1, Front Right = 7, Back Left = 2, Back Right = 6)
The function initializes the humanoid robot object in Python and maps the 6 servos to the specified pins.
Syntax: Humanoid(Right Hip = 7, Left Hip = 2, Right Foot = 6, Left Foot = 3, Right Hand = 8, Left Hand = 1)
The Quarky Mecanum Robot Drive Motors are initialized by the function, which assigns each motor to a specific port. This allows the robot to be programmed to move the motors in the desired direction.
Syntax: Mecanum(Front Left = 1, Back Left = 2, Back Right = 7, Front Right = 8)
The function initializes the Expansion Board of Quarky for use. Without initialization, the board will not respond to any other functions.
Syntax: initexpansion()
The function returns the arc cosine of a number.
Syntax: math.acos(x)
This function performs the calibration process for a robotic arm by taking in the error angles of each of its three servos (link 1, link 2, and base). It then stores the offset angle for each servo to the memory of the Quarky, ensuring that the robotic arm is functioning correctly at all times.
Syntax: roboticArm.calibrate(Link1 Offset = 0, Link2 Offset = 0, Base Offset = 0)
This function ensures proper sensor alignment for precise line-following control.
Syntax: AdvanceLineFollowing(ir_num = 2)
The function sets the digital state of the specified pin to HIGH or LOW / 0V or 3.3V.
Syntax: setdigitaloutput(pin, state)
The function enables the automatic display of the box on face detection on the stage.
Syntax: enablebox()
All articles loaded
No more articles to load

Activity: Control Humanoid Predefined Motions in Python

In this project, we will explain how to run predefined motions in PictoBlox for the Humanoid in Python. The predefined motions allow users to make the robot move forward, backward, left, and right.

Stage Mode

Follow the steps:

  1. Open a new project in PictoBlox.
  2. Select the Python Coding mode.
  3. Connect Quarky to PictoBlox.
  4. Create the following code in Python editor:
    import time
    humanoid = Humanoid(6, 1, 8, 3, 7, 2)
    
    humanoid.home()
    humanoid.move("forward", 1000, 1)
    time.sleep(1)
    humanoid.home()
  5. Click on the Run button to run the motion sequence.

The function move() can have the following arguments for the moves: “forward”, “backward”, “left”, and “right”.

Explore: Try other motions.

Upload Mode

Follow the steps:

  1. Open a new project in PictoBlox.
  2. Select the Python Coding mode. Switch to Upload Mode.
  3. Connect Quarky to PictoBlox.
  4. Create the following code in Python editor:
    import time
    from quarky import *
    from expansion_addon import Humanoid
    import time
    
    humanoid = Humanoid(6, 1, 8, 3, 7, 2)
    
    humanoid.home()
    humanoid.move("forward", 1000, 1)
    time.sleep(1)
    humanoid.home()
  5. Click on the Upload button.
  6. Test the Humanoid. Try running other motions as well.

Conclusion

This concludes our lesson on how to program the Quarky Humanoid using Python in PictoBlox. We saw how to install PictoBlox, connect Quarky to PictoBlox, use the Humanoid Python Library in both Stage and Upload Modes, and program the Humanoid to do predefined motions. We hope you enjoyed the lesson, happy coding!

Table of Contents