Cannot retrieve parameters from YAML file (even if the file is found)
Hi,
I wrote a very simple program in python to read parameters from a YAML file. The YAML file is the following:
mqtt_node:
ros__parameters:
variable: 9494.98
and the minimal code of the node is this one:
class mqtt_class(Node):
def __init__(self):
super().__init__('mqtt_class')
print()
print(self.get_parameter('variable')._value) # <- here is the problem
print()
)
def main(args = None):
rclpy.init(args = args)
my_publisher = mqtt_class()
rclpy.spin(my_publisher)
my_publisher.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()
This is the error I get:
Traceback (most recent call last):
File "/home/kkk/workspace/install/xxx/lib/xxx/xxx", line 11, in <module>
load_entry_point('xxx', 'console_scripts', 'xxx')()
File "/home/kkk/workspace/build/xxx/xxx/xxx.py", line 108, in main
my_publisher = mqtt_class()
File "/home/kkk/workspace/build/xxx/xxx/xxx.py", line 54, in __init__
print(self.get_parameter('variable')._value)
File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/node.py", line 512, in get_parameter
raise ParameterNotDeclaredException(name)
rclpy.exceptions.ParameterNotDeclaredException: ('Invalid access to undeclared parameter(s)', 'variable')
[ERROR] [zzzz-2]: process has died [pid 19805, exit code 1, cmd '/home/kkk/workspace/install/xxx/lib/xxx/xxx --ros-args -r __xxx:=xxx --params-file /home/kkk/workspace/install/xxx/share/xxx/params.yaml'].
What is wrong with the code?