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

I am not sure if it's better, but you could use sys.argv:

import sys

for arg in sys.argv:
    if arg.startswith("number_of_uavs:=")
        number_of_uavs = int(arg.split(":=")[1])

With this, the command suggested without explanation by @avzmpy works:

ros2 launch PKG_NAME LAUNCH_FILE number_of_uavs:=NUMBER

There is probably a prettier way to parse the argument :) You do have to use the := notation, because ros2 launch does not let any other through.


Having said this, this is not how I would do what you want to do, to launch multiple identical UAVs. I would limit the launch file to launch a single UAV, with a launch argument declared to pass the UAV ID, and a LaunchConfiguration using it. Then I would create another wrapper (bash) script around it that does the loop and calls ros2 launch multiple times to launch the required number of UAVs. When done that way, you can also launch each with a different value of ROS_DOMAIN_ID to make it impossible for them to mix communication without needing to use namespaces.

I am not sure if it's better, but you could use sys.argv:

import sys

for arg in sys.argv:
    if arg.startswith("number_of_uavs:=")
        number_of_uavs = int(arg.split(":=")[1])

With this, the command suggested without explanation by @avzmpy works:

ros2 launch PKG_NAME LAUNCH_FILE number_of_uavs:=NUMBER

There is probably a prettier way to parse the argument :) You do have to use the := notation, because ros2 launch does not let any other through.


Having said this, this is not how I would do what you want to do, to launch multiple identical UAVs. I would limit the launch file to launch a single UAV, with a launch argument declared to pass the UAV ID, and a LaunchConfiguration using it. Then I would create another wrapper (bash) script around it that does the loop and calls ros2 launch multiple times to launch the required number of UAVs. When done that way, you can also launch each with a different value of ROS_DOMAIN_ID to make it impossible for them to mix communication without needing to use namespaces.