# [ROS2][rclpy] Load parameters from file does not work when using namespaces

As the title says, I'm currently trying to load some parameters from a parameters.yaml file which is formatted as shown below:

nodename:
ros__parameters:
val1: 1
val2: 2


This parameter file is loaded to the node using a nodename.launch.py file as shown below:

    return LaunchDescription([
Node(
package='nodename',
node_namespace='/',
node_executable='nodename',
node_name='nodename',
output='screen',
emulate_tty=True,
parameters=[
path_to_parameters,
],
)
])


The node itself is started by setting allow_undeclared_parameters=true and automatically_declare_parameters_from_overrides=true while my code inside of the constructor of the Node loads the parameters as displayed here:

    # load parameters
val1_default = rclpy.parameter.Parameter(
"default_behavior",
type_=rclpy.parameter.Parameter.Type.INTEGER,
value=1
)
val1 = self.get_parameter_or("val1", val1_default).value


All this works fine as long as I don't change the nodes namespace in the launch file by e.g. setting node_namespace='robot1'. I have already played around with the name of my parameter where it is loaded in the code by e.g. applying the namespace name as a prefix. I also tried to changed the .yaml file according to the parameter file description documentation by e.g. including the namespaces name in the parameter file as described here. Unfortunately nothing of this works for me so I would be very thankful if someone could give me some advice.

Edit: I forgot to mention that I'm using ROS2 Eloquent Elusor on Mint/Ubuntu

edit retag close merge delete