Taking a Photo Using Code
We have learned how to take a photo manually, but it is not very convenient. In this lesson we will learn how to take a photo using a script.
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 Script
1. Launch Gazebo.
2. Open a new terminal and change directory.
3. Launch script.
You will see this string in terminal:
4. See the results. Open the image file.
NOTE: You can use image viewer which you prefer. For instance, you can use eog which is GNOME image viewer.
5. Interrupt Gazebo. Close the terminals.
You can watch these steps in the video:
Using ROS Parameter
You can use ros parameter to change the title of the image. You can find the
line in the take_photo.py
:
The program fetches value from the parameter server. If the parameter is not set
it uses the default value photo.jpg
.
Let’s check if the parameter is set. We will look for /take_photo/image_title
parameter, because image_title
parameter is a private parameter (~
before
image title
) for take_photo
node. Launch.
The parameter is not set. Launch the program with parameter.
The title of the saved photo is new_title.jpg
. This command sets the
/take_photo/image_title
parameter. Let’s check if the parameter set.
Now the program will use the title from parameter server. Check the current value.
Launch the program without a parameter.
The title of the saved photo is new_title.jpg
. new_title.jpg
is the value
from ros parameter server.
There is a brief introduction of ros parameters. You can read more about ros parameters on wiki ros.