2

There are two different nodes one of them written in Python, and the other in C++. They are doing the same thing basically. Let's say they are finding banana with different methods like viola-jones or hog. So, their names are:

node 1: object_detector_hog_node

node 2: object_detector_viola_node

I want to assign parameter that selects which node will open. Is it possible to do such thing?

I know that it is not possible to use if in launch files. Also, I don't want to open two nodes and check the parameter and kill one of the nodes.

cagatayodabasi
  • 762
  • 11
  • 34

1 Answers1

8

Yes this is possible. For such a binary selection, it is easiest to use a bool argument:

<launch>
  <arg name="use_hog" default="true" />

  <group if="$(arg use_hog)">
    <node type="object_detector_hog_node" ... />
  </group>

  <group unless="$(arg use_hog)">
    <node type="object_detector_viola_node" ... />
  </group>
</launch>

When you launch it add the argument use_hog. To use hog run

roslaunch your_package object_detector.launch use_hog:=true

to use viola-jones run

roslaunch your_package object_detector.launch use_hog:=false

You can also omit the default value, then it will raise an error when you don't provide the argument.

For more information see the ROS wiki.

luator
  • 4,769
  • 3
  • 30
  • 51
  • You probably can also use the `if`/`unless` directly in the `node` tag, then you don't need the `group`. Using `group` has the advantage that you can do multiple things inside. – luator May 16 '17 at 13:10