Computer Controlled Quadruped

Example Description
In this tutorial, you will learn how to control a quadruped robot using the arrow key program.

Activity Description

In this activity, you will control your quadruped robot using the arrow keys on your keyboard. The robot’s hip and leg pins are set up first, then it goes to the home position. Inside a forever loop, the robot checks which arrow key is pressed and moves in that direction. You can make the robot walk forward, backward, or move sideways left or right. You can also change the motion direction, number of times, and speed to see how your robot moves differently!

Let’s Code

Follow the steps

  1. Open the PictoBlox application from the Start Menu.
  2. Select the inviting realm of Blocks as your coding environment.
  3. Connect “Quarky” to your computer using a USB cable. Then, click the Board button in the toolbar and Select Board as Quarky.
  4. 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.
  5. Click on the Add Extension button and add the Quarky Quadruped extension.
  6. Add when flag clicked block from the Event Palette. This block helps you to start the script.
  7. To set up the quadruped, you can drag and drop pins for each leg and hip into the initialisation block using set pins FR Hip () FL Hip () FR Leg () FL Leg() BR Hip () BL Hip () BR Leg () BL Leg () blocks. This block sets which pins on the Quarky controller board control each servo motor for the front right (FR), front left (FL), back right (BR), and back left (BL) hips and legs. Drag this block and set each PIN as shown.  FR Hip: 4, FL Hip: 1, FR Leg: 8, FL Leg: 5, BR Hip: 3, BL Hip: 2, BR Leg: 7, BL Leg: 6.
  8. Add the home block to move the robot to its starting position.
  9. Add the if block. Check if the up arrow key is pressed. If true, do forward motion 1 time at medium speed.
  10. Press and hold the up arrow key on the keyboard and click the green flag in PictoBlox to make the quadruped move one step forward.
  11. Can you think of a block that would help the quadruped move continuously without needing to click the green flag each time?
    Alert:  Forever block is missing. This block helps us to keep checking which key is pressed.
  12. Use the forever block to keep checking which key is pressed.
  13. Inside the forever loop, add an if block. Check if the up arrow key is pressed. If true, do forward motion 1 time at medium speed.

    Output

  14. Add another if block. Check if the down arrow key is pressed. If true, do backward motion 1 time at medium speed.
  15. Add Controls for Left Arrow. Add another if block. Check if the left arrow key is pressed. If true, do lateral left motion 1 time at medium speed.
  16. Add Controls for Right Arrow. Add another if block. Check if the right arrow key is pressed. If true, do lateral right Motion 1 time at medium speed.

Run and Test

  1. Click the green flag and press the arrow keys to move the robot forward, backward, or sideways.
  2. Try changing the motion direction, number of times, or speed to explore different movements!

Final Output

Table of Contents