If clicking the above images doesn’t open the instructions, right-click on the image and choose “Save link as…” to download the PDF.
Object Detection
Design ways to avoid accidents between vehicles and objects in the road.
Connect
Think about:
- In what driving situations can a car hit an obstacle?
- What do you need to be aware of to avoid collisions with obstacles?
- What causes traffic jams in high density areas?
Construct
Build
Build a LEGO® MINDSTORMS® Education EV3 vehicle that can avoid accidents between vehicles and objects in the road. Start by constructing this model:
Build an obstacle for your robot to detect. You can build the cuboid model out of LEGO bricks or an obstacle of your choice.
Check
Before you program, check:
- Are all the wires correctly connected from the motors to ports B and C?
- Are the wheels correctly installed?
- Are the wheels rotating freely?
- Are the wires connected from the Ultrasonic Sensor to port 4?
Program
- Program your robot to detect any obstacles that might appear while the robot is moving forward (or backward).
- Make the robot stop when it detects an object that is less than 20 cm away.
Before you program, think about:
- How will you program the robot to detect obstacles?
- How will you program the robot to stop at obstacles?
- Which programming blocks will you use?
Sample Solution
- Start the program when EV3
enter
button is pressed. - Turn motors
B
andC
on at speed50
. - Wait until Ultrasonic Sensor detects an obstacle at a distance of less than
20
cm. - Stops all motors.
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
motors.largeBC.steer(0, 50)
pauseUntil(() => sensors.ultrasonic4.distance() < 20)
motors.stopAll()
})
Download and test
Click Download and follow the instructions to get your code onto your EV3 Brick. Press the center
button on the EV3 Brick to run the program.
Contemplate
On the road, when a driver sees and object, they slow their car down before coming to a full stop.
Program your EV3 Driving Base to do the same.
If the Ultrasonic Sensor:
- Detects an object less than
10
cm away, make the robot stop. - Detects an object between
10
and20
cm away, make the robot slow down. - Does not detect any object, continue to move at full speed.
Sample Solution
loops.forever(function () {
motors.largeBC.steer(0, 50)
if (sensors.ultrasonic4.distance() < 10) {
motors.stopAll()
} else if (sensors.ultrasonic4.distance() < 20) {
motors.largeBC.steer(0, 10)
}
})
Download and test
Click Download and follow the instructions to get your code onto your EV3 Brick. Press the center
button on the EV3 Brick to run the program.
Continue
- Get together with other building teams and make a traffic jam by placing all of your robots in a line with varying amounts of space between them.
- Have everyone start their robots at the same time and see what happens.
- Refine your programs so that all of the robots continue driving at the same speed with equal distances between them.
- Click on the JavaScript tab and experiment with changing the values in the code.
- Add a custom image or sounds from the Brick or Music menus.
Share
- Share what you think “efficiency in programming” means.
- Explore the different solutions other programmers came up with.
- Create a video of your project, especially your final presentation and your robot’s performance. Explain some important features of your software program.
- Include an image of your program with comments.
- Add a team photograph!
Congratulations! What will you design next?