Quarky Edge Detector Robot

Description
Learn how to build, code, and test an Edge Detection Robot using PictoBlox and Quarky. This robot can detect the edge and proceed along a path where the distance between the sensor and the surface is less than 10cm.

Introduction

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

The final structure of the robot will look like this:

 

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 B3 Plate.
  7. Push-fit the B3 Plate into the Servo Motor Shaft while keeping the Ultrasonic Sensor facing down.
  8. Connect the Ultrasonic Sensors to the Quarky Robot.
  9. Snap the A4 Plate to secure the wires.

The assembly is complete.

The Logic of the Robot

To avoid falling, our robot will change its path whenever it detects an edge by calculating the distance between the sensor and the surface. If the distance is more than 10 cm, that means an edge has been detected, and the robot will move in a different direction as a result.

Let’s look at the logic in detail:

  1. Our edge detector will move forward whenever the distance between the ultrasonic sensor and the surface is less than 10cm.
  2. Edge is detected when the distance between the ultrasonic sensor and the surface is more than 10cm. The robot stops detecting an edge.
  3. The ultrasonic head turns to the left to check whether there is an edge on the left or not.
  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.
  5. If there is an edge detected on the left side, the ultrasonic head turns to the right.
  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.
  7. If it detects edges in all directions. Quarky will move backward.

Flowchart

Below is the flowchart representation of our logic.

Coding Steps

Now it’s time to program our Edge Detector Robot! Follow the steps given below to make a script.

Initialize Robot

  1. Drag and drop the when 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 echo(), trig()  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 speed as 50%. This will make the robot go forward.
  6. Add wait () second below-go () at ()% speed.

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.

Checking for Free Area

  1. Next, create a block custom block named Set Servo Angle with Delay () 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 inside the if statement. Set the direction as left, 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 direction to 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 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, speed as 50%.

Finally, our robot is ready to run!

Testing

Run the robot and check if it is working properly.

Uploading the Code to Quarky

We can also upload the code to Quarky to make the robot run independently of PictoBlox. This we can do only on Laptop. Follow the steps:

  1. Switch to Upload Mode.
  2. Replace the when flag clicked block with when Quarky starts up block.
  3. Upload the Code with the Upload Code button.

That’s it. Now your robot can work independently.

Conclusion

In conclusion, this lesson has shown us how to build, code, and test an Edge Detection Robot. We have learned how to set up the robot using PictoBlox and upload the code to Quarky. This robot can detect the edge and proceed along a path where the distance between the sensor and the surface is less than 10cm.

Table of Contents