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

sensor_msgs.msg Image type value error. "Not a message data class"

asked 2018-05-31 15:59:28 -0500

SouLeo gravatar image

updated 2018-05-31 16:54:45 -0500

jayess gravatar image

I'm getting a value error when trying to run this code:

front_image_pub = rospy.Publisher('/front_camera/image_raw', Image, queue_size=10)

The precise error is:

Traceback (most recent call last):
  File "/home/nrgadmin/catkin_ws/src/vr_ui/src/playback.py", line 80, in <module>
    main()
  File "/home/nrgadmin/catkin_ws/src/vr_ui/src/playback.py", line 67, in main
    front_image_pub = rospy.Publisher('/front_camera/image_raw', Image, queue_size=10) 
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/topics.py", line 842, in __init__
    super(Publisher, self).__init__(name, data_class, Registration.PUB)
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/topics.py", line 144, in __init__
    raise ValueError("data_class [%s] is not a message data class"%data_class.__class__.__name__)
ValueError: data_class [type] is not a message data class

So the fun thing about this error, is that when I substitue the Image type with any of the other sensor_msgs.msg types (such as Temperature, CompressedImage, or Joy) I don't have any error at all.

Here's a link to the full code: https://github.com/SouLeo/360_lab_visualization/blob/master/src/playback.py

My package.xml is here: https://github.com/SouLeo/360_lab_visualization/blob/master/package.xml

My CMakeList is here: https://github.com/SouLeo/360_lab_visualization/blob/master/CMakeLists.txt

I'm so sorry for being dumb, but I seriously don't understand why some sensor_msg topics work and then Image doesn't.

Other things I have tried include:

  1. Clean building my vr_ui package
  2. verifying my package.xml and cmake list included sensor_msgs.msg dependency
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2018-05-31 16:57:13 -0500

marguedas gravatar image

updated 2018-05-31 16:58:51 -0500

It looks like you have a name collision between your class named Image and the message type you are importing as Image.

Can you try importing the Image message with a different name? e.g.

from sensor_msgs.msg import Image as ImageMsg

And use ImageMsg to create your publisher

front_image_pub = rospy.Publisher('/front_camera/image_raw', ImageMsg, queue_size=10)

Alternative: Or you can try renaming your Image class to something like MyImage

edit flag offensive delete link more

Comments

This is brilliant, and I can’t believe I didnt catch this. Thank you so so much!!

SouLeo gravatar image SouLeo  ( 2018-05-31 17:02:02 -0500 )edit

This is definitely the culprit. One needs to be careful with name collisions.

jayess gravatar image jayess  ( 2018-05-31 17:03:56 -0500 )edit
1

@SouLeo can you please accept the answer (tick the box) if this solved your issue. This will let people know that the answer has been accepted and that the problem doesn't need further investigation. Thanks!

marguedas gravatar image marguedas  ( 2018-05-31 18:02:02 -0500 )edit

done! (I think)

SouLeo gravatar image SouLeo  ( 2018-05-31 18:05:56 -0500 )edit

Question Tools

Stats

Asked: 2018-05-31 15:59:28 -0500

Seen: 1,575 times

Last updated: May 31 '18