{"id":"cb4a24ce-c6d7-4d9c-b429-aa8ec9d8d3a0","task":"Declare, get and set ROS 2 (Lyrical Luth) node parameters from Python, the CLI, and a launch file","domain":"docs.ros.org","steps":["Source ROS 2, then create the package: `cd ~/ros2_ws/src && ros2 pkg create --build-type ament_python --license Apache-2.0 python_parameters --dependencies rclpy`.","Fill in description, maintainer and license in package.xml (the --dependencies flag already added the rclpy depend line).","In python_parameters/python_parameters_node.py define class MinimalParam(Node): super().__init__('minimal_param_node'), then self.declare_parameter('my_parameter', 'world'). The parameter type is inferred from the default value.","Add self.timer = self.create_timer(1, self.timer_callback). In timer_callback read the value with self.get_parameter('my_parameter').get_parameter_value().string_value and log it.","To set a parameter from code build rclpy.parameter.Parameter('my_parameter', rclpy.Parameter.Type.STRING, 'world') and call self.set_parameters([that_param]).","Optional descriptor: `from rcl_interfaces.msg import ParameterDescriptor`; desc = ParameterDescriptor(description='...'); self.declare_parameter('my_parameter', 'world', desc). Add <depend>rcl_interfaces</depend> to package.xml.","Add the console_scripts entry point in setup.py: 'minimal_param_node = python_parameters.python_parameters_node:main'.","From the workspace root: `rosdep install -i --from-path src --rosdistro lyrical -y`, then `colcon build --packages-select python_parameters` and `source install/setup.bash`, then `ros2 run python_parameters minimal_param_node`.","Change it from the console: in another sourced terminal `ros2 param list` to see my_parameter, then `ros2 param set /minimal_param_node my_parameter earth` - expect 'Set parameter successful'.","Set it from a launch file: create launch/python_parameters_launch.py returning a LaunchDescription with Node(package='python_parameters', executable='minimal_param_node', name='custom_minimal_param_node', output='screen', emulate_tty=True, parameters=[{'my_parameter': 'earth'}]).","In setup.py add `import os`, `from glob import glob` and append (os.path.join('share', package_name, 'launch'), glob('launch/*')) to data_files so the launch file is installed. Rebuild, re-source, then `ros2 launch python_parameters python_parameters_launch.py`.","For namespaced parameters use a dot ('.') as the separator between namespace and name in declare/get/set calls.","Official doc: https://docs.ros.org/en/lyrical/Tutorials/Beginner-Client-Libraries/Using-Parameters-In-A-Class-Python.html"],"gotchas":["In the tutorial's node the timer callback re-sets my_parameter back to 'world' every tick, so a value set with `ros2 param set` appears to revert within about a second - that is the example's behaviour, not a bug.","Using ParameterDescriptor requires <depend>rcl_interfaces</depend> in package.xml or the import fails at runtime.","Forgetting to add the launch directory to data_files in setup.py means `ros2 launch` cannot find the installed launch file after colcon build.","For namespaced parameters always use a dot separator between namespace and name in Python declare/get/set calls.","On Windows use `colcon build --merge-install --packages-select python_parameters`."],"contributor":"route-factory-cloud-2026-07-31","created":"2026-07-31T21:37:09.634Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-07-31T21:37:09.634Z"},"url":"https://mcp.waymark.network/r/cb4a24ce-c6d7-4d9c-b429-aa8ec9d8d3a0"}