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_graphafter each node that you run, refreshrqt_graphto see the changes to the ROS graph- I recommend selecting Nodes/Topics (all) and un-checking Dead Sinks and Leaf topics
- Use
rosrunto start an accumulator node and acount_upnode- What behavior do you see?
- Run a
count_downnode along with thecount_upnode that is already running- What behavior do you see?
- Use
rosnode killto kill thecount_upnode- What behavior do you see
- Try to running another
count_downnode. What happens? - Use the
__nameand remapping to run twocount_downnodes simultaneously- What happens?
- Kill all the nodes that are running
- Use namespaces by setting the
ROS_NAMESPACEenvironment variable to run two sets of nodes:- An accumulator subscribed to a count_up in the
upnamespace - An accumulator subscribed to a count_down in the
downnamespace - You can do
ROS_NAMESPACE=name rosrun <...>to setROS_NAMESPACEjust for a singlerosruncommand - You can
export ROS_NAMESPACE=nameto set it permanently for a given terminal
- An accumulator subscribed to a count_up in the
- Run a
count_steadynode by specifying it's private parameter~valto be 1 at the command line.- Run it in the global namespace
- Have it publish to the accumulator node running in the
downnamespace. - Note, the
~in a private parameter is represented as an_on the commandline - You will need to remap the
counttopic
- Kill all nodes.
- Use
rosparamto set thecount_steady/valparameter to 2 - Run a
count_steadynode and note what value it is publishing - Use
rosparamto change thecount_steady/valparameter to 5- Does the value published by
count_steadychange?
- Does the value published by
- Kill and re-run the
count_steadynode. 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,
roslaunchstartsroscoreautomatically if it is not yet running
- Note,
- Run
rqt_graphto 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--nodesflag)
- 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.launchto see how launchfiles can include other launchfiles - Explore
three_maybe.launchto see the use of namespaces and conditional tags