Back to: Extras for “LEGO MindStorms EV3 Robots for Absolute Beginners”
One of the challenges in Tasmanian RoboCup Junior Rescue events is to avoid an obstacle that might stop your robot from being able to rescue a “person” from the “swamp”. Often this “obstacle” is a soft drink bottle filled with water, or it may be a lump of rock or a chunk of wood.
We have to think of some way to teach our robot to leave the line, go around this obstacle, and find the line again after it has passed the obstacle. We would like our robot to be able to behave something like this hand-controlled robot in the video below. The LEGO EV3 robot ambulance we use is inspired by Julia’s LEGO NXT Robot Ambulance (see her original at the bottom of this web page):
In the video above, you can see that Julia has added a touch sensor to her Robot Ambulance so that her Ambulance will be able to know that it has reached an obstacle. We now need to write code to use our own Robot’s touch sensor so that:
1. Our EV3 Robot knows when it meets an obstacle, and stops its motors
2. Our EV3 Robot goes backwards to give it enough room to turn away from the line
3. Our EV3 Robot turns away from the line, about 70 – 80 degrees
4. Our EV3 Robot starts moving forwards “around the obstacle”,
5. Our EV3 Robot stops moving “around the obstacle” when it finds the line on the other side of the obstacle
Sample Obstacle Avoidance Code
A sample code that works with our robot is shown below. You will see that we have connected our light sensor to slot 3. NOTE: Your code, light values, sensor and motor connections will probably be different, so be careful if you decide to follow this code!
Where would we place this obstacle avoidance code?
Following our previous tutorials, we could place this “Avoid Obstacle” (or “Avoid Water Tower”) code just before the “Line Follow Code”, as suggested below:
To see how to recreate these LEGO EV3-G commands in a way that will work with our one-color-sensor Robot, watch the video below.
After we added this code to our Rescue Challenge code, our robot avoided the obstacle, as shown in the video below:
Can we use other Sensors to Avoid an Obstacle?
Yes!
-
- An ultrasonic sensor can work beautifully, especially if the obstacle has a flat surface facing the robot (like the black or yellow obstacles pictured above). A round bottle (as often used in Tasmanian RoboCup events) is more difficult to detect, but students have built robots that work quite well if the ultrasonic sensor is placed at just the right height on the front of their robot – experiment with your robot build to see how the reliability of bottle detection varies with different ultrasonic sensor positions on your robot.
- An infrared sensor can also be used quite successfully to detect and avoid obstacles. However there can be problems, as some obstacles are not detected very well. If the obstacle is a clear bottle filled with clear water (as is often used in RoboCup competitions) the reflection from the water-filled obstacle is especially weak, and your robot may not detect the obstacle at all. One “experimental” solution is to change the obstacle – but unfortunately this is not an option in a RoboCup competition! The only solution in this case is to rebuild your robot to use a touch sensor or an ultrasonic sensor, as these both detect a wider range of obstacles than the infrared sensor.
- A touch sensor has been found by our students to be the most reliable option for detecting lots of different types of obstacles. Our students would suggest you try using a touch sensor first…
We hope that these hints will help you teach your Robot to avoid obstacles that have been placed on a line. Have fun!
I’m really enjoying the theme/design of your site. Do you ever run into any internet browser compatibility issues? A couple of my blog audience have complained about my site not operating correctly in Explorer but looks great in Safari. Do you have any suggestions to help fix this problem?|
Hi Talisha, thank you for your sharp eyes. There were minor problems on Safari on the Mac, & Internet Explorer on the PC. Hopefully both are fixed now. Your help is much appreciated, Graeme.