Ask Your Question

set bool param failed

asked 2014-09-29 07:32:12 -0600

GuoliangLiu gravatar image

updated 2014-10-08 08:40:24 -0600

SL Remy gravatar image

The code is:

ros::NodeHandle nh_private("~");     
bool state=false;

nh_private.param<bool>("state", state, "false");

It turns out the "state" is "true". Why???

edit retag flag offensive close merge delete



Following the answer from @kmhallen, this would seem to be expected (and correct) behaviour (you're just using the wrong type for your default value). Perhaps change your topic title to reflect this?

gvdhoorn gravatar imagegvdhoorn ( 2014-09-29 09:56:18 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2014-09-29 08:38:25 -0600

kmhallen gravatar image
template<typename T>
void param(const std::string& param_name, T& param_val, const T& default_val) const;

From the function prototype, param_val and default_val are both the template type, in this case bool.

The string value "false" is a pointer to the characters 'false' which is non-zero. This is interpreted as true when used as a bool. Try without quotes around false;

nh_private.param<bool>("state", state, false);
edit flag offensive delete link more


great! thinks!

GuoliangLiu gravatar imageGuoliangLiu ( 2014-10-07 20:25:47 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-09-29 07:32:12 -0600

Seen: 773 times

Last updated: Oct 08 '14