Lesson 12: Pamper your Robot Pet

Lesson Description

In this lesson, we will assemble the vertical robot, calibrate the IR sensors, and then use the data to make a Robo-Pet that reacts to hands and smiles when pampered.

Activity 1:  Assembling the Vertical Robot

We will see how to transform the Horizontal Robot into the Vertical Robot.

Coding Step

Follow the steps below:

  1. By far, your robot looks like this.
  2. Remove the Battery Holder Lock and then the Battery holder. Gently unsnap from the edges.
  3. Remove the Castor Wheel from the Robot.
  4. Attach Castor Wheel to the Castor Plate.

  5. Attach the Battery to the Robot.

  6. Snap the Caster Plate to the back side of the Robot as shown.
  7. Mount the Battery Holders and the Battery Holder Lock to secure the battery.

    Your robot is ready.

Activity 2: Making a Hand Detection System

In this activity, we will make the Quarky detect the hands.

Let us understand the IR Sensors. An infrared (IR) sensor is an electronic device that measures and detects infrared radiation in its surrounding environment. IR is invisible to the human eye.

Quarky has 2 IR sensors.

Let’s understand how they work.

An IR sensor consists of 2 LEDs: one which transmits the IR light and one which receives the IR light. When the IR rays are transmitted, they bounce from the nearest surface and get back to the receiver LED. That’s how an IR sensor detects an object.

We can get the sensor values in PictoBlox based on that value. We can estimate whether there is an obstacle.

  1. If the sensor detects nothing, its output value is increased. This means that the sensor is active.
  2. If it detects an obstacle, its output value decreases. This means that the sensor is inactive.

We need first to calibrate the IR sensors, i.e., make sure they’re working fine. For that, we’ll make a script in PictoBlox to calibrate them.

Coding Steps

Follow the steps below:

  1. Open PictoBlox App, go to My Space, and click on + button to create a new file.
  2. Connect Quarky to PictoBlox.
  3. Go to the Variables palette and create two variables named L and R.
  4. Next, make the following script to update the variable value to the left and right IR sensor values.
  5. You will notice that it appears in the top-left corner of the stage. We’ll use the variables to determine the threshold value for our IR sensors.
  6. Note the values of the Left and Right IR sensors when no obstacle is there in front of the robot. For example, in the above case:
    1. L_High = ­­­­­­__________
    2. R_High = __________
  7. Note the value of the Left and Right IR sensors when you put your hands in front of the robot:
    1. L_Low = __________
    2. R_Low = __________
  8. Next, do the average to get the threshold value:
    1. L_T = (L_High + L_Low)/2 = __________
    2. R_T = (R_High + R_Low)/2 = __________
  9. Remember these values.
  10. Getting Feedback via LEDs: Now, to check if the value works fine for our sensors, let’s add a feedback loop, something that will indicate that the sensor has detected the obstacle.
    1. Add a when flag clicked block from the Events
    2. Go to the Sensors palette and add two set () IR sensor thresholds to () block and write the threshold value you found before.
    3. Next, add a forever block from the Control We’re using this block because we want to check if the sensor detects the line continuously.
    4. Then, add an if-else block inside the forever
    5. Next, go to the Sensors palette and add an is () IR sensor active? block inside the white space of the if-else The IR sensor will be active when it detects the obstacle.
    6. To indicate that the sensor is active, let’s light up one of the LEDs of the dot matrix. From the Display palette, add a set LED x () y () to () with brightness () block under the if arm of the if-else Set the color as RED from the drop-down by clicking the color circle on the block.
    7. Duplicate the block and drop it under the else arm of the if-else Set the color as GREEN.
    8. Duplicate the if block and change the sensor to IR-R.
    9. Run the program and test the code.

 

 

Activity 3: Making a Robot-Pet

Make a robot pet that reacts when it is pampered with hands. The robot can detect the pampering using IR sensors, and act accordingly.

The objective is to make the robot execute certain actions when it detects a hand:

  • When the hand is detected on the Left sensor, turn left.
  • When the hand is detected on the Right sensor, turn right.
  • When the hand is detected on both the left and right sensors, introduce Quarky and smile.
  • When nothing is detected, do nothing.

Coding  Steps

Follow the steps below:

  1. Open PictoBlox App, go to My Space, and click on + button to create a new file.
  2. Connect Quarky to PictoBlox.
  3. Add a when flag clicked block from the Events
  4. Go to the Sensors palette and add two set () IR sensor thresholds to () block and write the threshold value you found in the last activity.
  5. Add set robot orientation as () block and set the orientation as vertical.
  6. Next, add a forever block from the Control We’re using this block because we want to check if the sensor detects the line continuously.
  7. Then, add an if-else block inside the forever
  8. Next, go to the Sensors palette and add an is () IR sensor active? block inside the white space of the if-else
  9. Duplicate the if block and put it inside the two branches of the if blocks. Change the value to IR-L.
  10. Now we have four branches all indicating four conditions. Let’s go over it one by one.
    1. The first case is when no hand is detected. Add a clear screen block from the Display
    2. The second case is when the IR-R sensor detects the hand. In this case, the robot will turn Left. Add go () at () % speed for () seconds block from the Robot Set the direction to left and time to 0.3 seconds.
    3. The third case is when the IR-L sensor detects the hand. In this case, the robot will turn Right. Add go () at () % speed for () seconds block from the Robot Set the direction to right and time to 0.3 seconds.
    4. Lastly, both sensors detect the hand. Make the Robot smile and play sound – Hi, I am Quarky using the play sound () until done
  11. The code is complete. Run and test it.  Save the file as Robo Pet.

Activity 3: Output

Make sure you finish and submit the assignment, as well as take the quizbefore moving on to the next lesson.

Table of Contents