ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Use ros::Time without master

asked 2014-01-01 12:10:16 -0500

astrokenny gravatar image

Is there anyway to use the structures and functions in ros::Time without the requirement to initialize a node and connect to a master? I want to use it as part of a test fixture for a library that does not otherwise use ros (ie, it only needs a level 1 test; see http://wiki.ros.org/UnitTesting), and it would be nice not to incur the overhead of needing to initialize a ros node, run roscore, connect to it, etc.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2014-01-02 04:28:52 -0500

Chad Rockey gravatar image

It depends on how you want to use ros::Time.

If you want the current live system time, there are two ways to do this. If you want a distributed, simulated time (like from Gazebo or rosbag play --clock), you can't do this without a ros system as it comes in over the /clock topic.

The first way is to use ros::Time, but call ros::Time::init(). You'll see the following error message if you try to use it without it:

Cannot use ros::Time::now() before the first NodeHandle has been created or ros::start() has been called.  If this is a standalone app or test that just uses ros::Time and does not communicate over ROS, you may also call ros::Time::init()

Just call ros::Time::init() and now ros::Time::now() should be available.

The other option is if you never, ever want to use simulated or recorded time, then you can use ros::WallTime. This is the same API as ros::Time, but always geared to the current time of the system on which ros is running.

Example:

ros::WallTime t = ros::WallTime::now();

Wiki page on WallTime:

http://wiki.ros.org/roscpp/Overview/Time#Wall_Time

edit flag offensive delete link more
1

answered 2014-01-01 17:36:14 -0500

Hello!

I don't believe there is a way to get the time without a ROS master since the master is what actually manages the clock (since this can be changed to use simulation time, etc.). Someone might correct me on that.

However, the underlying implementation of the ROS timer is Boost's ptime library from the header boost/date_time/posix_time/ptime.hpp (documentation here), so you could just use that instead. Personally I'd say it would be better to use the Boost clock than have ROS as a dependency for some entirely unrelated project.

-Tim

edit flag offensive delete link more

Comments

Maybe trying to set use_sim_time to false might make ros::Time behave like you want, but still then you could just use some other time library if you don't need it to be a ros time.

dornhege gravatar image dornhege  ( 2014-01-02 02:42:25 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2014-01-01 12:10:16 -0500

Seen: 1,390 times

Last updated: Jan 02 '14