ROS2 parameter in launch file with node namespace
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.
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 yourros2 launch
call 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 withros2 param
tools to know any parameters were applied or not.Update in Edit1
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?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 additionalturtlesim
(well that was not clear - now I get it). Anyway, I want to have an additionalturtlesim
node in a different namespace/new_turtle
starting up with the same yaml parameter file. How do I do that?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.
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
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 bothturtlesim
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 @dhoodGood to hear you got it doing what you wanted!!