Launchfile and Names Activity
Setup
Create a new workspace and clone the demonstration code
# Create a new workspace mkdir -p ws/src # clone the demonstration code cd ws/src git clone https://github.com/m-elwin/me495_counter.git counter # return to ws root cd ../
Build the workspace and activate it
- For each new terminal window that you open you will need to re-source the workspace
catkin_make source devel/setup.bash
Exploring Names
The counter
package provides several nodes (count_up
, count_down
, count_steady
and accumulator
).
The nodes that start with count_
publish on the count
topic.
The accumulator subscribes to count
and logs information.
- Run
roscore
- Run
rqt_graph
after each node that you run, refreshrqt_graph
to see the changes to the ROS graph- I recommend selecting Nodes/Topics (all) and un-checking Dead Sinks and Leaf topics
- Use
rosrun
to start an accumulator node and acount_up
node- What behavior do you see?
- Run a
count_down
node along with thecount_up
node that is already running- What behavior do you see?
- Use
rosnode kill
to kill thecount_up
node- What behavior do you see
- Try to running another
count_down
node. What happens? - Use the
__name
and remapping to run twocount_down
nodes simultaneously- What happens?
- Kill all the nodes that are running
- Use namespaces by setting the
ROS_NAMESPACE
environment variable to run two sets of nodes:- An accumulator subscribed to a count_up in the
up
namespace - An accumulator subscribed to a count_down in the
down
namespace - You can do
ROS_NAMESPACE=name rosrun <...>
to setROS_NAMESPACE
just for a singlerosrun
command - You can
export ROS_NAMESPACE=name
to set it permanently for a given terminal
- An accumulator subscribed to a count_up in the
- Run a
count_steady
node by specifying it's private parameter~val
to be 1 at the command line.- Run it in the global namespace
- Have it publish to the accumulator node running in the
down
namespace. - Note, the
~
in a private parameter is represented as an_
on the commandline - You will need to remap the
count
topic
- Kill all nodes.
- Use
rosparam
to set thecount_steady/val
parameter to 2 - Run a
count_steady
node and note what value it is publishing - Use
rosparam
to change thecount_steady/val
parameter to 5- Does the value published by
count_steady
change?
- Does the value published by
- Kill and re-run the
count_steady
node. What value is it publishing now? - Close all terminal windows to kill everything
Exploring Launchfiles
I'm sure you're tired of running all these nodes… Launchfiles to the rescue!
- Run
roslaunch counter count_nodes.launch
- Note,
roslaunch
startsroscore
automatically if it is not yet running
- Note,
- Run
rqt_graph
to see what nodes are running and how they are connected- What topics are being published and subscribed to
- Examine the source code for count_steady node and see if you can tell where the publishing happens.
- Examine count_nodes.launch
- How does the code in count_nodes.launch result in the graph that you see in rqt_graph?
- You can see what nodes a launchfile runs without actually running them by
executing
roslaunch --nodes counter count_nodes.launch
(notice the--nodes
flag)
- After listing the nodes, you can use this information to see the exact command that will be run to start a node:
roslaunch --args=/basic/accum1 counter count_nodes.launch
- Useful for debugging Launch files
- Explore
all.launch
to see how launchfiles can include other launchfiles - Explore
three_maybe.launch
to see the use of namespaces and conditional tags