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

Subscriber Node No Msg

asked 2016-01-03 10:26:06 -0500

theizu gravatar image

I have used the sample code for Sub a topic in python but however I am trying to subscribe a topic which gives out a the coordinates, image and etc in single data stream from rtabmap/graph topic. However doing this is just doesn't print out any msg at all. Do i need to convert the data into str or something cause all i need is the raw data in text?

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

def callback(data):
    rospy.loginfo(rospy.get_caller_id() + "I heard %s", data.data)

def listener():

    # In ROS, nodes are uniquely named. If two nodes with the same
    # node are launched, the previous one is kicked off. The
    # anonymous=True flag means that rospy will choose a unique
    # name for our 'listener' node so that multiple listeners can
    # run simultaneously.
    rospy.init_node('listener', anonymous=True)

    rospy.Subscriber("rtabmap/graph", String, callback)

    # spin() simply keeps python from exiting until this node is stopped
    rospy.spin()

if __name__ == '__main__':
    listener()
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-01-03 11:25:07 -0500

updated 2016-01-04 05:19:17 -0500

You need code that receives a message of the same name, and data type as the message that is transmitted.I suspect your code currently has the same topic name, but the format it is currently looking for (String) is not the same as what is being sent.

What format is the message rtabmap/graph ?

You would need to import that message type at the top of you code, and then create a listener of that type (so that the data can be parsed correctly when it arrives).

I can't see a topic of that type at http://docs.ros.org/api/rtabmap_ros/h... but there is one called MapGraph.

Assuming there is a Graph type then at the top of the code you would import that definition rather than String

from rtabmap_ros.msg import Graph

rather than the line that imported String

and where you setup the the subscriber

rospy.Subscriber("rtabmap/graph", Graph, callback)

Inside your callback you would now be able to access individual bits of the message using the dot notation

data.partOfMessageYouAreTryingToAccess

based on the message definition that tells you the names of the parts of the message (I can't find the definition so don't know what there is.

if that doesn't work try MapGraph

edit flag offensive delete link more

Comments

When i rostopic type /rtabmap/graph i get back rtabmap_ros/Graph

So i think its is own type. So how do I import this kind for example?

theizu gravatar image theizu  ( 2016-01-03 23:27:01 -0500 )edit

Which version/example are you using? As on rtabmap_ros wiki:

$ roslaunch rtabmap_ros rgbd_mapping.launch
$ rostopic type /rtabmap/mapGraph
rtabmap_ros/MapGraph
matlabbe gravatar image matlabbe  ( 2016-01-04 14:31:11 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2016-01-03 10:26:06 -0500

Seen: 225 times

Last updated: Jan 04 '16