Extra – Avoiding an Obstacle

READ FIRST: If you are only looking for help in the code used to go around an obstacle during line following, watch the video above now. However if you want to understand more about how this code works and what the EV3-G code is actually doing to your LEGO EV3 robot’s behavior, then start reading the following information, delaying watching this video until you reach the red line of text below.

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 at the start of this web page now.

After we added this code to our Rescue Challenge code, our robot avoided the obstacle, as shown in the video below:

We hope that these hints will help you teach your Robot to avoid obstacles that have been placed on a line. Have fun!

2 thoughts on “Extra – Avoiding an Obstacle”

  1. 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?|

    1. 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.

Leave a Comment

Your email address will not be published. Required fields are marked *