ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

ROSNODE Subscriber for custom datatype Python

asked 2018-05-14 03:47:06 -0600

ARM gravatar image

I have a rostopic names /scanpoints of type datatypes/scan_point_2018.

This is the custom datatype. The scan_point_2018 is defined in some path /path/..../scan_point_2018.hpp.

I need to write a subscriber for this topic and I tried the following code:

#!/usr/bin/env python import rospy from std_msgs.msg import String

 def callback(data):
     rospy.loginfo("%s Header: %d" % (data.header))

 def listener():
     rospy.init_node('scan_listener', anonymous=True)
     rospy.Subscriber("/scanpoints", String, callback)

 if __name__ == '__main__':

As expected it through error:

 [ERROR] [1526286071.031024461]: 
 Client [/scan_listener_6042_1526286069827] wants topic /scan_listener to have datatype/md5sum [std_msgs/String/992ce8a1687cec8c8bd883ec73ca41d1],but our version has [datatypes/scan_point_2018/9af20afc1058845793165634a89c8aa7]. Dropping connection.

I need to know how to call this custom datatype in my code? Do I need to include path of the file scan_point_2018.hpp or any other suggestions please!

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2018-05-16 13:33:26 -0600

ARM gravatar image

The best and most convenient way is to use Python API. Where you do not need to play the bag file instead call it using Python. Following code I took from ROS Official Site.

import rosbag
bag = rosbag.Bag('test.bag')
for topic, msg, t in bag.read_messages(topics=['chatter', 'numbers']):
    print msg
edit flag offensive delete link more

answered 2018-05-14 04:36:30 -0600

I recommend working through the custom message publisher and subscriber tutorials for python first. The .hpp file you refer to is a C++ header file so it's not what you need if your writing a python script.

You'll need to find the package which defines the message type put it in your workspace if it isn't already and add a dependency to it in. Then you'll need to import it into your script with a line like:

from <package_name>.msg import <message_type_name>

You'll need to look through your packages for a file at a path that looks like:


Hope this helps.

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



Asked: 2018-05-14 03:47:06 -0600

Seen: 398 times

Last updated: May 16 '18