Ask Your Question
0

confision about ros2 rclpy parameter

asked 2020-04-01 23:09:48 -0500

aby gravatar image

updated 2020-04-02 10:16:44 -0500

I implemented a subclass of node

class MyNode(Node):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

         self.declare_parameter(name='foo',
                                             value='foo_val_init',
                                             descriptor=ParameterDescriptor(name='foo',
                                                                                              type=ParameterType.PARAMETER_STRING))
            # just for debuggin
            print(self.get_parameter('foo').value)

I have tried to override this value from the command line at the startup of the node but nothing worked. I tried the following

ros2 run mynode run --ros-args -p "foo:=foo_val_cmdline"      #(prints foo_val_init)
ros2 run mynode run --ros-args -p foo "foo_val_cmdline"      #(prints foo_val_init)
ros2 run mynode run  -p foo "foo_val_cmdline"      #(prints foo_val_init)
ros2 run mynode run foo "foo_val_cmdline"      #(prints foo_val_init)

any idea what I am doing wrong? I tried looking at demos on the main rclpy repo and documentation and I think I misunderstanding these inside-node declared params purpose.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-04-02 08:36:57 -0500

marguedas gravatar image

updated 2020-04-02 10:30:29 -0500

The name of the command line flag to pass ROS arguments is --ros-args (plural, and not --ros-arg)

So if you modify your first invocation with --ros-args it should work

ros2 run mypackage mynode --ros-args -p foo:=foo_val_cmdline

Edit: It looks like you are using ROS 2 dashing. The ability to pass parameters via commandline has been added in ROS Eloquent and is not available in dashing.

edit flag offensive delete link more

Comments

thanks for the quick reply. I updated the question and fixed the typo yet it is the same issue. It could be related to https://github.com/ros2/rclcpp/issues...

aby gravatar image aby  ( 2020-04-02 10:14:01 -0500 )edit

makes sense. thank u. ...installing Eloquent

aby gravatar image aby  ( 2020-04-02 10:42:48 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2020-04-01 23:09:48 -0500

Seen: 164 times

Last updated: Apr 02 '20