Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run condition for composable nodes #311

Merged
merged 6 commits into from
Apr 27, 2022

Conversation

adityapande-1995
Copy link
Contributor

@adityapande-1995 adityapande-1995 commented Apr 14, 2022

Signed-off-by: Aditya aditya050995@gmail.com

Summary

This PR adds the condition parameter to composable nodes action. Resolves #294. This action is currently supported by ComposableNodeContainer but not ComposableNode itself.

Example usage

One can use the following example file :

import launch
import launch.actions
from launch.conditions import IfCondition, UnlessCondition
from launch.substitutions import LaunchConfiguration
import launch_ros.actions
from launch_ros.actions import ComposableNodeContainer
from launch_ros.descriptions import ComposableNode

def generate_launch_description():
    return launch.LaunchDescription([
        launch.actions.DeclareLaunchArgument(name='flag', default_value='False'),
        ComposableNodeContainer(
            name='my_container',
            namespace='',
            package='rclcpp_components',
            executable='component_container',

            composable_node_descriptions=[
                ComposableNode(
                    package='composition',
                    plugin='composition::Talker',
                    condition=IfCondition(LaunchConfiguration('flag')),
                    name='talker_1'),

                ComposableNode(
                    package='composition',
                    plugin='composition::Talker',
                    condition=UnlessCondition(LaunchConfiguration('flag')),
                    name='talker_2'),

                ComposableNode(
                    package='composition',
                    plugin='composition::Talker',
                    name='talker_3'),
            ],
            output='screen',
        ),
    ]) 

or alternatively as an xml,

<launch>
        <arg name="flag" default="false"/>
        <node_container pkg="rclcpp_components" exec="component_container" name="my_container" namespace="">
                <composable_node pkg="composition" plugin="composition::Talker" name="talker_1" if="$(var flag)" />
                <composable_node pkg="composition" plugin="composition::Talker" name="talker_2" unless="$(var flag)" />
                <composable_node pkg="composition" plugin="composition::Talker" name="talker_3" />
        </node_container>
</launch>

Running this as ros2 launch test.py flag:=True will make it launch talker_1 and talker_3, and False will make it launch talker_2 and talker_3.

Signed-off-by: Aditya <aditya050995@gmail.com>
@adityapande-1995 adityapande-1995 self-assigned this Apr 14, 2022
@adityapande-1995 adityapande-1995 added the enhancement New feature or request label Apr 14, 2022
Signed-off-by: Aditya <aditya050995@gmail.com>
Signed-off-by: Aditya <aditya050995@gmail.com>
@adityapande-1995 adityapande-1995 marked this pull request as ready for review April 22, 2022 20:21
Copy link
Member

@ivanpauno ivanpauno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

launch_ros/launch_ros/actions/composable_node_container.py Outdated Show resolved Hide resolved
Signed-off-by: Aditya <aditya050995@gmail.com>
@ivanpauno ivanpauno requested a review from hidmic April 26, 2022 14:14
@ivanpauno
Copy link
Member

@adityapande-1995 could you fix CI failures?

Signed-off-by: Aditya <aditya050995@gmail.com>
@adityapande-1995
Copy link
Contributor Author

adityapande-1995 commented Apr 27, 2022

CI :
build : --packages-above-and-dependencies launch_ros
test : --packages-above launch_ros

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows [Build Status]

Signed-off-by: Aditya <aditya050995@gmail.com>
@adityapande-1995
Copy link
Contributor Author

CI round 2 with flake8 fixes :

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows [Build Status]

@adityapande-1995
Copy link
Contributor Author

Got green CI, merging !

@adityapande-1995 adityapande-1995 merged commit a14156e into master Apr 27, 2022
@delete-merged-branch delete-merged-branch bot deleted the aditya/composable_node_condition_arg branch April 27, 2022 19:56
@sea-bass
Copy link

Any chance this can be backported to Humble? We just had a MoveIt user find an issue with something related to this change not being in Humble.

@mjcarroll
Copy link
Member

mjcarroll commented Jun 12, 2023

Any chance this can be backported to Humble? We just had a MoveIt user find an issue with something related to this change not being in Humble.

I don't see any reason why not after looking at it. Care to open a PR?

@clalancette
Copy link
Contributor

@Mergifyio backport humble

@mergify
Copy link

mergify bot commented Jun 12, 2023

backport humble

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Jun 12, 2023
* Added run condition for composable nodes
Signed-off-by: Aditya <aditya050995@gmail.com>
(cherry picked from commit a14156e)
clalancette pushed a commit that referenced this pull request Jun 13, 2023
* Added run condition for composable nodes
Signed-off-by: Aditya <aditya050995@gmail.com>
(cherry picked from commit a14156e)

Co-authored-by: Aditya Pande <aditya050995@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make ComposableNode support "condition"
5 participants