do () action () times at () speed

Description

The block performs the selected action for the quadruped. The action runs for the specified times and at the specified speed.

Available Actions:

Available Speeds:

If you want to perform the action at a different speed, then you can use a variable to define the speed.

Example

Learn how to program a quadruped robot to perform predefined actions using PictoBlox.

Activity Description

In this activity, students will use the Quarky Quadruped kit to make their four-legged robot perform a series of cool dance and movement actions. This helps them learn how to control servo motors and sequence movements step by step. In the end, the robot returns to its home position, ready for the next show!

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. Drag and drop the “when green flag clicked” block from the Events palette.
  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.
  8. Add the “home” block right after setting pins.. This will bring the robot to its initial position before starting the dance.
  9. Add a wait block after home. This gives the robot time to move to home position before doing the next action.
  10. Add the “do action” block from the Robotics palette, select dance1, set times to 1, and speed to Medium.
  11. Add another “wait (0.5) seconds” block to allow time for the action to complete.
  12.  Repeat steps 10 and 11 seven more times and choose a different predefined action.
  13. Finally, to return the quadruped to its starting position, you can drag and drop the home position block.

Final Code

Output

Click the green flag and watch the robot perform the complete dance sequence step by step, returning to its home position at the end.

Read More
Learn how to create a dance sequence with Quadruped and Music using PictoBlox in this tutorial. With this tutorial.

Activity Description

In this activity, Quarky will do a fun dance when you press button L. It sets up the servo pins, goes to the home position, and then repeats a sequence of dance moves like waving, shaking, and moving up and down. Quarky also plays sounds and notes to match the actions, creating a cool dance performance!

Let’s Learn

In Stage Mode:

  1. The code runs on PictoBlox while Quarky is connected.
  2. You must keep Quarky connected with USB or Bluetooth for it to respond.

In Upload Mode:

  1. The code is uploaded to Quarky’s brain and runs independently.
  2. Once uploaded, Quarky will work without PictoBlox or your computer.

Let’s Code

Stage mode

When Quarky‘s left pushbutton is pressed, it will wait for 1 second and play a sound. After that, Quadruped will wave its right hand and move back to thehome position. Then Quarky will play different tones, and Quadruped will do different actions. Finally, Quadruped will move back to thehome position.

  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. Use the forever block so the instructions inside it keep repeating endlessly.
  10. Inside the forever loop, add the Play Sound block.
  11. Select the sound “Hi, I am Quarky” to make the robot speak every time the loop repeats.
  12. Add the do block after the sound block.
  13. Choose forward motion, set to 1 time, at medium speed.
  14. This makes the quadruped take one step forward each time the loop runs.
  15. Add the home block after the forward motion so the quadruped resets its legs to the home position after each step.
  16. Play note E5 for an eighth duration.
  17. Do the front back action 3 times at fast speed.
  18. Play note C4 for an eighth duration.
  19. Do the bodyshake2 action 3 times at fast speed.
  20. Play note D4 for an eighth duration.
  21. Do the bodyshake3 action 3 times at fast speed.
  22. Play note E4 for an eighth duration.
  23. Do the bodyshake4 action 3 times at fast speed.
  24. Play note C5 for an eighth duration.
  25. Do the updown1 action 3 times at fast speed.
  26. Add a final home block to bring the robot back to its default position at the end of each cycle.
  27. The forever loop repeats all the steps again and again, so Quarky will keep dancing and playing music!

Upload mode

You can also make the Quadruped dance work independent of PictoBlox using the Upload Mode. For that switch to upload mode and replace the when green flag clicked block with when Quarky starts up the block.

  1. Use the When Quarky Start up block instead of the green flag so the code runs automatically when Quarky powers on, not when you click the green flag.
  2. Inside the forever loop, add an if block to check if button L is pressed. This means the dance routine only happens when you press button L.
  3. After the if block starts, there’s a wait 1 second block to pause for 1 second before the dance begins.

Steps to Upload the Code in Upload Mode

  1. Use the USB cable to connect Quarky to your laptop or PC.
  2. Switch to Upload Mode. Click on the “Upload” tab at the top (next to “Stage” mode).
  3. This changes your workspace to Upload Mode, so your code runs directly on Quarky’s board.
  4. Check Your Code: Make sure your blocks or Python code are ready.
  5. Confirm you’ve used when Quarky Start up (instead of green flag) — this is needed for Upload Mode.
  6. Connect to the Right Port: Click on the “Connect” button and select Quarky’s COM port (it may show as “Quarky” or “Serial Device”).
  7. Click ‘Upload Code’: Once connected, click the “Upload Code” button.
  8. Wait for the program to compile and upload — you’ll see a progress bar or message saying “Upload Successful”.

Run the Program

  1. After uploading, disconnect the USB if you want.
  2. Turn Quarky ON — it will now run the uploaded code autonomously, without PictoBlox.

Output

Explore: Try to create your dance sequence.
Read More
Incorporate a fun activity into your artificial intelligence learning journey by using Humanoid robots to learn about face detection.

Introduction

As we start learning artificial intelligence, let’s make it more engaging by incorporating a fun activity. One of the most popular topics in AI is face detection, and we can make it even more exciting by learning it with the help of Humanoid robots. Are you interested in learning it together?

Code

Logic

  1. Simply drag and drop the RHip(), LHip(), RFoot(), LFoot(), RHand(), LHand() block from the Humanoid extension.
  2. Start the program by initializing the sprite and face detection library parameters.
  3. Use the forever loop block to create a continuous loop.
  4. If the camera detects more than one face, the Humanoid will move forward with a specific time, speed, and dance move with do() motion() times at () speed() block.
  5. If no face is detected, the Humanoid will move backward at a specific time and speed using do() motion() times at () speed() block.

Output

Read More
All articles loaded
No more articles to load
Table of Contents