(c++) Rospram fails when reading certain boolean values

asked 2019-04-05 12:48:31 -0500

cody.littley gravatar image

For some reason, I can't get getParam() to return the value true unless it is formatted in a very specific way. Is this a bug? Any insight is appreciated.

I am loading the rosparam server using a yaml file. My file looks something like this:

foo:
    bar:
        my_boolean_value: true

When I use the getParam() function to retrieve the value, it tells me that the value does not exist.

bool value;
bool success = handle.getParam("foo/bar/my_boolean_value", value);
// success == false

The same thing happens when I try to interpret it as a string.

std::string value;
bool success = handle.getParam("foo/bar/my_boolean_value", value);
// success == false

However, if I use the following yaml files I have no problem reading it with the code above.

foo:
    bar:
        my_boolean_value: True
        # Notice the capitol 'T'

foo:
    bar:
        my_boolean_value: False


foo:
    bar:
        my_boolean_value: false
        # first letter doesn't need to be a capitol for false

foo:
    bar:
        my_boolean_value: "true"
        # I can read this a a string value, unlike the unquoted variant
edit retag flag offensive close merge delete

Comments

Clarifying question: if success is false for all cases, then your code is never actually reading the parameters, when does true return successfully for value not success?

stevemacenski gravatar image stevemacenski  ( 2019-04-06 23:13:59 -0500 )edit

The variable success is false only for the input string true. success resolves to true and the variable value holds the correct result when the input string is True, false, False, and "true" (as long as I request a string).

cody.littley gravatar image cody.littley  ( 2019-04-08 11:15:21 -0500 )edit