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

getting time difference from topic

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

Rizqa gravatar image

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

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  
stamp: 
secs: 1365612244
nsecs: 639405012
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

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

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 http://www.ros.org/wiki/ROS/Tutorials/WritingPublisherSubscriber%28c%2B%2B%29.

Beste regards, zumili

edit flag offensive delete link more

Comments

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 -0500 )edit
0

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

davinci gravatar image

You should write a subscriber node that listens to the topic and subtracts the timestamps. http://www.ros.org/wiki/ROS/Tutorials/WritingPublisherSubscriber%28c%2B%2B%29

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

edit flag offensive delete link more

Comments

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 -0500 )edit

How did you do it?

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

Question Tools

Stats

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

Seen: 4,417 times

Last updated: Apr 16 '13