Petoi Doc Center
🇺🇸English
Search
K

Petoi Coding Blocks

How to use the extension library specially developed for the Petoi robot in Mind+

Prepare Mind+

  • Download the latest version from Mind+ official website
    • Windows: >= V1.7.0
    • Mac: version: >= V1.7.3 RC2.0
  • After the installation is complete, you can open Mind+

Prepare Petoi Robot

  • For Nyboard products (Nybble, Bittle), there are two ways to upload the firmware - Mind+ mode, which supports the Mind+ extension library.
      • If you just downloaded a new version of this Desktop App. You should click the Upgrade the Firmware button. You can select 'N' to preserve the calibration values.
      • If you have upgraded the firmware at least once after a new download, You can click the Update the Mode Only button. It's faster to only switch the modes without refreshing the parameters.
    • Using the Arduino IDE Please download the latest code from GitHub. Follow the steps of uploading, set up the configuration mode, and activate this line of code in OpenCat.ino #define MAIN_SKETCH
      #define GROVE_SERIAL_PASS_THROUGH
      Then upload the major functionalities sketch and power on the robot. Use the data cable and USB uploader to connect with the computer or the Bluetooth module to complete the pairing.
    • Note that the gyroscope function is turned off with the Mind+ mode on NyBoard to save memory space. The robot won't be able to self-balance and auto-recover.
If you don't use the "Read or Write analog/digital pin" function block, you can upload the Standard mode sketch for Bittle / Nybble and use the Mind+ extension library. Note:
When the robot is in the Mind+ mode, the gyroscope function will be turned off, and the robot will not be able to balance or auto recover.
  • For BiBoard products (such as Bittle and Bittle X), there is no need to modify any software code. By default, all functional blocks in Mind+ are supported. At the same time, the gyroscope function is turned on; that is, the robot can self-balance and auto-recover.

Import Petoi Mind+ extension library

Paste the GitHub URL(https://github.com/PetoiCamp/Petoi_MindPlusLib) in the text box of the import interface:
For macOS (<=V1.7.2 RC3.0), you need to download PetoiRobot.zip and copy the extracted folder (PetoiRobot) to /Users/{your username}/Documents/mindplus-py/environment/Python3.6.5-64/lib/python3.6/site-packages/

Programming and Running

Petoi Coding Blocks is a user-extended library of Mind+.
If you open Mind+ by double-clicking the icon
, it will not automatically load this extension library, and you need to re-import it manually every time you open the app.
If you open Mind+ by double-clicking the code file(suffix mp or sb3) that uses this extension library, or load these code files after opening Mind+, Mind+ will automatically load this extension library.

The principle and process

This extension library can control the robot without compiling and uploading the code to the robot's main board. Click the "Run" button directly to run the program on the Python level and send instructions to the robot's serial port. If you need to stop the program while running, you can click the "Stop" button anytime. The process of the program can be divided into three steps:
  1. 1.
    Open the serial port
  2. 2.
    Control the robot
  3. 3.
    Close the serial port

The instructions for blocks

Open the serial port

There are two ways to open the serial port:
  • Automatically identify and open the serial port
  • Enter the name of the serial port to open the serial port
If it is failed to open the serial port, you can refer to the printed information in the terminal window to replace the name of the serial port:

Deactivate Gyro

When the gyroscope function is turned on, the robot can balance its body in real-time. It may be seen that when the robot is doing preset actions (especially when performing more violent actions), the body will shake back and forth, and even the body will tip over. The robot will automatically perform recovery actions, which may disrupt your preset steps.
If the uploaded sketch is Mind+ mode sketch(#define GROVE_SERIAL_PASS_THROUGH this line is activated), the gyroscope function will be turned off, and the robot will not be able to balance or auto recover, so there is no need to add this block.
If the robot is in standard mode, you'd better deactivate the Gyro after the serial port-opening block. It deactivates the gyroscope function to prevent the robot from performing balance feedback actions in real-time. For example:

Perform inherent skills

Use this block to let the robot perform skills pre-built on the robot's main board. From "sit" to "zero" are postures (contains only one action frame). From "boxing" to "sniff" are behaviors (contain multiple posture frames and are performed only once). From "stepping" to "trotRight" are gaits (contain multiple posture frames, and are repeated in periodical loops until stopped). With the delay setting in the block, the robot can be controlled to execute the next block function after the skill is done or doing (gait) and delay the preset time.

Perform the skill exported from the Skill Composer

Use this block to let the robot perform the skill exported from the Skill Composer.
It is equivalent to inputting the serial command 'T' in the serial monitor and then delaying the preset time.

Rotate joints in a sequence.

Use this block to control one joint or multiple joints to rotate in sequence. There are several ways to use the blocks for reference:
  • Controls individual joint rotations to an absolute angle value
  • Controls individual joint rotations to a relative angle value
  • Control multiple joints to rotate sequentially to absolute angle values or relative angle values
  • Use the joint angle list to control multiple joints to rotate to absolute angle values in a sequence.
With the use of the delay setting in the block, the robot can be controlled to execute the next block function after the action is done and delaying the preset time.
  • ,
    represents a list consisting of a joint index and an angle value. For example, [Head panning to 30 degrees] represents the list [0, 30].
  • It consists of one or more pairs of joint index + angle value, and the specific format is as follows: [joint index, angle value, joint index, angle value...]

Rotate joints simultaneously

Using this block can control multiple joints to rotate at the same time. There are several ways to use the blocks for reference:
  • Control multiple joints to rotate to absolute angle values or relative angle values at the same time
  • Use the joint angle list to control the simultaneous rotation of multiple joints to absolute angle values.
With the use of the delay setting in the block, the robot can be controlled to execute the next block function after the action is done and delaying the preset time.

Get the current angle value of a joint.

Use this block to get the current angle value of the selected joint. It is recommended to assign it to a variable first and then use the variable and algorithm to control other joints to rotate.
The return value of this block is only an angle value, which cannot be filled in the "Turn sequentially" and "'Turn simultaneously" blocks alone.
Demo code:
DemoEn.mp
278KB
Binary

Transform to frame

Use this block to control all joints to rotate at the same time. Please use it with the "Action frame" block. As shown below:
The "Action frame" block represents a list of 16 angle values. Each angle value corresponds to the absolute angle value to which the corresponding joint index servo rotates.
With the delay setting in the block, the robot can be controlled to execute the next block function after the action is done and delaying the preset time.

Play a melody

Use this block to control the robot to play music. There are several ways to use blocks together for reference:
  • A list made up of multiple "Tone + Duration" blocks
  • Using a tone duration list
Consists of one or more pairs of Tone + Duration, the specific format is as follows:
[tone, duration, tone, duration, tone, duration...]
With the delay setting in the block, the robot can be controlled to execute the next block function after playing the music and delaying the preset time.

Execute a serial command

Use this block to send a serial command to the robot, which can provide you with more and more flexible control methods. For example, you can input "kkcL" (kick the left front leg), and "khiR" (raise the right front leg to say hello). For more serial port commands, please refer to the serial protocol.
With the delay setting in the block, the robot can be controlled to execute the next block function after executing the serial command and delaying the preset time.

Write analog value

Use this block to write an analog value to a specified pin. Analog value range: 0~255

Read analog value

Use this block to read an analog value from a specified pin.

Write digital value

Use this block to write a high/low-level value to the specified pin. High-level: 1; Low-level: 0.

Read digital value

Use this block to read the high/low-level value of the specified pin.

Close the serial port

Generally, at the end of the program, it is recommended to use this block to close the serial port communication.

Demos

We provide some demos to download for reference in the GitHub repository (Petoi_MindPlusLib/examples).