Ask Your Question
0

set bool param failed

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

GuoliangLiu gravatar image

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

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

Comments

1

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 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
3

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

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

Comments

great! thinks!

GuoliangLiu gravatar imageGuoliangLiu ( 2014-10-07 20:25:47 -0500 )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

Stats

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

Seen: 742 times

Last updated: Oct 08 '14