Writing Your First Script
We can write a program and robot will do these instructions. In this lesson you will learn how to launch, create and modify a script. We will launch python script but it does not matter if you know this language or not.
Open a new terminal. Launch the empty world:
Launching a Script
You should do these instructions step by step:
1. Create a new directory.
2. Change directory.
3. Download sources.
NOTE: You need to have Github account to do this step.
4. Change directory.
5. Launch script.
6. The TurtleBot is going forward in Gazebo.
7. Press Ctrl+C
in the terminal to stop TurtleBot.
Creating and Modifying a Script
Now you will modify the existing script. TurtleBot will revolve on its axis.
1. Change directory.
2. Create a copy of goforward.py
.
3. Edit goincircles.py
.
NOTE: You can use editor which you prefer.
4. Modify linear.x
from 0.2 to 0 and angular.z
from 0 to 0.5.
NOTE: TurtleBot uses only linear.x
and angular.z
values because it
works in a planar (2D) world and it has a differential drive system which cannot
move laterally.
5. Press Ctrl+X
, then Ctrl+S
to save the changes. After saving is finished,
you will see a message like this:
Wrote /home/<user_name>/helloworld/turtlebot/goincircles.py
.
6. Press Ctrl+X
, then Ctrl+C
to exit Emacs.
7. Launch script.
8. TurtleBot is revolving on its axis.
9. Press Ctrl+C
in the terminal to stop TurtleBot.
Launching another Script
1. Change directory.
2. Launch script.
3. TurtleBot is drawing a square.
4. Press Ctrl+C
in the terminal to stop TurtleBot.
You can watch these steps in this video:
Open files goforward.py
and draw_a_square.py
and try to understand the
meaning of the commands reading the comments.
You can learn more about Python in this book or find basic online tutorial.