ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
![]() | 1 | initial version |
You also need to add your declared argument to the final LaunchDescription
that you return.
![]() | 2 | No.2 Revision |
You also One thing you need to do to expose the argument to the user is to add your declared argument it to the final LaunchDescription
that you return.return:
return LaunchDescription([arg_n_drones, *l_include_drown_spawn])
To use it in your launch file as a normal Python variable, you need to use OpaqueFunction
:
https://answers.ros.org/question/415825/can-i-programmatically-call-a-launch-file-with-arguments-that-can-be-used-as-a-variable-for-python-operations/
https://answers.ros.org/question/416438/adding-node-from-within-opaquefunction-in-ros2-python-launch-file/
That latter one includes a concrete example of using a declared launch argument to do N things. There are a couple of ways to access its string value. You can use a LaunchConfiguration
object inside your OpaqueFunction
and use LaunchConfiguration.perform(context)
:
https://github.com/danzimmerman/dz_launch_examples/blob/rolling/launch/opaque_multi_nodes.launch.py#L9
or you can access it by name from the context.launch_configurations
dictionary:
https://github.com/danzimmerman/dz_launch_examples/blob/rolling/launch/arg_examples.launch.py#L24
(This is what LaunchConfiguration.perform(context)
uses internally, see here).
![]() | 3 | No.3 Revision |
One thing you need to do to expose the argument to the user is to add it to the final LaunchDescription
that you return:
return LaunchDescription([arg_n_drones, *l_include_drown_spawn])
To use it in your launch file as a normal Python variable, you need to use OpaqueFunction
:
https://answers.ros.org/question/415825/can-i-programmatically-call-a-launch-file-with-arguments-that-can-be-used-as-a-variable-for-python-operations/
https://answers.ros.org/question/416438/adding-node-from-within-opaquefunction-in-ros2-python-launch-file/
That latter one includes a concrete example of using a declared launch argument to do N things. There are a couple of ways to access its string value. You can use a LaunchConfiguration
object inside your OpaqueFunction
and use LaunchConfiguration.perform(context)
:
https://github.com/danzimmerman/dz_launch_examples/blob/rolling/launch/opaque_multi_nodes.launch.py#L9
or you can access it by name from the context.launch_configurations
dictionary:
https://github.com/danzimmerman/dz_launch_examples/blob/rolling/launch/arg_examples.launch.py#L24
(This is what (LaunchConfiguration.perform(context)
uses accesses this internally, see here).
![]() | 4 | No.4 Revision |
One thing First you need to do to expose the add your declared argument to the user is to add it to the final LaunchDescription
that you return:
return LaunchDescription([arg_n_drones, *l_include_drown_spawn])
To use it in your launch file as a normal Python variable, I believe you need to must use OpaqueFunction
:
https://answers.ros.org/question/415825/can-i-programmatically-call-a-launch-file-with-arguments-that-can-be-used-as-a-variable-for-python-operations/
https://answers.ros.org/question/416438/adding-node-from-within-opaquefunction-in-ros2-python-launch-file/
That latter one includes a concrete example of using a declared launch argument to do N things. There are a couple of ways to access its string value. You can use a LaunchConfiguration
object inside your OpaqueFunction
and use LaunchConfiguration.perform(context)
:
https://github.com/danzimmerman/dz_launch_examples/blob/rolling/launch/opaque_multi_nodes.launch.py#L9
or you can access it by name from the context.launch_configurations
dictionary:
https://github.com/danzimmerman/dz_launch_examples/blob/rolling/launch/arg_examples.launch.py#L24
(LaunchConfiguration.perform(context)
accesses this internally, see here).
![]() | 5 | No.5 Revision |
First you need to add your declared argument to the final LaunchDescription
that you return:
return LaunchDescription([arg_n_drones, *l_include_drown_spawn])
To use it in your launch file as a normal Python variable, I believe you must use OpaqueFunction
:
https://answers.ros.org/question/415825/can-i-programmatically-call-a-launch-file-with-arguments-that-can-be-used-as-a-variable-for-python-operations/
https://answers.ros.org/question/416438/adding-node-from-within-opaquefunction-in-ros2-python-launch-file/
That latter one includes a concrete example of using a declared launch argument to do N things. There are a couple of ways to access its string value. You can use a LaunchConfiguration
object inside your OpaqueFunction
and use LaunchConfiguration.perform(context)
:
https://github.com/danzimmerman/dz_launch_examples/blob/rolling/launch/opaque_multi_nodes.launch.py#L9
or you can access it by name from the context.launch_configurations
dictionary:
https://github.com/danzimmerman/dz_launch_examples/blob/rolling/launch/arg_examples.launch.py#L24
(LaunchConfiguration.perform(context)
accesses this internally, see here).
![]() | 6 | No.6 Revision |
First you need to add your declared argument to the final LaunchDescription
that you return:
return LaunchDescription([arg_n_drones, *l_include_drown_spawn])
To use it in your launch file as a normal Python variable, I believe you must use OpaqueFunction
:
https://answers.ros.org/question/415825/can-i-programmatically-call-a-launch-file-with-arguments-that-can-be-used-as-a-variable-for-python-operations/
https://answers.ros.org/question/416438/adding-node-from-within-opaquefunction-in-ros2-python-launch-file/
That latter one second answer includes a concrete example of using a declared launch argument to do N things. There are a couple of ways to access its string value. You can use a LaunchConfiguration
object inside your OpaqueFunction
and use LaunchConfiguration.perform(context)
:
https://github.com/danzimmerman/dz_launch_examples/blob/rolling/launch/opaque_multi_nodes.launch.py#L9
or you can access it by name from the context.launch_configurations
dictionary:
https://github.com/danzimmerman/dz_launch_examples/blob/rolling/launch/arg_examples.launch.py#L24
(LaunchConfiguration.perform(context)
accesses this internally, see here).