0
$\begingroup$

Rosanswers logo

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?


Originally posted by Josch on ROS Answers with karma: 230 on 2013-04-29

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by Martin Günther with karma: 11816 on 2013-04-29

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by Josch on 2013-04-30:
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.

Comment by Martin Günther on 2013-04-30:
Are you sure that a simple list of integers (like [1, 2, 3, 4]) doesn't work? I'm 99% sure it works.

Comment by Josch on 2013-04-30:
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.

$\endgroup$

Your Answer

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