Contents
Time and Duration
ROS has builtin time and duration primitive types, which rosserial provides as the ros::Time and ros::Duration classes, respectively. A Time is a specific moment (e.g. "today at 5pm") whereas a Duration is a period of time (e.g. "5 hours"). Durations can be negative.
Times and durations have identical representations:
unsigned long secs unsigned long nsecs
Getting the Current Time
In order to get the current ROS time, you must be connected to ROS. Then, you can use your NodeHandle object, nh, to query the current time. nh.now()
Get the current time as a ros::Time instance:
1 ros::Time begin = nh.now();
Creating Time and Duration Instances
You can create a Time or Duration to a specific value as well, either using a two-integer constructor:
Converting Time and Duration Instances
Time and Duration objects can also be turned into floating point seconds: