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

ROSSerializationException while publishing PointCloud2 Message

asked 2013-04-29 22:34:06 -0600

Josch gravatar image

updated 2014-04-20 14:06:46 -0600

ngrennan gravatar image

Hello everyone,

when my node is publishing a PointCloud2 message I get the following error:

Traceback (most recent call last):
  File "/home/rosuser/ros_workspace/src/udp_83b_adapter_eclipse_python/src/UDP83BAdapter.py", line 141, in <module>
    adapter.init()
  File "/home/rosuser/ros_workspace/src/udp_83b_adapter_eclipse_python/src/UDP83BAdapter.py", line 137, in init
    self.receive()
  File "/home/rosuser/ros_workspace/src/udp_83b_adapter_eclipse_python/src/UDP83BAdapter.py", line 43, in receive
    self.sonarToPointfield()
  File "/home/rosuser/ros_workspace/src/udp_83b_adapter_eclipse_python/src/UDP83BAdapter.py", line 128, in sonarToPointfield
    self.pub.publish(msg_pointcloud2)
  File "/opt/ros/groovy/lib/python2.7/dist-packages/rospy/topics.py", line 801, in publish
    raise ROSSerializationException(str(e))
rospy.exceptions.ROSSerializationException: field fields[].offset must be unsigned integer type

The message is completely generated by my python script. Here is the fields declaration and initialization:

    #  Create 4 PointFields as channel description
    msg_pf1 = smsgs.PointField()
    msg_pf1.name = np.str('x')
    msg_pf1.offset = np.uint32(0)
    msg_pf1.datatype = np.uint8(7)
    msg_pf1.count = np.uint32(1)

    msg_pf2 = smsgs.PointField()
    msg_pf2.name = np.str('y')
    msg_pf2.offset = np.uint32(4)
    msg_pf2.datatype = np.uint8(7)
    msg_pf2.count = np.uint32(1)

    msg_pf3 = smsgs.PointField()
    msg_pf3.name = np.str('z')
    msg_pf3.offset = np.uint32(8)
    msg_pf3.datatype = np.uint8(7)
    msg_pf3.count = np.uint32(1)

    msg_pf4 = smsgs.PointField()
    msg_pf4.name = np.str('intensity')
    msg_pf4.offset = np.uint32(12)
    msg_pf4.datatype = np.uint8(2)
    msg_pf4.count = np.uint32(1)

And somewhere later in the code:

    msg_pointcloud2.fields = [msg_pf1, msg_pf2, msg_pf3, msg_pf4]

I'm using python/rospy. Another strange thing: I can run the script. As soon as I try to access the message (e.g. via rostopic echo) the error comes up.

Does anybody have a idea why this is happening? What can I try to debug?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2013-04-29 23:29:56 -0600

updated 2013-04-29 23:36:38 -0600

You probably shouldn't use numpy types, but native data types. The offsets field is supposed to be a native python long instead of numpy.uint32. Instead of:

msg_pf1.offset = np.uint32(0)

just write:

msg_pf1.offset = 0

... and so on for all other fields.

Regarding your other comment:

I'm using python/rospy. Another strange thing: I can run the script. As soon as I try to access the message (e.g. via rostopic echo) the error comes up.

This is probably because the serialization code isn't called until there is a subscriber to the topic.

edit flag offensive delete link more

Comments

This was too easy to come in my mind :-D. Thank you!

Another question: When python asks for a unsiged int list, what do I have to give it? An easy list filled with integers is not correct, unfortunately.

Josch gravatar image Josch  ( 2013-04-30 00:29:56 -0600 )edit
1

Are you sure that a simple list of integers (like [1, 2, 3, 4]) doesn't work? I'm 99% sure it works.

Martin Günther gravatar image Martin Günther  ( 2013-04-30 01:16:56 -0600 )edit

Good point. They were numpy datatypes. I changed them to usual types now (float, float, float, int). Unfortunately python still says: field data[] must be unsigned integer type EDIT: Nevermind, another obvious mistake.

Josch gravatar image Josch  ( 2013-04-30 01:57:10 -0600 )edit

Question Tools

Stats

Asked: 2013-04-29 22:34:06 -0600

Seen: 7,225 times

Last updated: Apr 29 '13