Back to Course

Class 6 - Coding, AI & Robotics Course

0% Complete
0/0 Steps
  1. Coding

    Session 1: Introduction to Coding
    3 Topics
  2. Session 2: Backdrop, Costume, and Animation
    3 Topics
    |
    1 Quiz
  3. Session 3: Basics of Algorithm and Flowchart
    3 Topics
    |
    1 Quiz
  4. Session 4: Basics of Pseudocode
    3 Topics
    |
    1 Quiz
  5. Session 5: Getting Started with Quarky
    3 Topics
    |
    1 Quiz
  6. Session 6: Variables: The Multitaskers
    4 Topics
    |
    1 Quiz
  7. Session 7: Arithmetic Operators
    4 Topics
    |
    1 Quiz
  8. Session 8: Conditional Statements
    3 Topics
    |
    1 Quiz
  9. Session 9: Logical Operators
    4 Topics
    |
    1 Quiz
  10. Session 10: Nested Conditional Statements
    2 Topics
    |
    1 Quiz
  11. Session 11: Loops
    3 Topics
    |
    1 Quiz
  12. Session 12: Touch Based Piano
    2 Topics
  13. Session 13: Criterial in Loops
    5 Topics
    |
    1 Quiz
  14. Session 14: Catch the Fruit Game - Part 1
    2 Topics
  15. Session 15: Catch the Fruit Game - Part 2
    2 Topics
    |
    1 Quiz
  16. Artificial Intelligence
    Section 16: Introduction to Artificial Intelligence
    3 Topics
    |
    1 Quiz
  17. Session 17: Basics of Face Detection
    2 Topics
    |
    1 Quiz
  18. Session 18: Face Expression Detection
    2 Topics
    |
    1 Quiz
  19. Session 19: Mimic Face with Quarky
    1 Topic
  20. Session 20: Face Filter - Part 1
    2 Topics
  21. Session 21: Face Filter - Part 2
    2 Topics
  22. Robotics
    Session 22: Basics of Robotics
    2 Topics
    |
    1 Quiz
  23. Session 23: Wirelessly Controlled Robot
    2 Topics
  24. Session 24: Introduction to Sensors
    3 Topics
    |
    1 Quiz
  25. Session 25: Introduction to Actuators
    3 Topics
    |
    1 Quiz
  26. Session 26: Face Tracking with Robot
    2 Topics
  27. Session 27: Obstacle Avoidance Robot - Part 1
    3 Topics
  28. Session 28: Obstacle Avoidance Robot - Part 2
    2 Topics
    |
    1 Quiz
  29. Session 29: Edge Detector Robot - Part 1
    3 Topics
  30. Session 30: Edge Detector Robot - Part 2
    2 Topics
    |
    1 Quiz
  31. Capstone Project
    Capstone Project
Lesson Progress
0% Complete

Now it’s time to program our own Obstacle Avoidance Robot! Follow the steps given below to make a script for the Obstacle Avoidance robot.

Initialize Robot

  1. Create two variables named Max, and Min from the Variables palette.
  2. Drag and drop the when green flag clicked block from the Events palette.
  3. Then, add the set () to() block. Set to Min to 5.
  4. Duplicate this block and set Max to 30So, we are basically initializing maximum and minimum distances of 30 cm and 5 cm.
  5. Create a block named – Initialize Robot. Place the block.
  6. Now, to initialize the pins go to the Sensors palette and add connect Ultrasonic ()  to trig (), echo()  below the Initialize Robot hat block.Note: Select the proper pins for echo and trig in the above block with respect to your connections.
  7. 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.
  8. Add wait () second below-set servo on () to () angle.

Detecting Obstacle

  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 Min variable in the second space. This block will help compare the sensor value with the minimum distance.

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 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 45 degrees. This condition will stop the robot and turn the servo’s angle to 45 degrees whenever an obstacle will come within the minimum distance range.
  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 Sensorspalette within the first space of the ()>() block and Max variable in the second. This block will help compare the sensor value with the maximum distance.
  8. If the condition is satisfied, the robot should turn right. This can be done by adding go () at () % speed for () seconds inside the if statement. Set the speed as 50%, and time as 0.6 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 135 degrees and the robot direction to left.
  10. Create a custom block named – Check Extreme. This block will check the conditions for 0 and 180 degrees. Add the block in the else branch.
  11. Next, if our robot doesn’t get any obstacles, it should keep going forward. So, for that, put the servo () to the () angle at the end of the first if branch. Set the angle as 90 degrees.
  12. Lastly, place the  go () at() speed() block. From the dropdown, select the direction as forward,  speed as 50%.

Checking Extreme Conditions

  1. Duplicate the block from Set Servo Angle with Delay () block with the value of 135 and place it below the Check Extreme block. Change the angle to 0 degrees and the robot direction to the right and the time to 1.2 seconds.
  2. 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 left.
  3.  Within the else-branch, add go () at ()% speed for () seconds block. This time set the direction as right, speed as 80%, and time as 1.5 seconds. This will make the robot go reverse.

Finally, our robot is ready to run!

Assignment

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

You must upload the PictoBlox program you created in this activity 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. Click on Browse.
  2. Search and Select your saved Project file(.sb3) and Click Open.
  3. Click on Upload to submit the assignment.
evive Alert
The file type allowed is the SB3 file generated from the PictoBlox program. The maximum file size allowed is 5 MB.

Good luck!