This page will serve as a one stop shop for understanding the onboard and offboard launch files used for campus rover mark 3: 'Mutant' and 'Alien'. Along the way, it will also serve as a launch file tutorial in general.
This is a simple walkthrough of how to create a launch file: labnotebook/faq/launch_file_create.md
On-board is a short and rather simple launch file. Generally, a node should be run on-board if it meets one of two criteria:
The node interfaces directly with the hardware of the robot, and therefore must be onboard
The node is lightweight enough that it can run on the raspberry pi without causing too much strain to the cpu.
The line above launches the normal turtlebot bringup script. This makes the include
tag very useful, because it is the equivalent of a roslaunch
terminal command. In short - by using the include tag, a launch file can launch other launch files. The file
argument is the path to the launch file you want to include. $(find <package name>)
does what it says - finds the path to the specified package in your catkin workspace.
Here we see a node with parameters. This snippet launches the raspberry pi camera, which must be on-board in order to publish images captured by the camera. Often, the documentation on nodes like this will inform you of all the parameters and what their values mean.
The cpu checker node is also on-board, because it uses a python module to monitor the current cpu usage at any given time, then publish it as a ROS topic.
the talk service must be on-board so that it can produce audio through the robot's audio port.
pickup_checker and scan_filter are both lightweight nodes that are ideal for being included on-board. The state manager is also a rather small node, if you believe it or not - all it has to do is store the current state and make state changes.
rover_controller is arguably the anomaly - it does quite a bit to communicate with the web app and deal with navigation goals and completion. It could easily be moved off-board.
Here we see an arg defined on it's own, outside of a node launch. This behaves the same way as assigning a variable. The value can be accessed at any point in the launch file, as demonstrated below:
This snippet launches our custom navigation launch file, and you can see on line 2 how $(arg <arg name>)
passes the value. Since this value is only passed once, you could say in this case is is redundant, but you can image how if you had to use the value multiple times how it could be very useful.
This line uses a provided topic tool to throttle the publish rate of the given topic down to 2 hz. More importantly, $(env <var>)
is used to get the value of the given environment variable, which must be defined in .bashrc.
Now we see the use of remapping topics. This is very useful particularly in namespacing, as well as ensuring that a node is subscribed to the right topic for a certain kind of data - such as camera feed, in this case.
The final part of the file are all of the static transforms - these are entities that do not move with respect to their reference frame. The six numerical args are, in order, from left to right, x, y, z, yaw, pitch, roll. NOTE: the orientation of fiducials needs to be reviewed and corrected - though the positions are very accurate
Here is the key difference:
args are self-contined within launch files. They are defined and accessed only within launch files.
Params are how to pass values (such as args) into an executable node. They send values to the ROS parameter server. For a param to be accepted within a node, it must get the paramter from the server. Here is an example from rover_controller.py:
The <group>
tag allows for clusters of node to only be launched if the value passed to the group tag is true. A basic example is seen with modules like voice:
You can see that voice.launch is included only if the voice arg is true. the voice arg can be manually set to false to diable voice, as documented in the cr_ros_3 readme.
But what if your condition is based on something else? There is a way to evaluate operations in launch to a boolean. Observe:
eval
will take a python-evaluable boolean expression and evaluate it to true or false. This group above will only launch when the campus rover model is set to "ALIEN".
As you know, $(find <package name>)
will return the absolute path to the specified package, which allows for launch files from eternal packages to be included in your launch. A handy shortcut exists for launch files in the same package. Suppose A.launch and B.launch are in the same launch folder. A.launch can include B.launch like so using $(dirname)
:
This trick only works in ROS versions that are newer than Lunar.
Shell scripts can be run in roslaunch the same way nodes are launched. Here's an example:
The above example runs a script that will dynamically flip upside down raspberry pi camera's video output.