Back to Course
Class 6 - Coding, AI & Robotics Course
0% Complete
0/0 Steps
-
Coding
Session 1: Introduction to Coding3 Topics -
Session 2: Backdrop, Costume, and Animation3 Topics|1 Quiz
-
Session 3: Basics of Algorithm and Flowchart3 Topics|1 Quiz
-
Session 4: Basics of Pseudocode3 Topics|1 Quiz
-
Session 5: Getting Started with Quarky3 Topics|1 Quiz
-
Session 6: Variables: The Multitaskers4 Topics|1 Quiz
-
Session 7: Arithmetic Operators4 Topics|1 Quiz
-
Session 8: Conditional Statements3 Topics|1 Quiz
-
Session 9: Logical Operators4 Topics|1 Quiz
-
Session 10: Nested Conditional Statements2 Topics|1 Quiz
-
Session 11: Loops3 Topics|1 Quiz
-
Session 12: Touch Based Piano2 Topics
-
Session 13: Criterial in Loops5 Topics|1 Quiz
-
Session 14: Catch the Fruit Game - Part 12 Topics
-
Session 15: Catch the Fruit Game - Part 22 Topics|1 Quiz
-
Artificial IntelligenceSection 16: Introduction to Artificial Intelligence3 Topics|1 Quiz
-
Session 17: Basics of Face Detection2 Topics|1 Quiz
-
Session 18: Face Expression Detection2 Topics|1 Quiz
-
Session 19: Mimic Face with Quarky1 Topic
-
Session 20: Face Filter - Part 12 Topics
-
Session 21: Face Filter - Part 22 Topics
-
RoboticsSession 22: Basics of Robotics2 Topics|1 Quiz
-
Session 23: Wirelessly Controlled Robot2 Topics
-
Session 24: Introduction to Sensors3 Topics|1 Quiz
-
Session 25: Introduction to Actuators3 Topics|1 Quiz
-
Session 26: Face Tracking with Robot2 Topics
-
Session 27: Obstacle Avoidance Robot - Part 13 Topics
-
Session 28: Obstacle Avoidance Robot - Part 22 Topics|1 Quiz
-
Session 29: Edge Detector Robot - Part 13 Topics
-
Session 30: Edge Detector Robot - Part 22 Topics|1 Quiz
-
Capstone ProjectCapstone Project
Lesson 28,
Topic 1
In Progress
Programming
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
- Create two variables named Max, and Min from the Variables palette.
- Drag and drop the when green flag clicked block from the Events palette.
- Then, add the set () to() block. Set to Min to 5.
- Duplicate this block and set Max to 30. So, we are basically initializing maximum and minimum distances of 30 cm and 5 cm.
- Create a block named – Initialize Robot. Place the block.
- 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.
- 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.
- Add wait () second below-set servo on () to () angle.
Detecting Obstacle
- Now, go to the Control palette and add a forever block below the Initialize Robot.
- After that, place the if () then block from the Control palette inside the forever block.
- Next, go to the Operators palette and put the ()<() block inside the space of the if () then block.
- 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
- Next, create a block custom block named Set Servo Angle with Delay () with Angle as the parameter.
- Put a set servo () to () angle block with the angle as Angle.
- After that add delay of 0.5 seconds by introducing wait () seconds.
- 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.
- Now, we will check the maximum distance by adding if () then else block from the Control palette.
- Next, go to the Operators palette and put the ()>() block inside the if () then else block.
- 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.
- 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.
- 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.
- 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.
- 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.
- Lastly, place the go () at() speed() block. From the dropdown, select the direction as forward, speed as 50%.
Checking Extreme Conditions
- 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.
- 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.
- 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:
- Click on Browse.
- Search and Select your saved Project file(.sb3) and Click Open.
- Click on Upload to submit the assignment.
The file type allowed is the SB3 file generated from the PictoBlox program. The maximum file size allowed is 5 MB.
Good luck!