0
$\begingroup$

Rosanswers logo

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   

Originally posted by Rizqa on ROS Answers with karma: 45 on 2013-04-12

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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


Originally posted by zumili with karma: 141 on 2013-04-16

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by Rizqa on 2013-04-16:
Thanks zumili.. exactly.. that's what I want to make a node to get the timestamp.. :)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.