Launch files

From Bike Wiki
Revision as of 18:34, 9 May 2020 by Jll329 (talk | contribs)
Jump to navigation Jump to search

What is is

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.


Example Annotated Launch files

// Specifies the xml version <?xml version="1.0"?> // Every launch file beings and ends with the <launch> and </launch> tags <launch>

   //<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>

</launch>

<?xml version="1.0"?> //Tag to indicate the start of a launch file. Should be included in every launch file <launch>

  //"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>

</launch>