Ask Your Question

How to parameterize a duration?

asked 2013-11-24 10:03:16 -0600

updated 2013-11-24 16:37:28 -0600

I have used the following pattern a number of times, across a variety of packages:

double my_param_seconds;
ros::param::get("~my_param", my_param_seconds);
my_param_ = ros::Duration(my_param_seconds);

This seems awkward compared to parameterizing integers or doubles. It's fine if it's only one or two, but for a safety state machine which has a half-dozen parameterized timeouts, this is a drag. I can write my own little wrapper function, but perhaps something standard already exists?

Alternatively, is it better to simply store the seconds value, and convert that to a ros::Duration at the point of use?


edit retag flag offensive close merge delete


Can you define "awkward" in this context? I am not sure to understand what you would like to see improved here... Having the possibility to directly retrieve a ros::Duration object from the parameter API?

Thomas gravatar image Thomas  ( 2013-11-24 14:42:38 -0600 )edit

Sure, have attempted to clarify the question. I know that parameter types are constrained by the XMLRPC types, but I'm wondering if a general Time/Duration helper already exists before I roll my own.

mikepurvis gravatar image mikepurvis  ( 2013-11-24 16:39:15 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2013-11-24 19:02:31 -0600

Thomas gravatar image

Unfortunately there is not such as direct conversion. However this sounds like a nice improvement.

The get function is defined in rosparam.h.

If you add the missing overloading:

ROSCPP_DECL bool get(const std::string& key, ros::Duration& s);

...the templated get will automagically use it. This should even work if you define this function in your own C++ source file (considering you keep the same namespace). Hence, you can fork the project on GitHub, submit a pull request providing the additional getter. In the meanwhile (i.e. until a new version of roscomm is released), you can check the ROS version and provide the overloading yourself for older ROS versions.

As ROS relies on Boost.DateTime to store time-related values, I suggest you use the Boost.DateTime API in the get function to ensure a consistent parsing.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools



Asked: 2013-11-24 10:03:16 -0600

Seen: 398 times

Last updated: Nov 24 '13