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

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..

As Describe in this tutorial,

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)

if __name__ == '__main__':

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

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


Thanks @Dan Lazewatsky it works ^_^

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

Question Tools


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

Seen: 7,883 times

Last updated: Apr 16 '13