Skip to content

"yes" and "no" string parameters are confused for bool parameters #1983

@Alberto-Neri

Description

@Alberto-Neri
  • Operating System:
    Windows 10
  • Installation type:
    ROS2 Foxy binaries
  • DDS implementation:
    Cyclone-DDS
  • Client library (if applicable):
    rclcpp

Steps to reproduce issue

Use whatever node you want and add somewhere:

std::string calib;
try {
    this->declare_parameter<std::string>("calib", "no");
    this->get_parameter_or("calib", calib, std::string("no"));
}
catch (std::exception e) {
    std::cout << e.what() << "\n";
}
std::cout << calib << "\n";

Then try run the node with:

ros2 run pkg_name exe_name --ros-args -p "calib:=yes"

Expected behavior

The CLI prints yes.

Actual behavior

Exception triggered with description:
parameter 'calib' has invalid type: expected [string] got [bool].

Additional information

If I launch the node with:
ros2 run pkg_name exe_name --ros-args -p "calib:=ok"
I get the expected behaviour (ok printed).

If I modify the code to accept a bool parameter, like this:

bool calib;
try {
    this->declare_parameter<bool>("calib", false);
    this->get_parameter_or("calib", calib, false);
}
catch (std::exception e) {
    std::cout << e.what() << "\n";
} 
std::cout << calib << "\n";

and do: ros2 run pkg_name exe_name --ros-args -p "calib:=yes"
I get no exception and it prints 1, that is the same as true!!
While doing: ros2 run pkg_name exe_name --ros-args -p "calib:=ok"
gives me the inverse exception as before:
parameter 'calib' has invalid type: expected [bool] got [string]. !!!

Is this expected?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions