GETTING STARTED
ROBOTICS
TAKING LEARNING TO THE REAL WORLD
CAPSTONE PROJECT

ACTIVITY: Making a Robo-Pet

Making a Robo-Pet – Overview

Now it’s time to make our AI Robo-Pet! The robo-pet should recognize the face, match it with the stored face, and if the face matches, it should follow the face.Learn AI with Quarky

How? Let’s have a look!

Understanding the Logic

We want our robo-pet to follow our face. For that, we need to define the ranges of our motion. Let’s define them.

If the x position of our face is less than -100, it means our face is on the extreme left. Therefore, our robo-pet should also move left.

If the x position of our face is greater than 100, it means our face is on the extreme right. Therefore, our robo-pet should also move right.

If the width of our face is less than 200, it means that our face is far away from the screen. Therefore, our robo-pet should move towards us.

Now, it’s time to code our robo-pet!

Let’s Code!

We will continue with the script we made for matching the face.

  1. First, make a custom block. Go to the My Blocks palette and make a block named Face Matching.
  2. Next, replace the when flag clicked hat block with the Face Matching hat block.Face Matching
  3. Till now, we have made the script to store the face and then match it. Now, it’s time to make the robo-fun follow our face once the face is matched. Thus, place a when flag clicked hat block from the Events palette into the scripting area.
  4. To make the face recognition more visible we’ll be showing a bounding box around the face of the user. But at the start of the script there should be no bounding block, thus from the Face Detection palette add () bounding box block and choose hide from the drop-down.
  5. Next, we will match the face, thus, drop the Face Matching stack block.
  6. Once the face is matched, we need to show the bounding box, thus drop () bounding box and select show from the drop-down.
  7. As we are working with the vertical robtot, we need to set the orientation. Thus, from the Robot palette, place set robot orientation as () block and select vertical from the drop-down.
  8. Place a forever block from the palette.
  9. Next to analyse the face, drop the analyse image from () block and choose camera.
  10. Now, let’s make the robo-pet follow us. Add an if-else block.
  11. Then, in its white space, add a () < () block from the Operators palette.
  12. In the first space of the () < () block, add a get () of face () block from the Face Detection palette. In the second space, write –100. If this condition is true, then our robo-pet should move left.
  13. Go to the Robot palette and drop a go () at () % speed for () seconds block under the if arm. Let the speed be 100%. Change the direction to the left and set the time to 0.2 seconds.
  14. Next, add another if-else block under the else arm of the first block. In the space of this if-else block, drop a () > () block.
  15. In the first space of the () > () block, add a get () of face () block from the Face Detection palette. In the second space, write 100. If this condition is true, then our robo-pet should move right.
  16. Go to the Robot palette and drop a go () at () % speed for () seconds block under the if arm. Let the speed be 100%. Change the direction to right and set the time to 0.2 seconds.
  17. Now, add an if block under the else arm of the second if-else block. In its white space, add a () < () block from the Operators palette.
  18. In the first space of the () < () block, add a get () of face () block from the Face Detection palette and select width from the first drop-down. In the second space, write 200. If this condition is true, then our robo-pet should move right.
  19. Go to the Robot palette and drop a go () at () % speed for () seconds block under the if arm. Let the speed be 100% and the direction forward. Set the time to 0.5 seconds.Robo Pet

Now, run the script by clicking the green flag and enjoy!

Assignment

Before you move on to the next lesson, a small assignment awaits you!

Make a video of the project you made in this activity and upload it to the website.

Submitting the assignment is a must in order to receive the certificate after completing the course.

Follow the steps below to upload your assignment:

  1. First, you need to choose the video file, thus click on Browse.
  2. Select your video file.
  3. And click the Upload button.

Good luck!

×
×

Cart