Ask Your Question
0

how to get timestamp from header

asked 2013-04-16 08:21:57 -0500

Rizqa gravatar image

updated 2013-04-16 08:32:58 -0500

Hi ROS fans..

I am new in ROS.. I try to make a simple node that subscribes timestamp from a messages with a header and a timestamp here..

http://www.ros.org/doc/api/sensor_msgs/html/msg/JointState.html

As Describe in this tutorial

http://ros.org/wiki/ROS/Tutorials/WritingPublisherSubscriber%28python%29,

I make a simple coding like this..

#!/usr/bin/env python 

import rospy 
from sensor_msgs.msg import JointState

def callback(data):
    rospy.loginfo(rospy.get_name() + ": I heard %s" % data.header)

def listener():
    rospy.init_node('listener', anonymous=True)
    rospy.Subscriber('get_timestamp', JointState, callback)
    rospy.spin()

if __name__ == '__main__':
    listener()

But I get this error..

 rospy.loginfo(rospy.get_name() + ": I heard %s" % data.header)
      TypeError: float argument required, not Header

why float argument required ? How to solve that problem..

Actually I am confuse with the Sensor_msgs/JointState, because the type of the header is std_msgs/header.

how to subscribe it from sensor_msgs/JointState to get timestamp ?

I hope someone can help me.. :) Thanks..

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2013-04-16 08:44:42 -0500

The error you are seeing has to do with the string formatting. Oddly, I see that error if I use %f, but not %s (%s should try to convert the argument to a str). If you want just the timestamp, use data.header.stamp

edit flag offensive delete link more

Comments

Thanks @Dan Lazewatsky it works ^_^

Rizqa gravatar image Rizqa  ( 2013-04-16 09:14:16 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-04-16 08:21:57 -0500

Seen: 6,521 times

Last updated: Apr 16 '13