0
$\begingroup$

Rosanswers logo

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


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

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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


Originally posted by Dan Lazewatsky with karma: 9115 on 2013-04-16

This answer was ACCEPTED on the original site

Post score: 3


Original comments

Comment by Rizqa on 2013-04-16:
Thanks @Dan Lazewatsky it works ^_^

$\endgroup$

Your Answer

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