ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Launch files have limited built in run time decisions. There are, however, if and unless attributes for all tags. Combined with the arg tag, you could pass in an argument at launch time to conditionally run either node1 or node2 from the same launch file. Maybe you could rig up some code or a script to pass one argument if button1 is pressed and another argument if button2 is pressed.

Launch files have limited built in run time decisions. There are, however, if and unless attributes for all tags. Combined with the arg tag, you could pass in an argument at launch time to conditionally run either node1 or node2 from the same launch file. Maybe you could rig up some code or a script to pass one argument if button1 is pressed and another argument if button2 is pressed.

EDIT

Q: "So in my case an argument is a node, correct?" -@Astronaut

Not the node itself, but an arg on which node to launch. Something like:

<launch>
    <arg name="launch_node_1" default="true" />
    <node if="$(arg launch_node_1)" name="node1" .../>
    <node unless="$(arg launch_node_1)" name="node2" .../>
</launch>

Then a call of roslaunch my_file.launch launch_node_1:=true would launch node1 and a call of roslaunch my_file.launch launch_node_1:=false would launch node2

I've not yet used rqt_launch, but Dan is doubtless more experienced than I.

Launch files have limited built in run time decisions. There are, however, if and unless attributes for all tags. Combined with the arg tag, you could pass in an argument at launch time to conditionally run either node1 or node2 from the same launch file. Maybe you could rig up some code or a script to pass one argument if button1 is pressed and another argument if button2 is pressed.

EDIT

Q: "So in my case an argument is a node, correct?" -@Astronaut

Not the node itself, but an arg on which node to launch. Something like:

<launch>
    <arg name="launch_node_1" default="true" />
    <node if="$(arg launch_node_1)" name="node1" .../>
    <node unless="$(arg launch_node_1)" name="node2" .../>
</launch>

Then a call of roslaunch my_file.launch launch_node_1:=true would launch node1 and a call of roslaunch my_file.launch launch_node_1:=false would launch node2

I've not yet used rqt_launch, but Dan is doubtless more experienced than I.

EDIT 2:

Q: So in a script I have to call first the launch file than the arguments in that launch file, true??And possible to launch more than two nodes? Like button1 will run node1, button2 will run node2, button3 runs node3 etc..

Yes, you will launch the launch file to run any combination of any number of nodes you want, based on whatever arguments you pass in. A launch file is a one time thing, though. roslaunch will keep nodes alive if you tell it to, but it isn't constantly monitoring the status of the arguments. To run different nodes at different times, you shouldn't use a single launch file. It wasn't built for that.