Lesson 22: Edge Detector Robot

Lesson Description

In this lesson, you will learn how to build an Edge Detection Robot and make it move autonomously by coding it in PictoBlox. You will also learn to use the Ultrasonic Sensor to detect edges.

All About – Edge Detector Robot

As the name suggests, an Edge Detection Robot is an intelligent device that detects the edge or absence of a surface and avoids it by turning in different directions to prevent itself from falling off. For instance, an autonomous robot car uses edge detection technology to avoid falling off cliffs.

Edge Detection Robot detects the edge and proceeds along a path where the distance between the sensor and the surface is less than 10cm.

 

Assembly of the Robot

Let’s build the robot. We are taking the Horizontal Robot for reference to the start of the assembly.

  1. First, detach the Castor Wheel from the Quarky Robot by removing the Bolt.
  2. Then, attach both the B4 Plate and the Castor Wheel using the same Bolt.
  3. Push-fit servo motor into the B4 Plate such that the shaft is facing downwards and the ‘+’ mark is aligned with it.
  4. Connect the Servo Motor to the Quarky.
  5. Open PictoBlox and set the Servo Motor angle to 90 degrees. The servo head should get aligned properly.
  6. Push-fit the Ultrasonic Sensor into the B8 Plate.
  7. Push-fit the B8 Plate into the Servo Motor Shaft while keeping the Ultrasonic Sensor facing down.
  8. Connect the Ultrasonic Sensors to Quarky Robot.

The assembly is complete.

Logic & Flowchart

To avoid falling, our robot will change its path whenever it detects an edge by calculating the distance between the sensor and the surface. Let’s look at the logic in detail:

STEP 1: Our edge detector will move forward whenever the distance between the ultrasonic sensor and the surface should be less than 10cm.

STEP 2: Edge is detected when the distance between the ultrasonic sensor and the surface is more than 10cm. The robot stops detecting an edge.

STEP 3: The ultrasonic head turns to the left to check whether there is an edge on the left or not.

STEP 4: If there is no edge on the left, Quarky will change its direction to the left by turning left by 90 degrees. The ultrasonic head will get straight. And the robot moves ahead.

STEP 5: If there is an edge detected on the left side, the ultrasonic head turns to the right.

STEP 6: If no edge is detected, Quarky changes its direction to the right by turning right. The ultrasonic head will get straight. And moves ahead.

STEP 7: If it detects edges in all directions. Quarky will move backward.

Logic Flowchart

Below is the flowchart representation of our logic.

Coding Steps

Follow the steps below:

  1. Create a New file in PictoBlox App.
  2. Connect Quarky to PictoBlox.
  3. Initialize Robot:
    1. Drag and drop the when green flag clicked block from the Events palette.
    2. Create a block named – Initialize Robot. Place the block.
    3. Now, to initialize the pins go to the Sensors palette and add connect Ultrasonic () to trig (), echo ()  below the Initialize Robot hat block.
    4. The next step would be to set the initial servo angle as 90 degrees, for this drag and drop the set servo on () to () angle from the Robot palette
    5. Add go () at () % speed block. This time set the direction as forward, and the speed as 50%. This will make the robot go forward.
    6. Add wait () second below-go () at () % speed.
  4. Detecting Edge:
    1. Now, go to the Control palette and add a forever block below the Initialize Robot.
    2. After that, place the if () then block from the Control palette inside the forever block.
    3. Next, go to the Operators palette and put the ()>() block inside the space of the if () then block.
    4. Drag and drop the get ultrasonic () distance block from the Sensors palette within the first space of the () > () block and 10 in the second space. This block will help compare the sensor value and detect edges.
  5. Checking for Free Area:
    1. Next, create a block custom block named Set Servo Angle with Delay () block with Angle as the parameter.
    2. Put a set servo () to () angle block with the angle as Angle.
    3. After that add a delay of 0.5 seconds by introducing wait () seconds.
    4. Come back to the main script. Add the stop robot from the Robot palette. Add Set Servo Angle with Delay () block with angle set as 0 degrees. This condition will stop the robot and turn the servo’s angle to 0 degrees whenever an edge is detected.
    5. Now, we will check the maximum distance by adding if () then else block from the Control palette.
    6. Next, go to the Operators palette and put the ()<() block inside the if () then else block.
    7. Drag and drop the get ultrasonic () distance block from the Sensors palette within the first space of the ()<() block and 10 in the second.
    8. If the condition is satisfied, the robot should turn left. This can be done by adding go () at () % speed for () seconds block inside the if statement. Set the speed as 50%, and the time as 1.2 seconds.
    9. After that, duplicate the block from Set Servo Angle with Delay () block and place it in the else branch. Change the angle to 180 degrees and the robot’s direction to the right.
    10. Within the else-branch, add go () at () % speed for () seconds block. This time set the direction as backward, speed as 50%, and time as 0.5 seconds.
    11. Add another go () at () % speed for () seconds block. This time set the direction as left, speed as 80%, and time as 1.4 seconds. This will make the robot go reverse.
    12. Next, if our robot doesn’t get any edge, it should go forward. So, put the servo () to the () angle block at the end of the first if branch. Set the angle as 90 degrees.
    13. Lastly, place the go () at () speed () block. From the dropdown, select the direction as forward, and the speed as 50%.
  6. Finally, our robot is ready to run! Run the robot and check if it is working properly.
  7. Save the file as Edge Avoidance.

Activity: Output

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

 

Table of Contents