We have learned how to launch and modify existing python script in this lesson. We have learned how to send robot a command saying: “go forward until we send you a stop signal”. In this lesson we will learn more complicated command: “we want to end up at the location three meters forward regardless of what path takes us there”.

We will work with the files from github repository. You can find the information how to clone the github repository in “Writing Your First Script” lesson. We assume that your files are situated here ~/helloworld/turtlebot.

Launching Gazebo and Rviz

1. Launch Gazebo.

roslaunch turtlebot_gazebo turtlebot_world.launch

2. Run the navigation demo.

roslaunch turtlebot_gazebo amcl_demo.launch

3. Launch Rviz.

roslaunch turtlebot_rviz_launchers view_navigation.launch

4. Change the TurtleBot orientation.

Send a navigation goal to change TurtleBot orientation. It has to be facing the long object.

5. Change the TurtleBot position.

Send a navigation goal to stand TurtleBot in front of the object facing it. For example, like this:

Send a Navigation Goal

Position of TurtleBot before Launching the Script

Launching Script

1. Launch script.

python ~/helloworld/turtlebot/goforward_and_avoid_obstacle.py

2. See the results in Rviz.

TurtleBot will find a path and stop on another side of object.

3. Interrupt the processes. Close the terminals.

You can watch these steps in the video:

Going Forward and Avoiding Obstacles Using Code

After finishing the instructions open file goforward_and_avoid_obstacle.py and try to understand the meaning of the commands reading the comments.

NOTE: In the script goforward_and_avoid_obstacle.py there is also a restriction on the time of task execution (lines 50-51):

#allow TurtleBot up to 60 seconds to complete task
success = self.move_base.wait_for_result(rospy.Duration(60))