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

launch_ros action to set parameters for all nodes in scope using a global parameter yaml file #260

Merged
merged 18 commits into from
Sep 1, 2021

Conversation

adityapande-1995
Copy link
Contributor

@adityapande-1995 adityapande-1995 commented Aug 18, 2021

This PR aims to add a new launch_ros action, SetParametersFromFile which can accept a yaml file with ROS parameters which can be passed to all nodes in scope.

Example usage :

The parameter file:

The parameter yaml file must be written in the following format:

demo_node_1:
  ros__parameters:
    param_1: 1
    param_2: 5

demo_node_2:
  ros__parameters:
    param_2: 10
    param_4: hello_world

Launch file in xml:

demo_node_3 is not in the same scope, so the SetParametesFromFile action won't affect it.

<launch>
  <group>
    <set_parameters_from_file filename='/path/to/param/file.yaml'>
    <node pkg="demo_nodes_cpp" exec="parameter_blackboard" name="demo_node_1">
    <node pkg="demo_nodes_cpp" exec="parameter_blackboard" name="demo_node_2">
  </group>
  <node pkg="demo_nodes_cpp" exec="parameter_blackboard" name="demo_node_3">
</launch>

Equivalent usage in python:

from launch import LaunchDescription
from launch_ros.actions import Node, SetParametersFromFile
from launch.actions import GroupAction

def generate_launch_description():
  return LaunchDescription([
     GroupAction(
       actions = [
          SetParametersFromFile('path/to/yaml/file.yaml'),

          Node(
            package = 'demo_nodes_cpp',
            executable = 'parameter_blackboard',
            name = 'demo_node_1'
          ),

          Node(
            package = 'demo_nodes_cpp',
            executable = 'parameter_blackboard',
            name = 'demo_node_2'
          )
        ]
      ),

       Node(
          package = 'demo_nodes_cpp',
          executable = 'parameter_blackboard',
          name = 'demo_node_3'
        )
  ])

TODO

@ivanpauno
Copy link
Member

This is only adding the parameterers to Node actions but not to loaded components, which might be a bit unexpected by users.
Maybe we can fix that after #259 is merged.

Signed-off-by: Aditya Pande <[email protected]>
Signed-off-by: Aditya Pande <[email protected]>
Signed-off-by: Aditya Pande <[email protected]>
Signed-off-by: Aditya Pande <[email protected]>
@adityapande-1995
Copy link
Contributor Author

TODO

@ivanpauno ivanpauno requested a review from hidmic August 25, 2021 21:11
@ivanpauno ivanpauno added the enhancement New feature or request label Aug 25, 2021
@adityapande-1995
Copy link
Contributor Author

adityapande-1995 commented Aug 26, 2021

Parameters are now passed in order , e.g. this launch file

<launch>
	<group>
		<set_parameters_from_file filename="/home/aditya/LaunchTest/params.yaml"/>
		<set_parameter name="test_param" value="10"/>
		<set_parameters_from_file filename="/home/aditya/LaunchTest/params2.yaml"/>
		<set_parameter name="test_param2" value="10"/>
		<node pkg="demo_nodes_cpp" exec="parameter_blackboard" name="demo_node_1" namespace="ns1"/>
		<node pkg="demo_nodes_cpp" exec="parameter_blackboard" name="demo_node_2"/>
	</group>
		<node pkg="demo_nodes_cpp" exec="parameter_blackboard" name="demo_node_3"/>
</launch>

will run --

aditya@qemu-ubuntu:~/LaunchTest$ ps auxww | grep blackboard | cut -c 60-
   0:00 /home/aditya/ros2_rolling/install/demo_nodes_cpp/lib/demo_nodes_cpp/parameter_blackboard --ros-args -r __node:=demo_node_1 -r __ns:=/ns1 --params-file /home/aditya/LaunchTest/params.yaml -p test_param:=10 --params-file /home/aditya/LaunchTest/params2.yaml -p test_param2:=10
   0:00 /home/aditya/ros2_rolling/install/demo_nodes_cpp/lib/demo_nodes_cpp/parameter_blackboard --ros-args -r __node:=demo_node_2 --params-file /home/aditya/LaunchTest/params.yaml -p test_param:=10 --params-file /home/aditya/LaunchTest/params2.yaml -p test_param2:=10
   0:00 /home/aditya/ros2_rolling/install/demo_nodes_cpp/lib/demo_nodes_cpp/parameter_blackboard --ros-args -r __node:=demo_node_3
   0:00 grep --color=auto blackboard

Similarly,

def generate_launch_description():
    return LaunchDescription([

        GroupAction(
            actions = [
                SetParametersFromFile('/home/aditya/LaunchTest/params.yaml'),
		SetParameter(name = 'test_param', value = 10),
                SetParametersFromFile('/home/aditya/LaunchTest/params2.yaml'),
		SetParameter(name = 'test_param2', value = 10),

                Node(
                    package = 'demo_nodes_cpp',
                    executable = 'parameter_blackboard',
                    name = 'demo_node_1',
					namespace = 'ns1'
                    ),

                Node(
                    package = 'demo_nodes_cpp',
                    executable = 'parameter_blackboard',
                    name = 'demo_node_2',
		    parameters = [{'param_10':10}]
                    )
                ]
            ),

    Node(
        package = 'demo_nodes_cpp',
        executable = 'parameter_blackboard',
        name = 'demo_node_3'
        )
    
    ])

will produce:

aditya@qemu-ubuntu:~/LaunchTest$ ps auxww | grep blackboard | cut -c 60-
   0:00 /home/aditya/ros2_rolling/install/demo_nodes_cpp/lib/demo_nodes_cpp/parameter_blackboard --ros-args -r __node:=demo_node_1 -r __ns:=/ns1 --params-file /home/aditya/LaunchTest/params.yaml -p test_param:=10 --params-file /home/aditya/LaunchTest/params2.yaml -p test_param2:=10
   0:00 /home/aditya/ros2_rolling/install/demo_nodes_cpp/lib/demo_nodes_cpp/parameter_blackboard --ros-args -r __node:=demo_node_2 --params-file /home/aditya/LaunchTest/params.yaml -p test_param:=10 --params-file /home/aditya/LaunchTest/params2.yaml -p test_param2:=10 --params-file /tmp/launch_params_s1x0dxst
   0:00 /home/aditya/ros2_rolling/install/demo_nodes_cpp/lib/demo_nodes_cpp/parameter_blackboard --ros-args -r __node:=demo_node_3
   0:00 grep --color=auto blackboard

TODO

  • Fix broken test cases for SetParameter
  • Add new tests for SetParametesFromFile

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.

Implementation LGTM!
This looks ready to go with some tests added.

Signed-off-by: Aditya Pande <[email protected]>
Signed-off-by: Aditya Pande <[email protected]>
Signed-off-by: Aditya Pande <[email protected]>
Signed-off-by: Aditya Pande <[email protected]>
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!

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 with green CI

Copy link
Member

@jacobperron jacobperron left a comment

Choose a reason for hiding this comment

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

LGTM! Just a couple minor comments.

Signed-off-by: Aditya Pande <[email protected]>
@adityapande-1995
Copy link
Contributor Author

CI :

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@adityapande-1995 adityapande-1995 merged commit a65ad43 into master Sep 1, 2021
@delete-merged-branch delete-merged-branch bot deleted the aditya/set_params_from_file branch September 1, 2021 23:44
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.

5 participants