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

ros2 param set string type "Off" #677

Closed
icolwell-as opened this issue Dec 7, 2021 · 4 comments · Fixed by #684
Closed

ros2 param set string type "Off" #677

icolwell-as opened this issue Dec 7, 2021 · 4 comments · Fixed by #684
Assignees
Labels
bug Something isn't working

Comments

@icolwell-as
Copy link

Bug report

Required Info:

  • Operating System:
    • Ubuntu 20.04
  • Installation type:
    • binaries
  • Version or commit hash:
    • Foxy
  • DDS implementation:
    • Default
  • Client library (if applicable):
    • N/A

Steps to reproduce issue

Declare string parameter from within cpp code.
Attempt to set the parameter from the CLI to the string "Off"

ros2 param set /node param_name Off

Expected behavior

Paremeter is set to the string "Off"

Actual behavior

Parameter is changed to boolean type and set to False.

Additional information

I tried all the following, none of them allow me to set a string value:

ros2 param set /node param_name Off
ros2 param set /node param_name "Off"
ros2 param set /node param_name 'Off'
ros2 param set /node param_name off

Is there any way to enforce the type when parsing the passed-in CLI value? or at the very least assume the passed-in value is the same type as the existing parameter type?

Maybe a new -f/--force-type flag for "force" type?

@clalancette
Copy link
Contributor

Thanks for the report. This is basically unintentional behavior (and hence a bug).

What's happening here is that we are using YAML parsing to parse the value, and it is automatically interpreting certain values (on, off, true, false, etc) as booleans, and then trying to send that to the node. In Foxy, parameter types are flexible, so it automatically changes the type. In Rolling, for instance, the ros2 param set call fails because there we are enforcing types and this is trying to change the type.

One workaround for all platforms is to do the following:

ros2 param set /node param_name "\"off\""

Which will make the parameter literally "off". That's enough to keep it a string, though you'll have to have custom code inside of the node in order to strip the quotes off. In the meantime, I'll mark this as a bug to look into.

@clalancette
Copy link
Contributor

#684 is a potential fix for this, though I don't think we can completely fix it.

With #684 in, running:

ros2 param set /node param 'off'

will still interpret the argument as a boolean. But the following would work as an override:

ros2 param set /node param '!!str off'

@clalancette clalancette self-assigned this Jan 6, 2022
@icolwell-as
Copy link
Author

Thanks for the fix! much appreciated.

@clalancette
Copy link
Contributor

You are welcome, happy to help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants