Robotics StackExchange | Archived questions

Using substitutions with condition on LaunchConfiguration for ComposableNode

Trying to add some logic here. Working with a component container and not "simple nodes" seems to not work.

In this Using-Substitutions there is a way described by "condition=IfCondition(", as it seems to be impossible in python (not a big fan) to simply do something like

if (test_var == true ) : 
    # do something

This is a stripped down launch file

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.conditions import IfCondition
from launch.substitutions import LaunchConfiguration, PythonExpression
from launch_ros.actions import ComposableNodeContainer
from launch_ros.descriptions import ComposableNode

test_var = LaunchConfiguration('test_var')
test_var_arg = DeclareLaunchArgument(
    'test_var', default_value='False'
)

my_node = ComposableNode(
                        # condition=IfCondition(
                        #         PythonExpression([
                        #             test_var,
                        #             ' >= 2'
                        #         ])
                        #     ),
                        package='composition',
                        plugin='composition::Talker'
                    )

def generate_launch_description():
    return LaunchDescription(
        [
            ComposableNodeContainer(
                name='test_container',
                namespace='',
                package='rclcpp_components',
                executable='component_container_mt',
                composable_node_descriptions= [ my_node ],
                output='screen',
                emulate_tty=True
            )
        ]
    )

Commenting in the part

                    condition=IfCondition(
                            PythonExpression([
                                test_var,
                                ' >= 2'
                            ])
                        ),

Gives me

[ERROR] [launch]: Caught exception in launch (see debug for traceback): Caught exception when trying to load file of format [py]: ComposableNode.__init__() got an unexpected keyword argument 'condition'

Other threads like

did not help me much.

I would be much in favor of a simple

if (test_var == true ) : 
    # do something

but anything else that works would be also great. Maybe someone has a solution to this?

Asked by basti.hunter on 2023-08-03 09:18:29 UTC

Comments

Answers