Activity: Roaming Rover
Program the rover to move around the room using the ultrasonic sensor to avoid running into obstacles. If the rover detects an object, turn away from the object and keep moving forward.
Relevant Coding Skills
Relevant Rover Concepts
Setup
When running the exercise, it can often work well to have a small obstacle course setup with flat surfaces like boxes and books for the rover to detect. The ultrasonic sensor works best against flat hard surfaces as it is detecting reflected sound waves. Angled or soft surfaces are harder to detect.
Here’s Our Approach
Stage 1
Use an IF statement block with a logic comparison block to check if the ultrasonic sensor detects an obstacle in front of the rover.
Stage 2
Use the IF ELSE block to turn when an obstacle is detected and drive forward when it is not detected using motor blocks.
Stage 3
Repeat this behaviour by wrapping everything in a while loop. While true will repeat forever.