In this lesson, we’re about to perform a classic act of robotics – programming an obstacle avoiding robot. At first, this task may seem too complicated, but soon you will find that creating your first obstacle avoiding robot is surprisingly easy. 🙂
Preparations
- You will need the Rover.
- Connect the Rover with LOFI Blocks.
Programming
Here’s the algorithm we need to program to teach our robot, how to avoid obstacles:
- If you don’t see any obstacles, go forward.
- If an obstacle is close, turn.
Whether the robot will see an obstacle or not, we can define using readings from the distance sensor. Let’s assume that the robot won’t react to obstacles farther than 30 cm.
If you play that program, our robot will already be able to avoid obstacles. It will go forward if no obstacle is present, and if an obstacle is detected, the robot will turn.
All thanks to a simple program with a double condition IF/ELSE.
Let’s try to upgrade this mechanism:
- If you don’t see any obstacles, go forward.
- If an obstacle is close, turn.
- If there’s an obstacle close to you, go back.
In this case, we’ll define “close” as readings from the distance sensor between 30 and 10 cm. “Very close” will be defined as distance below 10 cm.
Because our algorithm has 3 conditions, we can’t use the block IF… ELSE. Instead we will use three single conditions. Our program will look like this:
And we’re done! Have fun with your obstacle avoiding robot!