Going Forward and Avoiding Obstacles with Code
By this point you’ve cloned the github repository for this article series and successfully created a map (saved at /tmp/mymap
) of your current location. (If you have changed locations since the map generation article, create a new map.)
TurtleBot Without Obstacle Avoidance
Let’s run our first script again. On TurtleBot:
On the workstation run:
Your TurtleBot will be going forward. Intentionally stand in front of it and TurtleBot will crash into your feet. Press CTRL + C to stop it.
TurtleBot with Obstacle Avoidance
Manually orient TurtleBot so it can go forward 3 meters without crashing into anything. On TurtleBot run:
On the workstation run:
TurtleBot can’t reliably determine its initial pose (where it is) so we’ll give it a hint by using “2D Pose Estimate”. Select “2D Pose Estimate” and specify TurtleBot’s location. Leave RViz open so we can monitor its path planning.
TIP: After you estimate TurtleBot’s pose it can reliably know where it is even while traveling.
In a separate terminal run:
Try walking into the robot’s path while it is driving to see how it responds.
Why Does It Go in Circles?
TurtleBot is looking around for features, comparing them to the map and using that to determine where it is. This process is called localization. Here’s an excellent video on TurtleBot localization created by Melonee Wise:
Let’s have a look at the code:
It’s also available for viewing on GitHub.
Note that instead of saying “go forward for a few seconds” we’re saying “we want to end up at the location 3 meters forward regardless of what path takes us there”. TurtleBot can take up to 60 seconds to try and find a path to this location all with a few lines of code.