Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] String parameter parsed as boolean (when passed as a dictionary to a Node in a launch file) #410

Open
beltransen opened this issue Sep 5, 2024 · 0 comments

Comments

@beltransen
Copy link

Bug report

Required Info:

  • Operating System:
    • Ubuntu 22.04
  • Installation type:
    • Binaries
  • Version or commit hash:
    • 0.19.7-2jammy.20240728.221802
  • DDS implementation:
    • N/A
  • Client library (if applicable):
    • N/A

Steps to reproduce issue

When launching a node using a python launch file passing parameters as a dict, there is a problem parsing the string values 'y' and 'n', as they are interpreted as boolean values.

For instance, the following launch file my_launch.py tries to spawn a node from the pcl_ros package that can receive a string parameter filter_field_name:

from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
    return LaunchDescription([
        Node(
		package='pcl_ros',
		executable='filter_passthrough_node',
		name='passthrough_y',
		output='screen',
		parameters=[{
		    'filter_field_name': 'y'
		}]
	    )
    ])

If the value of the parameter is any other than 'y' or 'n', the node starts correctly. However, if any of those values is passed, the following error arises:
[INFO] [filter_passthrough_node-1]: process started with pid [25858] [filter_passthrough_node-1] terminate called after throwing an instance of 'rclcpp::exceptions::InvalidParameterTypeException' [filter_passthrough_node-1] what(): parameter 'filter_field_name' has invalid type: Wrong parameter type, parameter {filter_field_name} is of type {string}, setting it to {bool} is not allowed. [ERROR] [filter_passthrough_node-1]: process has died [pid 25858, exit code -6, cmd '/home/beltransen/ros2_ws/install/pcl_ros/lib/pcl_ros/filter_passthrough_node --ros-args -r __node:=passthrough_y --params-file /tmp/launch_params_lirux2gp'].

The content of the temporary .yaml file (/tmp/launch_params_lirux2gp) generated from the dictionary of parameters and passed to the node is:

/**:
  ros__parameters:
    filter_field_name: y

The problem here is that, during the conversion, the 'y' and 'n' strings are inserted into the .yaml file without single quotes, unlike any other string value, which preserves the quotes and, therefore, can be correctly parsed.

If I manually create a .yaml file keeping the single quotes:

/**:
   ros__parameters:
    filter_field_name: 'y'

And adapt the launch file to read the parameters from the .yaml file instead of passing them as a dictionary:

from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
    return LaunchDescription([
        Node(
		package='pcl_ros',
		executable='filter_passthrough_node',
		name='passthrough_y',
		output='screen',
		parameters=["/path/to/config.yaml"]
	    )
    ])

The node starts correctly.

Expected behavior

The temporary .yaml file created from parameters passed as a dictionary should preserve the quotes of all string parameters.

Actual behavior

The temporary .yaml file created from parameters passed as a dictionary removes the quotes of string parameters when taking 'y' or 'n' values. Afterwards, when the .yaml file is read, those values are interpreted as booleans.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant