Create a ROS duration object
a default ROS duration object. The properties for seconds and nanoseconds
are set to 0.
dur = rosduration
Duration objects, perform addition and subtraction, and compare duration objects. You can also add duration objects to ROS
Time objects to get another
Create a duration using seconds and nanoseconds.
dur1 = rosduration(100,2000000)
dur1 = ROS Duration with properties: Sec: 100 Nsec: 2000000
Create a duration using a floating-point value. This sets the seconds using the integer portion and nanoseconds with the remainder.
dur2 = rosduration(20.5)
dur2 = ROS Duration with properties: Sec: 20 Nsec: 500000000
Add the two durations together to get a single duration.
dur3 = dur1 + dur2
dur3 = ROS Duration with properties: Sec: 120 Nsec: 502000000
Subtract durations and get a negative duration. You can initialize durations with negative values as well.
dur4 = dur2 - dur1
dur4 = ROS Duration with properties: Sec: -80 Nsec: 498000000
dur5 = rosduration(-1,2000000)
dur5 = ROS Duration with properties: Sec: -1 Nsec: 2000000
dur1 > dur2
ans = logical 1
Add a duration to a ROS
time = rostime('now','system')
time = ROS Time with properties: Sec: 1.5668e+09 Nsec: 705000000
timeFuture = time + dur3
timeFuture = ROS Time with properties: Sec: 1.5668e+09 Nsec: 207000000
totalSecs— Total time
Total time, specified as a floating-point scalar. The integer portion is set to the
Sec property with the remainder applied to the
Nsec property of the
secs— Whole seconds
Whole seconds, specified as an integer. This value is directly
set to the
Sec property of the
The maximum and minimum values for
Nanoseconds, specified as a positive integer. This value is
directly set to the
NSec property of the
unless it is greater than or equal to 109.
The value is then wrapped and the remainders are added to the value
Duration, returned as a ROS