Programming the Mars Rover with Python in PictoBlox

Description
Learn how to program the Mars Rover using Python in PictoBlox. Connect Quarky to PictoBlox, upload the firmware, and use the Python functions in Stage/Upload mode to explore the possibilities of robotics with Mars Rover.

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

PictoBlox

With PictoBlox, you can program the Mars Rover!

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.

Mars Rover 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:

rover = MarsRover(4, 1, 7, 2, 6)

Mars Rover 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 MarsRover
rover = MarsRover(4, 1, 7, 2, 6)

Python Functions

The following functions are available for use in the Mars Rover library:

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 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 makes the servo motors connected to the wheels orient inwards. This orientation is used for making the robot turn right and left efficiently.
Syntax: setinangle(Angle = 40)
The function makes the servo motors connected to the wheels orient towards the left. This orientation is used for making the robot turn left in a circle.
Syntax: setleftturnangle(Angle = 40)
The function makes the servo motors connected to the wheels orient towards the right. This orientation is used for making the robot turn right in a circle.
Syntax: setrightturnangle(Angle = 40)
The function sets the servo motors of the Mars Rover to the specified angles.
Syntax: setwheelsangle(Front Left = 90, Front Right = 90, Back Left = 90, Back Right = 90)
The function sets the servo motors of the head to the specified angle.
Syntax: setheadangle(Angle = 90)
All articles loaded
No more articles to load

Conclusion

In conclusion, PictoBlox provides an easy way to program the Mars Rover using Python in Stage and Upload modes. With the Mars Rover Python Library, users can control the rover in various ways and create awesome robot projects. Now it‘s time to get started with your own robot project!

Table of Contents