Ask Your Question
0

ROSSerializationException while publishing TFMessage

asked 2017-08-01 23:56:16 -0500

Quang Le gravatar image

Hi everyone,

When I'm trying to publish tf2_msgs/TFMessage message, I got the following error:

0.966600119221
0.967081379774
0.968426689557
0.968817018408 
0.970126572275
0.970582148198
0.971705996452
0.972002006677
Traceback (most recent call last):
File "laser_scan.py", line 103, in <module>
  Laser_reading()
File "laser_scan.py", line 35, in __init__
  self.lc_tf.handle() 
File "laser_scan.py", line 93, in tf_handler
  self.tf_pub.publish(tf_msg)
File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/topics.py", line 856, in publish
raise ROSSerializationException(str(e))
rospy.exceptions.ROSSerializationException: field transforms must be a list or tuple type

It seems that my node can run for a while (I tried to print some field of the messages as you guys can see above), then suddenly get this error. The message is generated by my script below:

tf_msg = TFMessage()
tf_msg.transforms = TransformStamped()

tf_msg.transforms.header = Header()
tf_msg.transforms.header.stamp.secs =  float(msg.utime)/1e6
tf_msg.transforms.header.frame_id = "camera"

tf_msg.transforms.child_frame_id = "base_laser"
tf_msg.transforms.transform = Transform()

tf_msg.transforms.transform.translation = Vector3()
tf_msg.transforms.transform.translation.x = msg.trans[0]
tf_msg.transforms.transform.translation.y = msg.trans[1]
tf_msg.transforms.transform.translation.z = msg.trans[2]

tf_msg.transforms.transform.rotation = Quaternion()
tf_msg.transforms.transform.rotation.x = msg.quat[0]
tf_msg.transforms.transform.rotation.y = msg.quat[1]
tf_msg.transforms.transform.rotation.z = msg.quat[2]
tf_msg.transforms.transform.rotation.w = msg.quat[3]
print msg.quat[3]

Does anybody have a idea about this? and how can I do to fix this?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-08-09 23:00:57 -0500

Ed Venator gravatar image

The problem is that tf_msg.transforms should be a Python list containing one or more transforms. Change your code like this:

tf_msg = TFMessage()

tf_msg.transforms.append(TransformStamped())

tf_msg.transforms[0].header.stamp.secs =  float(msg.utime)/1e6
tf_msg.transforms[0].header.frame_id = "camera"

tf_msg.transforms[0].child_frame_id = "base_laser"

tf_msg.transforms[0].transform.translation = Vector3()
tf_msg.transforms[0].transform.translation.x = msg.trans[0]
tf_msg.transforms[0].transform.translation.y = msg.trans[1]
tf_msg.transforms[0].transform.translation.z = msg.trans[2]

tf_msg.transforms[0].transform.rotation = Quaternion()
tf_msg.transforms[0].transform.rotation.x = msg.quat[0]
tf_msg.transforms[0].transform.rotation.y = msg.quat[1]
tf_msg.transforms[0].transform.rotation.z = msg.quat[2]
tf_msg.transforms[0].transform.rotation.w = msg.quat[3]
print msg.quat[3]
edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-08-01 23:56:16 -0500

Seen: 550 times

Last updated: Aug 09 '17