Access ROS time functionality
Time object representing an instance of time in
seconds and nanoseconds. This time can be based on your system time, the ROS simulation
time, or an arbitrary time.
initializes the time values for seconds and nanoseconds based on
time = rostime(
totalSecs, which represents the time in seconds as
a floating-point number.
initializes the time values for seconds and nanoseconds individually. Both
inputs must be integers. Large values for
time = rostime(
wrapped automatically with the remainder added to
the current ROS time. If the
time = rostime("now")
use_sim_time ROS parameter
is set to
the simulation time published on the
Otherwise, the function returns the system time of your machine. The
time is a ROS
Time object. If no
output argument is given, the current time (in seconds) is printed to the
rostime can be used to timestamp messages or to
measure time in the ROS network.
also returns a Boolean that indicates if
time is in
simulation time (
true) or system time
always returns the system time of your machine, even if ROS publishes
simulation time on the
time = rostime("now","system")
clock topic. If no output argument
is given, the system time (in seconds) is printed to the screen.
The system time in ROS follows the UNIX or POSIX time standard. POSIX time is defined as the time that has elapsed since 00:00:00 Coordinated Universal Time (UTC), 1 January 1970, not counting leap seconds.
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
Nsec property of the
Sec— Whole seconds
Whole seconds, specified as a positive integer.
The maximum and minimum values for
Nanoseconds, specified as a positive integer. It this value is greater
than or equal to 109, then the value is wrapped
and the remainders are added to the value of
Connect to a ROS network.
Launching ROS Core... ......................................................Done in 1.2992 seconds. Initializing ROS master on http://192.168.0.10:50528. Initializing global node /matlab_global_node_53326 with NodeURI http://bat1074310glnxa64:35637/
Get the current ROS Time. You can also check whether is it system time by getting the
[t,issim] = rostime('now')
t = ROS Time with properties: Sec: 1.5983e+09 Nsec: 946272345
issim = logical 0
Initialize a ROS network.
Launching ROS Core... ..........................................Done in 1.8596 seconds. Initializing ROS master on http://192.168.0.10:49789. Initializing global node /matlab_global_node_65657 with NodeURI http://bat1002808glnxa64:36291/
Create a stamped ROS message. Specify the
Header.Stamp property with the current system time.
point = rosmessage('geometry_msgs/PointStamped'); point.Header.Stamp = rostime('now','system');
Shut down the ROS network.
Shutting down global node /matlab_global_node_65657 with NodeURI http://bat1002808glnxa64:36291/ Shutting down ROS master on http://192.168.0.10:49789. ........
This example shows how to convert current ROS time into a MATLAB® standard time. The ROS Time object is first converted to a double in seconds, then to the specified MATLAB time.
Set up ROS network and store ROS time.
Launching ROS Core... ........................................Done in 1.2519 seconds. Initializing ROS master on http://192.168.0.10:53702. Initializing global node /matlab_global_node_79012 with NodeURI http://bat1012606glnxa64:37633/
t = rostime('now');
Convert ROS time to a double in seconds.
secondtime = double(t.Sec)+double(t.Nsec)*10^-9;
Set time to a specified MATLAB format.
time = datetime(secondtime, 'ConvertFrom','posixtime')
time = datetime 24-Aug-2020 23:05:15
Shut down ROS network.
Shutting down global node /matlab_global_node_79012 with NodeURI http://bat1012606glnxa64:37633/ Shutting down ROS master on http://192.168.0.10:53702. .........
seconds function to get the total seconds of a
Time object from its
time = rostime(1,860000000)
time = ROS Time with properties: Sec: 1 Nsec: 860000000
Get the total seconds from the time object.
secs = seconds(time)
secs = 1.8600