Explorer: Avoid obstacles
The lesson teaches how the eXperiBot explores its environment and independently avoids obstacles.

Learn how to explore your surroundings with your eXperiBot while avoiding obstacles.
Model solutions
Unit 1
No program code is required for this unit. You must simply prepare the eXperiBot for operation, which means:
Assemble the eXperiBot completely
Establish a connection to the app
Unit 2
Solution file for download and import into the eXperiBot Blockly app.
Lesson contents
Unit 1
Connect your eXperiBot to the app.
Proceed as follows:
Switch on your eXperiBot.
Then press the “Connect” button at the top right of the screen. Follow the instructions to connect your eXperiBot to the app.



You’ve assembled your eXperiBot and connected it to the app—now you’re ready to go!
Unit 2
In order for your eXperiBot to drive like a modern car, it needs sensors. These help it to avoid obstacles in its surroundings.
Your eXperiBot then reacts appropriately. If something is in the way, for example, it automatically swerves out of the way.
The following module is called Multisensor.

This Multisensor enables your eXperiBot to detect objects or avoid obstacles.
The Multisensor emits invisible infrared light (IR light).
When this IR light hits an object, it is reflected back to the Multisensor.
If a lot of IR light is reflected back, the object is close.
If little or no IR light is reflected back, there is no object or it is further away.
This light signal allows the Multisensor to detect whether there is an object in front of it and how far away it is.
Light-colored objects reflect more light and are therefore detected earlier and more clearly than dark objects.
Attach a Multisensor to the front of the eXperiBot in the direction of travel.

If you want your eXperiBot to explore the room for as long as you like, these statements must be repeated over and over again.
To do this, drag the appropriate block from the “Loops” category into your editor.
If something needs to be repeated over and over again, you need an “infinite repeat” Loop.
Your eXperiBot should move forward for as long as you want.
To do this, select a suitable block from the “Motor” category.
Insert the block into the “Repeat forever” block.
Tip
Your program could now look like this:
Test your program by placing your eXperiBot on the floor in your room.

Change the time and speed.
Observe how these changes affect your eXperiBot’s driving.
Your eXperiBot explores the environment.
Your eXperiBot crashes into obstacles.
When your eXperiBot detects an obstacle, it should drive backwards.
The statement “drive backwards” therefore executes only when the eXperiBot detects an “obstacle”.
To do this, insert a suitable block from the “Logic” category in the correct place in your program.
You need a block that only executes statements if your eXperiBot detects an obstacle.
What is an “if-do” block?
This block only executes statements if a certain condition is true.
This is called a conditional block.
With a conditional block, you can control the flow of your program using conditions.
A condition can only be true or false.
If the condition is “true”, the program executes the statements; if it is “false”, the program skips them.
This feature lets your eXperiBot respond appropriately to different situations.
When do you need the “if—do” block?
Use it whenever you want your eXperiBot to respond differently in a situation:
If the condition is true, your eXperiBot executes the statement.
If the condition is false, your eXperiBot does not execute the statement.
How do you insert the “if—then” block?
Drag the “if—do” block from the “Logic” category into your program.

Top: Condition
Inside: Statement
When your eXperiBot detects an obstacle, it should drive backwards. At the beginning, your eXperiBot checks whether there is an obstacle. This check is repeated continuously.
The Multisensor can avoid obstacles. To do this, add a suitable condition from the “Multisensor” category to your program.
The Multisensor detects an obstacle as an object.
The “if-do” block executes a Statement if a condition is true.
Condition
Statement

What statement should your eXperiBot execute when it detects an obstacle?
To do this, add a suitable statement from the “Motor” category to your program.
If your eXperiBot only moves backward, that’s not enough. When it moves forward, it will bump into the obstacle again. You need a block that changes the direction of your eXperiBot—for example, “Motor drive a right backward curve”.
Test your program. To do this, place your eXperiBot back on the floor in your room. Place an obstacle on the floor at a slight distance, such as your backpack or a ball.

Does your eXperiBot avoid the obstacle? If not, adjust your program and try again.
Check the condition and the statement in your “if-do” block again.
Your eXperiBot explores its surroundings and avoids obstacles.

Unit 3
Modern cars use distance sensors to avoid obstacles early on.
The IR sensor in your eXperiBot’s Multisensor works in the same way to detect objects in front of it.
You can use the sensitivity setting to adjust the distance at which the IR sensor reacts.
Change the sensitivity in the block and test different values.
Try out very small and very large values. Test your program after each value.

Observe: How does your eXperiBot behave at very low and very high sensitivities?
Start with 100%—this is the normal value.
Change the sensitivity in small increments, for example, 20%, 50%, 150%.
Use a clearly visible obstacle, such as a pencil case.
Compare the results of your tests and decide which sensitivity works best.
Consider: At which value does your eXperiBot avoid obstacles best?
Complete the following in your mind:
The higher the sensitivity value, the…
The lower the sensitivity value, the…
Your eXperiBot now avoids obstacles at exactly the right time because you have tested and adjusted the sensitivity settings.

Unit 4
Cars use warning signals.
When a car detects an obstacle, warning lights flash or it emits a sound. This quickly alerts the person behind the wheel.
Your eXperiBot can do something similar: it can play a sound before avoiding an obstacle.
When your eXperiBot detects an obstacle, it should play a sound before avoiding it.
To do this, add a suitable block to your program.
Pay attention to the order of your blocks: first the sound, then the dodge.
Test your program. Run your eXperiBot and observe:
Does the sound play every time?
Can you hear the sound clearly?
Does your eXperiBot swerve correctly afterwards?

Your eXperiBot plays a sound before it dodges the obstacle.

Bonus unit 1
Work with a partner. You need two eXperiBots.
Place your eXperiBots on the floor. Leave enough space between them and align them so that they are facing each other. The two Multisensors should be pointing towards each other.

Test your “avoid obstacle” program. Check whether your eXperiBots recognize each other and avoid each other when they approach each other.

Does your program work in this situation? Adjust it if something is not working yet.
Hint
Adjust the sensitivity of the Multisensors. Experiment to find the settings that work best so that your two eXperiBots can detect each other.
Your eXperiBots recognize each other in good time and safely avoid collisions.

