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

getting time difference from topic

asked 2013-04-12 05:00:11 -0600

Rizqa gravatar image

updated 2013-04-12 05:03:07 -0600

Hi ROS fans..

I am new in ROS.. I try to get "time difference" from this topic, it means that I subtract current time and previous time from that topic.

How to get the time from this topic in code ??

I hope someone can help me :) Thanks..

rizqa@ubuntu:~$ rostopic echo /send_to_servo 
[/send_to_servo] value was not numeric: header:    
seq: 343  
secs: 1365612244
nsecs: 639405012
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2013-04-16 01:25:33 -0600

zumili gravatar image

Hello Rizqa,

you have the choise, it depends on what you actually want to do.

One way is, that you meassure the time between two messages in that node which creates and sends the message. The other way is that you get messages from other nodes. I think this is what you actually want.

So like davinci already said you need a subscriber. You initializes that subscriber with a self defined callback function and of course the message/topic name. This callback function gets called if a message from another node arrives. But don't forget that you have to call ros::spin() or ros::spinOnce()!!. Then you can directly get the current time in this callback function with ros::Time::now(). This can be done if the message doesn't have a header with a timestamp. If you get messages with a header and a timestamp you can read this timestamp from the message.

So I also recomment to have a look at the tutorial

Beste regards, zumili

edit flag offensive delete link more


Thanks zumili.. exactly.. that's what I want to make a node to get the timestamp.. :)

Rizqa gravatar image Rizqa  ( 2013-04-16 05:08:59 -0600 )edit

answered 2013-04-12 05:16:32 -0600

davinci gravatar image

You should write a subscriber node that listens to the topic and subtracts the timestamps.

But what do you try to achieve? You want to send servo signals or something?

edit flag offensive delete link more


Thanks @davinci.. I want to make speed-based tracking so I need time difference...

Velocity = Displacement / time_difference

Rizqa gravatar image Rizqa  ( 2013-04-12 18:04:37 -0600 )edit

How did you do it?

cybodroid gravatar image cybodroid  ( 2016-03-18 03:15:03 -0600 )edit

Question Tools


Asked: 2013-04-12 05:00:11 -0600

Seen: 4,355 times

Last updated: Apr 16 '13