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

difference between usage of rostime::Now & toSec for Matlab

asked 2017-01-13 05:49:48 -0600

Sami gravatar image

Hello everyone,

i have some troubles and hope that you can help me. I want to use the time that i got from ROS in Matalb. First i used the command ros::Time::now(); and i got for each frame a timestamp. And now in matlab, i want to use the difference between the timestamp (eg. timestamp[3] - timestamp [2] or timestamp[4] - timestamp [3]) for further calculations. But the problem is that i always got the value 0 when i calcute the difference. And now i have used the function toSec in ROS. And when i calculate the difference in matlab, i have results # 0, meanings "better results". I have read the wiki , but it doesnt tell or explain exactly what is the difference between using or working with the ros::Time or toSec ? I hope please that you can better lighten it


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-01-13 11:01:57 -0600

dornhege gravatar image

ros::Time::now() gives you an actual time stamp as an object. toSec() just converts this into a double represenation in seconds. Subtracting time stamps and calling toSec() on this should work and give you correct results.

edit flag offensive delete link more


Thanks for the reply. Thanks. That means, for the evaluation of results in matlab, it is better to use the function toSec() and not to use directly the value of ros::Time::now() (meanings the timestamp value) ?

Sami gravatar image Sami  ( 2017-01-13 18:27:29 -0600 )edit

In Matlab,if want to work with timestamp, its better to tranform it using toSec? Is there a difference, if i first,for each time stamp that i receive, use the function toSec and then calculate the difference between values that follow each other, then i publish them or if I do it like you said?

Sami gravatar image Sami  ( 2017-01-13 18:36:23 -0600 )edit

besides double inaccuracies that should give you the same result, i.e., a time difference in seconds. If Matlab can't handle the ros::Time class, then you can use the time stamp in seconds.

dornhege gravatar image dornhege  ( 2017-01-15 05:38:22 -0600 )edit

Question Tools


Asked: 2017-01-13 05:49:48 -0600

Seen: 1,899 times

Last updated: Jan 13 '17