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 turns the sprite by the specified amount of degrees clockwise. This changes the direction the sprite is facing.
Syntax: right(angle = 15)
The function gives its sprite a thought bubble with the specified text, which stays for the specified amount of seconds.
Syntax: think(message = “Hello!”, time = 0)
The function will play the specified sound, with no pause to its script.
Syntax: play(sound_name = “Grunt”)
The function removes all marks made by the pen or stamping. It is the only pen block that the Stage can use.
Syntax: clear()
The function turns off the specified RGB LED of Quarky (specified with the X and Y position of the LED).
Syntax: clearled(x_position = 1, y_position = 1)
The function returns the IR sensor analog reading. The reading varies from 0 to 4095.
Syntax: readirsensor(sensor = “IRL”)
The function moves the Quarky robot in the specified direction for the specified time. The direction can be “FORWARD”, “BACKWARD”, “LEFT”, and “RIGHT”.
Syntax: runtimedrobot(direction = “FORWARD”, speed = 100, time = 1)
The function plays the specified audio on the Quarky speaker. The function has a callback, so other functions will be executed after the audio is played.
Syntax: playsounduntildone(audio = “QuarkyIntro”)
This function is used to analyze the image received as input from the camera, for the feature.
Syntax: analysecamera()
This function is used to analyze the image received as input from the camera, for the handwritten and printed text.
Syntax: analysecamera()
When the function is executed, the recognition window will open and you will get a specified time during which PictoBlox will record whatever you say. Once recorded, the speech will be converted to the text of the language you spoke in and saved locally.
Syntax: analysespeech(time = 2, language = “en-US”)
The function sets the pick action angle with the specified angle. This is useful to set a custom pick angle for the pick and place robot.
Syntax: setpickangle(angle = 40)
The function returns a tensor with a length 1 axis inserted at the index axis.
Syntax: tf.expand_dims(input, axis = 0, name)
The function calibrates the angles of the servo motors and saves them in the memory of Quarky. Due to some mechanical assembly errors, there may be some misalignment of the servos which can be handled with this block.
Syntax: setoffset(Front Right Hip Offset = 0, Front Left Hip Offset = 0, Front Right Leg Offset = 0, Front Left Leg Offset = 0, Back Right Hip Offset = 0, Back Left Hip Offset = 0, Back Right Leg Offset = 0, Back Left Leg Offset = 0)
The function reports the state of the PIR sensor connected to the selected pin. The function returns 1 when it is HIGH (or 3.3V) or 0 when it is LOW (or 0V).
Syntax: pirstatus(pin = “D3”)
The function creates an Adafruit IO object that set up the API connection between the PictoBlox and the Adafruit server with the specified username and AIO key.
Syntax: adaio.connecttoadafruitio(username = “username”, AIO Key = “AIO key”)
The function calibrates the angle servo motors and saves them in the memory of Quarky. Due to some mechanical assembly errors, there may be some misalignment of the servos which can be handled with this block.
Syntax: setoffset(Head = 0, Front Left = 0, Front Right = 0, Back Left = 0, Back Right = 0)
The function calibrates the angles of the hip and foot servo motors and saves them in the memory of Quarky. Due to some mechanical assembly errors, there may be some misalignment of the servos which can be handled with this block.
Syntax: setlegoffset(Left Hip Offset = 0, Right Hip Offset = 0, Left Foot Offset = 0, Right Foot Offset = 0)
The function allows the robot to move in the specified direction at a given speed.
Syntax: runrobot(direction = “forward”, speed = 100)
The function sets the servo motor connected to the specified servo pin of the Quarky Expansion board to the specified angle. The expansion board can control up to 8 servos simultaneously.
Syntax: moveservo(servo port = 1, angle = 40)
The function is used to return the inverse hyperbolic cosine of a given value.
Syntax: math.acosh(x)
The function takes the current end–effector position and adds an offset value to it. It then updates the end–effector position in the length and Z directions according to the specified direction. The function also normalizes the end–effector position, ensuring that the calculated offset is applied consistently.
Syntax: roboticArm.setoffset(length Offset = 0, Z Offset = 0)
This function moves the robot forward and reverse for a set time, collecting IR sensor data on white and black lines.
Syntax: calibrateir()
The function disables the automatic display of the box on face detection on the stage.
Syntax: disablebox()
The function turns the sprite by the specified amount of degrees counter-clockwise. This changes the direction the sprite is facing.
Syntax: left(angle = 15)
The function changes its sprite’s costume to a specified one.
Syntax: switchcostume(costume_name = “Tobi Jump”)
The function will stop any sounds currently being played on all sprites and the Stage. Pressing the Stop button will also stop all sounds, but is rarely used as it also stops all the other scripts running in the project.
Syntax: stopallsounds()
The function reports the Euclidean distance, in pixels, between it and the mouse-pointer or a specified sprite’s costume center.
Syntax: distance(object_name = “_edge_”)
The function will make its sprite continuously pen a trail wherever it moves until the up() function is used. The color, size, and transparency of the trail can be changed with other functions.
Syntax: down()
The function reads the digital value of the sensors connected to the specified pin. The function returns True or False.
Syntax: readdigitalinput(pin)
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