Difference between revisions of "Launch files"
m (→Launch File!) |
|||
(10 intermediate revisions by 3 users not shown) | |||
Line 7: | Line 7: | ||
In order to utilize a launch file you have to run the roslaunch command. The roslaunch command takes in a launch file and determines what ROS nodes and nodelts need to start in order for the robot to function.<br>On the bike we use a shell script to launch all the appropriate launch files. See getting around the Pi for more information on the bike’s roslaunch setup. | In order to utilize a launch file you have to run the roslaunch command. The roslaunch command takes in a launch file and determines what ROS nodes and nodelts need to start in order for the robot to function.<br>On the bike we use a shell script to launch all the appropriate launch files. See getting around the Pi for more information on the bike’s roslaunch setup. | ||
− | + | ===Various Launch File Tags=== | |
− | ===Various Launch File | + | <code><launch></code> : Begins a launch file and contains everything in the launch file.<br> |
− | <launch> : Begins a launch file and contains everything in the launch file.<br> | + | <code><node></code> : Begins a ros node that needs to be started up<br> |
− | <node> : Begins a ros node that needs to be started up<br> | ||
Must be declared with a “pkg”, “type”, and “name” with more optional args<br> | Must be declared with a “pkg”, “type”, and “name” with more optional args<br> | ||
− | <machine> : Used to indicate what machine the ROS nodes should be run on if not locally.<br> | + | <code><machine></code> : Used to indicate what machine the ROS nodes should be run on if not locally.<br> |
− | <include> : Used to reference other launch files. This tag imports and args that the other has<br> | + | <code><include></code>: Used to reference other launch files. This tag imports and args that the other has<br> |
Must be declared with a “file”<br> | Must be declared with a “file”<br> | ||
− | <remap> : Used to rename the name of a topic/node.<br> | + | <code><remap></code> : Used to rename the name of a topic/node.<br> |
− | <env> : Used to create an environment variable for nodes<br> | + | <code><env></code> : Used to create an environment variable for nodes<br> |
Must be declared with a “name” and “value”<br> | Must be declared with a “name” and “value”<br> | ||
− | <param> : Used to declare a parameter value at the parameter server level.<br> | + | <code><param></code> : Used to declare a parameter value at the parameter server level.<br> |
Other nodes are able to access these parameters.<br> | Other nodes are able to access these parameters.<br> | ||
− | <rosparam> : Used to reference parameters declared in an external .YAML file<br> | + | <code><rosparam></code> : Used to reference parameters declared in an external .YAML file<br> |
Must be declared with “file” and “param”<br> | Must be declared with “file” and “param”<br> | ||
− | <group> Used to group multiple nodes together.<br> | + | <code><group></code> Used to group multiple nodes together.<br> |
Often used with ns to assign a name to the group.<br> | Often used with ns to assign a name to the group.<br> | ||
− | <test> : Used to run a ros node for testing purposes<br> | + | <code><test></code> : Used to run a ros node for testing purposes<br> |
− | <arg> : Used to define a local variable<br> | + | <code><arg></code> : Used to define a local variable<br> |
− | + | ||
===Example Annotated Launch Files=== | ===Example Annotated Launch Files=== | ||
Note: the lines with <code>//</code> are comments meant to help make sense of the file. | Note: the lines with <code>//</code> are comments meant to help make sense of the file. | ||
Line 35: | Line 34: | ||
<?xml version="1.0"?> | <?xml version="1.0"?> | ||
// Every launch file beings and ends with the <launch> and </launch> tags | // Every launch file beings and ends with the <launch> and </launch> tags | ||
− | < | + | <1aunch> |
//<arg name="some_name" default="some_name"> is used to read in an argument, and to use a default value if none is found | //<arg name="some_name" default="some_name"> is used to read in an argument, and to use a default value if none is found | ||
<arg name="svo_file" default="" /> | <arg name="svo_file" default="" /> | ||
Line 70: | Line 69: | ||
</include> | </include> | ||
</group> | </group> | ||
− | </ | + | </1aunch> |
</code> | </code> | ||
Line 77: | Line 76: | ||
<?xml version="1.0"?> | <?xml version="1.0"?> | ||
//Tag to indicate the start of a launch file. Should be included in every launch file | //Tag to indicate the start of a launch file. Should be included in every launch file | ||
− | < | + | <1aunch> |
//"arg name=" sets up variable names that can be referenced later in the launch file by using $(arg [given arg name]). | //"arg name=" sets up variable names that can be referenced later in the launch file by using $(arg [given arg name]). | ||
//See corresponding documentation to determine what to set the default value to | //See corresponding documentation to determine what to set the default value to | ||
Line 127: | Line 126: | ||
</node> | </node> | ||
</group> | </group> | ||
− | </ | + | </1aunch> |
</code> | </code> |
Latest revision as of 19:14, 12 December 2020
Contents
Launch File
What is is a Launch File
ROS launch files are used to Launch files are used to set up multiple ROS nodes at a single time and configure them. Launch files are written in a specific XML format and end with the .launch file extension.
How they are Used
In order to utilize a launch file you have to run the roslaunch command. The roslaunch command takes in a launch file and determines what ROS nodes and nodelts need to start in order for the robot to function.
On the bike we use a shell script to launch all the appropriate launch files. See getting around the Pi for more information on the bike’s roslaunch setup.
Various Launch File Tags
<launch>
: Begins a launch file and contains everything in the launch file.
<node>
: Begins a ros node that needs to be started up
Must be declared with a “pkg”, “type”, and “name” with more optional args
<machine>
: Used to indicate what machine the ROS nodes should be run on if not locally.
<include>
: Used to reference other launch files. This tag imports and args that the other has
Must be declared with a “file”
<remap>
: Used to rename the name of a topic/node.
<env>
: Used to create an environment variable for nodes
Must be declared with a “name” and “value”
<param>
: Used to declare a parameter value at the parameter server level.
Other nodes are able to access these parameters.
<rosparam>
: Used to reference parameters declared in an external .YAML file
Must be declared with “file” and “param”
<group>
Used to group multiple nodes together.
Often used with ns to assign a name to the group.
<test>
: Used to run a ros node for testing purposes
<arg>
: Used to define a local variable
Example Annotated Launch Files
Note: the lines with //
are comments meant to help make sense of the file.
This first file is a sample file given by the ZED ROS SDK
// Specifies the xml version
<?xml version="1.0"?>
// Every launch file beings and ends with the <launch> and </launch> tags
<1aunch>
//<arg name="some_name" default="some_name"> is used to read in an argument, and to use a default value if none is found
<arg name="svo_file" default="" />
<arg name="stream" default="" />
<arg name="node_name" default="zed_node" />
<arg name="camera_model" default="zed" />
<arg name="publish_urdf" default="true" />
<arg name="camera_name" default="zed" />
<arg name="base_frame" default="base_link" />
<arg name="cam_pos_x" default="0.0" />
<arg name="cam_pos_y" default="0.0" />
<arg name="cam_pos_z" default="0.0" />
<arg name="cam_roll" default="0.0" />
<arg name="cam_pitch" default="0.0" />
<arg name="cam_yaw" default="0.0" />
// The <group> tag is used for grouping multiple nodes together
// The ns field assigns a namespace. In this context, it is assigning a name to this new group.
<group ns="$(arg camera_name)">
// The <include> tag loads in from another launch file.
<include file="$(find zed_wrapper)/launch/include/zed_camera.launch.xml">
<arg name="camera_name" value="$(arg camera_name)" />
<arg name="svo_file" value="$(arg svo_file)" />
<arg name="stream" value="$(arg stream)" />
<arg name="node_name" value="$(arg node_name)" />
<arg name="camera_model" value="$(arg camera_model)" />
<arg name="base_frame" value="$(arg base_frame)" />
<arg name="publish_urdf" value="$(arg publish_urdf)" />
<arg name="cam_pos_x" value="$(arg cam_pos_x)" />
<arg name="cam_pos_y" value="$(arg cam_pos_y)" />
<arg name="cam_pos_z" value="$(arg cam_pos_z)" />
<arg name="cam_roll" value="$(arg cam_roll)" />
<arg name="cam_pitch" value="$(arg cam_pitch)" />
<arg name="cam_yaw" value="$(arg cam_yaw)" />
</include>
</group>
</1aunch>
This file is simmilar to previous one, however it introduces nodes and nodelets
<?xml version="1.0"?>
//Tag to indicate the start of a launch file. Should be included in every launch file
<1aunch>
//"arg name=" sets up variable names that can be referenced later in the launch file by using $(arg [given arg name]).
//See corresponding documentation to determine what to set the default value to
<arg name="camera_name" default="zed" />
<arg name="zed_nodelet_name" default="zed_nodelet" />
<arg name="svo_file" default="" />
<arg name="stream" default="" />
<arg name="base_frame" default="base_link" />
<arg name="publish_urdf" default="true" />
<arg name="camera_id" default="0" />
<arg name="gpu_id" default="-1" />
<arg name="cam_pos_x" default="0.0" />
<arg name="cam_pos_y" default="0.0" />
<arg name="cam_pos_z" default="0.0" />
<arg name="cam_roll" default="0.0" />
<arg name="cam_pitch" default="0.0" />
<arg name="cam_yaw" default="0.0" />
//Here is the portion of the launch file where the a nodlet manager is created
<arg name="nodelet_manager_name" default="$(arg camera_name)_nodelet_manager" />
//"group ns=" is used to create aliases to prevent collision in larger projects. You can reference the group by
writing "groupname/param_to_be_referenced"
<group ns="$(arg camera_name)">
//"node pkg=" initializes a node with the given parameters
//nodelets are groups of nodes that are grouped together for efficiency purposes
<node pkg="nodelet" type="nodelet" name="$(arg nodelet_manager_name)" args="manager" output="screen" />
//"include file=" is how you reference args declared in a different launch file
<include file="$(find zed_wrapper)/launch/include/zed_camera_nodelet.launch">
<arg name="nodelet_manager_name" value="$(arg nodelet_manager_name)" />
<arg name="camera_name" value="$(arg camera_name)" />
<arg name="svo_file" value="$(arg svo_file)" />
<arg name="stream" value="$(arg stream)" />
<arg name="node_name" value="$(arg zed_nodelet_name)" />
<arg name="camera_model" value="$(arg camera_model)" />
<arg name="base_frame" value="$(arg base_frame)" />
<arg name="publish_urdf" value="$(arg publish_urdf)" />
<arg name="cam_pos_x" value="$(arg cam_pos_x)" />
<arg name="cam_pos_y" value="$(arg cam_pos_y)" />
<arg name="cam_pos_z" value="$(arg cam_pos_z)" />
<arg name="cam_roll" value="$(arg cam_roll)" />
<arg name="cam_pitch" value="$(arg cam_pitch)" />
<arg name="cam_yaw" value="$(arg cam_yaw)" />
</include>
<node pkg="nodelet" type="nodelet" name="depthimage_to_laserscan" args="load depthimage_to_laserscan/DepthImageToLaserScanNodelet $(arg nodelet_manager_name)">
//similar to "arg name =" "param name=" sets values needed for a node to function"
<param name="scan_height" value="10"/>
<param name="output_frame_id" value="$(arg camera_name)_left_camera_frame"/>
<param name="range_min" value="0.1"/>
<remap from="image" to="$(arg zed_nodelet_name)/depth/depth_registered"/>
</node>
</group>
</1aunch>