Create a ROS duration object
returns a default
ROS duration object. The properties for seconds and nanoseconds are set to
dur = rosduration
In a future release, ROS Toolbox will use message structures instead of objects for ROS messages.
To use message structures now, set the
"struct". For more information, see ROS Message Structures.
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
Initialize a ROS network.
Launching ROS Core... Done in 0.62416 seconds. Initializing ROS master on http://192.168.0.10:51131. Initializing global node /matlab_global_node_99486 with NodeURI http://bat1073817glnxa64:42303/
Add a duration to a ROS
time = rostime('now','system')
time = ROS Time with properties: Sec: 1.6157e+09 Nsec: 379100720
timeFuture = time + dur3
timeFuture = ROS Time with properties: Sec: 1.6157e+09 Nsec: 881100720
Shut down the ROS network.
Shutting down global node /matlab_global_node_99486 with NodeURI http://bat1073817glnxa64:42303/ Shutting down ROS master on http://192.168.0.10:51131.
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
Durationobject | structure
Duration, returned as a ROS
Duration object or message structure with
Behavior change in future release
You can now create messages as structures with fields matching the message object properties. Using structures typically improves performance of creating, updating, and using ROS messages, but message fields are no longer validated when set. Message types and corresponding field values from the structures are validated when sent across the network.
To use ROS messages as structures, use the
argument when creating your publishers, subscribers, or other ROS objects. Any messages
generated from these objects will utilize structures.
pub = rospublisher("/scan","sensor_msgs/LaserScan","DataFormat","struct") msg = rosmessage(pub)
You can also create messages as structures directly, but make sure to specify the data
"struct" for the publisher, subscriber, or other ROS objects as
well. ROS objects still use message objects by default.
msg = rosmessage("/scan","sensor_msgs/LaserScan","DataFormat","struct") ... pub = rospublisher("/scan","sensor_msgs/LaserScan","DataFormat","struct")
In a future release, ROS messages will use structures by default and ROS message objects will be removed.
For more information, see Improve Performance of ROS Using Message Structures.