Ask Your Question
0

ROS2 parameter in launch file with node namespace

asked 2020-04-21 04:34:32 -0500

RodBelaFarin gravatar image

updated 2020-04-21 08:07:15 -0500

From the following answer by @dhood it says that since Crystal modifications for the nodes name/namespace in launch files will also be taken into account for the parameter YAML file:

https://answers.ros.org/question/3043...

This seems not to work for me.

I am using Ubuntu 18.04 in a VM with ROS Eloquent installed. I am using turtlesim for my tests. My turtlesim.yaml looks as follows:

turtlesim:
  ros__parameters:
    background_b: 0
    background_g: 0
    background_r: 190
    use_sim_time: false

And that is the dedicated turtle.launch.py file:

#!/usr/bin/env python3

import os
from ament_index_python.packages import get_package_share_directory

from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
    my_first_pkg = get_package_share_directory('myfirstpackage')
    return LaunchDescription([
        Node(
            package='turtlesim',
            node_executable='turtlesim_node',
            node_namespace='new_turtle',
            parameters=[os.path.join(my_first_pkg, 'turtlesim.yaml')],
            output='screen'),
        Node(
            package='turtlesim',
            node_executable='draw_square',
            node_namespace='new_turtle',
            output='log'),
    ])

I am expecting now turtlesim to startup with a red background, but it is not affected and still got the default background. If I am extending the node namespace in the YAML parameter file as following, it does work:

new_turtle/turtlesim:
  ros__parameters:
    background_b: 0
    background_g: 0
    background_r: 190
    use_sim_time: false

===========Edit1===========

The logging does also not work: calling ros2 launch myfirstpackage turtle.launch.py --ros-args --log-level debug ends in:

usage: ros2 [-h] Call `ros2 <command> -h` for more detailed usage. ...
ros2: error: unrecognized arguments: --ros-args --log-level debug

And ros2 param list shows only the parameters from the node within the namespace:

/new_turtle/turtlesim:
  background_b
  background_g
  background_r
  use_sim_time

But the values still haven't changed.

edit retag flag offensive close merge delete

Comments

Not an answer, just a troubleshooting tip: you could try reading the debug output from the ROS 2 core as it is handling your parameter file. That might give you extra insight into what is going on. You can enable the debug output in Eloquent by --ros-args --log-level debug to the end of your ros2 launchcall from the command line. (see https://index.ros.org/doc/ros2/Tutori... for usage in other ROS 2 versions). You could inspect the messages with rqt_console. Also you might want to inspect the parameters on the nodes with ros2 param tools to know any parameters were applied or not.

dhood gravatar image dhood  ( 2020-04-21 06:45:30 -0500 )edit

Update in Edit1

RodBelaFarin gravatar image RodBelaFarin  ( 2020-04-21 08:07:34 -0500 )edit

Thanks for the edits - I think I misunderstood your original post. (plus that log-level command doesn't seem to be used by ros2 launch in that way, oops!)

Is it that you want to make the node so it's _not_ in the namespace? And what you are seeing is that you are only able to make the parameters apply to the /new_turtle/turtlesim node, but you want instead to have your node as just /turtlesim not in a namespace, and can't get the parameters to apply to it in that case?

If that's the case, you need to modify the yaml file like you did, yes, but additionally you also need to remove the node_namespace='new_turtle' line from the launch file, to stop the node being put into the namespace. Does that sound right for your situation?

dhood gravatar image dhood  ( 2020-04-22 02:54:01 -0500 )edit

Thanks for the support - OK, let me try to explain it again, sorry for my misleading explanations. I have turtlesim and parameters that I want to have set, when I start the node. I am using a launch file to startup this setup. So far, so good. Now I want to have an additional turtlesim (well that was not clear - now I get it). Anyway, I want to have an additional turtlesim node in a different namespace /new_turtle starting up with the same yaml parameter file. How do I do that?

RodBelaFarin gravatar image RodBelaFarin  ( 2020-04-22 04:15:45 -0500 )edit

oh ok! I think I see what you want now. In that case, you'd need _two_ entries in the yaml file, one for the node /turtlesim and /new_turtle/turtlesim, is that what you're doing?

Or, programmatically, you could create one python dictionary of parameters, and pass that to both Nodes in the launch file.

dhood gravatar image dhood  ( 2020-04-22 04:42:20 -0500 )edit
1

oh, or you could try this approach with the double asterisks instead of specifying the node name! https://answers.ros.org/question/3043... I haven't tried that myself but it looks like it might do what you want. That's a new feature that wasn't available at the time of Crystal

dhood gravatar image dhood  ( 2020-04-22 04:46:44 -0500 )edit

Yes, the double asterisk workaround does work! I didn't even tried it, because I was still thinking in a global parameter server as in ROS1 and I thought that this will affect ALL parameters with the name background_r for example. In that way it would have affected both turtlesim nodes, but yeah - parameters are now dedicated to one node.

In that case I am wondering why not by default the ros2 param dump command saves the *.yaml file using the /** instead of the node name. I would say that's much more intentional and more user-friendly. But thanks @dhood

RodBelaFarin gravatar image RodBelaFarin  ( 2020-04-22 05:14:43 -0500 )edit

Good to hear you got it doing what you wanted!!

dhood gravatar image dhood  ( 2020-04-22 05:56:23 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-04-22 05:21:06 -0500

RodBelaFarin gravatar image

As pointed out by @dhood in the comments, using double asterisk in the *.yaml file solves my problem.

I changed my *.yaml as following and can now change the namespace or node name in my launch file:

/**:
  ros__parameters:
    background_b: 0
    background_g: 0
    background_r: 190
    use_sim_time: false
edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

3 followers

Stats

Asked: 2020-04-21 04:34:32 -0500

Seen: 330 times

Last updated: Apr 22