Ask Your Question
1

Using roslaunch to launch ros nodes

asked 2017-07-19 16:21:41 -0500

Ryan_F gravatar image

updated 2017-07-19 16:22:35 -0500

I'm familiar with creating nodes from scratch by coding publishes and subscribers, but i'm not very familiar with roslaunch. Let's say i've downloaded a ros package off github, and this package contains several nodes. If i navigate the package and find the launch folder, i know that i can use

roslaunch parentfolder launchfile.launch

to run an individual launch file (and this usually launches some corresponding node). But if this package i've installed has 5 nodes, i have to run roslaunch 5 times, in 5 different terminals to simultaneously run all of these nodes. So i have two questions:

Can i use roslaunch to launch more than one .launch file at a time?

Will roslaunch only take .launch files, or can it be used to launch other types of files? (and as a follow up, i'm not really too familiar with ros .launch files, i know basic xml but i'd like to become more familiar so any links or resources to that effect would help a lot)

Thanks!

edit retag flag offensive close merge delete

Comments

You can also use launch files to load parameters and to launch nodes on different machines as well.

jayess gravatar imagejayess ( 2017-07-19 16:46:05 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-07-19 16:43:30 -0500

jayess gravatar image

Yes, you can use roslaunch to launch multiple nodes at once and you can even include other launch files (from other packages!) within a separate launch file. Let's use the turtlebot_simulator metapackage as an example.

Here's the code for the launch file that brings up a gazebo simulation of the turtlebot (turtlebot_world.launch) :

<launch>
  <arg name="world_file"  default="$(env TURTLEBOT_GAZEBO_WORLD_FILE)"/>

  <arg name="base"      value="$(optenv TURTLEBOT_BASE kobuki)"/> <!-- create, roomba -->
  <arg name="battery"   value="$(optenv TURTLEBOT_BATTERY /proc/acpi/battery/BAT0)"/>  <!-- /proc/acpi/battery/BAT0 --> 
  <arg name="gui" default="true"/>
  <arg name="stacks"    value="$(optenv TURTLEBOT_STACKS hexagons)"/>  <!-- circles, hexagons --> 
  <arg name="3d_sensor" value="$(optenv TURTLEBOT_3D_SENSOR kinect)"/>  <!-- kinect, asus_xtion_pro --> 

  <include file="$(find gazebo_ros)/launch/empty_world.launch">
    <arg name="use_sim_time" value="true"/>
    <arg name="debug" value="false"/>
    <arg name="gui" value="$(arg gui)" />
    <arg name="world_name" value="$(arg world_file)"/>
  </include>

  <include file="$(find turtlebot_gazebo)/launch/includes/$(arg base).launch.xml">
    <arg name="base" value="$(arg base)"/>
    <arg name="stacks" value="$(arg stacks)"/>
    <arg name="3d_sensor" value="$(arg 3d_sensor)"/>
  </include>

  <node pkg="robot_state_publisher" type="robot_state_publisher" name="robot_state_publisher">
    <param name="publish_frequency" type="double" value="30.0" />
  </node>

  <!-- Fake laser -->
  <node pkg="nodelet" type="nodelet" name="laserscan_nodelet_manager" args="manager"/>
  <node pkg="nodelet" type="nodelet" name="depthimage_to_laserscan"
        args="load depthimage_to_laserscan/DepthImageToLaserScanNodelet laserscan_nodelet_manager">
    <param name="scan_height" value="10"/>
    <param name="output_frame_id" value="/camera_depth_frame"/>
    <param name="range_min" value="0.45"/>
    <remap from="image" to="/camera/depth/image_raw"/>
    <remap from="scan" to="/scan"/>
  </node>
</launch>

This launch file includes both other launch files and several nodes. Here is how it includes other launch files:

<include file="$(find gazebo_ros)/launch/empty_world.launch">
    <arg name="use_sim_time" value="true"/>
    <arg name="debug" value="false"/>
    <arg name="gui" value="$(arg gui)" />
    <arg name="world_name" value="$(arg world_file)"/>
</include>

and here is how it includes other nodes:

<node pkg="robot_state_publisher" type="robot_state_publisher" name="robot_state_publisher">
    <param name="publish_frequency" type="double" value="30.0" />
</node>

You could simply include a launch file without args or params like this:

<include file="$(find package_name)/launchfile.launch"/>

or similarly for a node:

<node pkg="package" type="node_type" name="node_name"/>

Please refer to the roslaunch wiki entry for more details, or ask another question.

edit flag offensive delete link more

Comments

Thanks so much for this! All of those arguments that you have entered, are those some sort of argv commands passed into a .cpp or python file somehow?

Ryan_F gravatar imageRyan_F ( 2017-07-19 16:52:46 -0500 )edit

They're the way that you pass data from one launch file to another which can then set parameters or do some boolean checks. I suggest that you read about args at the wiki.

jayess gravatar imagejayess ( 2017-07-19 16:57:09 -0500 )edit

Also read about the parameter server and param tag. Knowing about these and how to use them will give you access to some of the power of using launch files.

jayess gravatar imagejayess ( 2017-07-19 17:00:22 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2017-07-19 16:21:41 -0500

Seen: 4,916 times

Last updated: Jul 19 '17