Programming the Quadruped with Python in PictoBlox

Description
Learn how to program the Quadruped using Python in PictoBlox. Learn about Python functions. Toggle between upload and stage mode to interact with sprites and boards accordingly.

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

PictoBlox

With PictoBlox, you can program the Quadruped to walk, dance, and do 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.

Quadruped 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:

quad = Quadruped(4,1,8,5,3,2,7,6)

Quadruped 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 Quadruped
quad = Quadruped(4,1,8,5,3,2,7,6)

Python Functions

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

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 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 performs the selected motion for the quadruped. The motion runs for the specified times and at the specified speed.
Syntax: move(motion = “forward”, time period = 1000, cycle = 1)
The function performs the selected action for the quadruped. The action runs for the specified times and at the specified speed.
Syntax: action(action = “dance1”, time period = 1000, cycle = 1)
The function sets the servo motors of the quadruped to the specified angles at the specified speed.
Syntax: moveall(servo angles = [90,90,90,90,90,90,90,90], time = 1000)
The function sets the selected servo motor angle to the specified angle in the specified time. This creates a smooth motion for the servo motor from the current angle to the specified angle.
Syntax: movelimb(servo motor number = 1, angle = 90, time = 1000)
The block sets the oscillator parameters for the selected servo motor.
Syntax: setoscillationparameters(servo motor number = 1, amplitude = 30, offset = 90, time period = 1000, phase difference = 0)
The function resets the oscillator parameter for all the servo motors.
Syntax: resetoscillationparameters()
The function executes the oscillator according to stored parameters for the servo motor and the current time.
Syntax: executeoscillator()
The function executes the oscillator according to stored parameters for the servo motor and the current angle specified in the block.
Syntax: executesscillatorat(angle = 90)
The block resets the timer running for the oscillator to 0.
Syntax: resetoscillationtimer()
The function reports the time passed from the reset for the oscillator.
Syntax: oscillationtimer()
All articles loaded
No more articles to load

Activity: Control Quadruped Predefined Motions

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

Stage Mode

Follow the steps below:

  1. Create a New file in PictoBlox.
  2. Select the Python Coding mode.
  3. Connect Quarky to PictoBlox. Create the following code in the Python editor.
    import time
    quad = Quadruped(4, 1, 8, 5, 3, 2, 7, 6)
    
    quad.home()
    quad.move("forward", 1000, 1)
    time.sleep(1)
    quad.home()
  4. Click on the Run button to run the motion sequence.
Explore: Try to create a square using the Quadruped motion block.

Upload Mode

Follow the steps below:

  1. Create a New file in PictoBlox.
  2. Select the Python Coding mode. Switch to Upload Mode.
  3. Connect Quarky to PictoBlox. Create the following code in the Python editor.
    from quarky import *
    from expansion_addon import Quadruped
    import time
    
    quad = Quadruped(4, 1, 8, 5, 3, 2, 7, 6)
    
    quad.home()
    quad.move("forward", 1000, 1)
    time.sleep(1)
    quad.home()
  4. Click on the Upload button to upload the code in Quarky.

Test the Quadruped. Try running other motions with it as well.

Note:  The function move() can have the following arguments for the moves: “forward”, “backward”, “lateral left”, “lateral right”, “circular left”, “circular right”, “turn left”, “turn right”.
Table of Contents