Hi Davide,
The line below simply waits until a message is published on the
/initialpose topic. This is a blocking statement and the script
won't proceed until a message is received. Once the user sets the
initial pose in RViz, the corresponding pose message is published on
this topic and the script proceeds to the next two lines which are:
self.last_location = Pose()
rospy.Subscriber('initialpose',
PoseWithCovarianceStamped, self.update_initial_pose)
The first line just initializes the self.last_location variable for
later use. The second line subscribes to the /initialpose topic and
passes any received messages to the callback function
self.update_initial_pose which looks like:
def update_initial_pose(self, initial_pose):
self.initial_pose = initial_pose
So the callback simply sets the variable self.initial_pose to the
incoming message.
These lines have their equivalents in the C++ API. I suggest
looking at the online tutorial
Writing
a Simple Publisher and Subscriber (C++). In particular, you
will need the subscriber code.
As for Section 8.5.4, the nav_test.py script is run when the
fake_nav_test.launch file is run. ROS launch files can be used to
fire up nodes (scripts and binaries) and set parameters. If you
look near the end of the fake_nav_test.launch file, you will see
these lines:
<!-- Start the navigation test -->
<node pkg="rbx1_nav" type="nav_test.py"
name="nav_test" output="screen">
<param name="rest_time" value="1" />
<param name="fake_test" value="true" />
</node>
This is where the actual nav_test.py script is run while also
setting the parameters rest_time to 1 and fake_test = true. Note
that the nodes in a ROS launch file are not necessary run in the
same order as they appear in the launch file which is one of the
reasons we block the nav_test.py script until we receive a message
on the /initialpose topic.
Please see the
roslaunch
tutorial for more details on using ROS launch files.
As a general note, the ROS By Example books assume you have read
through the online
Beginner's
Tutorials that cover basics. These tutorials are well written
and cover both the Python and C++ APIs for the basic ROS concepts.
--patrick