ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

use parameters from python launch file in node

asked 2021-08-15 18:46:34 -0600

rosnoob145 gravatar image

I am trying to use parameters specified in my .launch.py file, but a ParameterNotDeclaredException is thrown when accessing any parameter. Does anyone know why? I try to access the parameters like this from within my Node:

self.get_parameter('buffer_size')

Here is the launch file. I'm using Foxy and Python

from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
    return LaunchDescription([
        Node(
            package='blackfly_calibration',
            executable='broadcaster',
            parameters=[
                {"capture_frequency": 20.0},
                {"buffer_size": 10},
                {"image_topic": "/camera/image_raw"}
            ],
        )
    ])
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2021-08-16 11:02:30 -0600

Before calling get_parameter, you had need to call;

self.declare_parameter(“buffer_size”,0)

Here you initialize buffer_size with a default value of 0, you can set a desired default parameter.

edit flag offensive delete link more

Comments

thank you so much!

rosnoob145 gravatar image rosnoob145  ( 2021-08-16 11:31:57 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2021-08-15 18:46:34 -0600

Seen: 147 times

Last updated: Aug 16 '21