Subscribing to a topic with Python

asked 2016-12-15 19:00:59 -0500

AkaTomo93 gravatar image

updated 2016-12-15 19:01:56 -0500

Hello people, I've had trouble subsciribing to a topic of type: /robot0/odom

Where odom is a type of nav_msgs/Odometry and it brings me x,y coordinates and orientation.

I've written a simple code for this, but when I run the script, it's not printing anything on the terminal.

#!/usr/bin/env python

import rospy
from nav_msgs.msg import Odometry

def callback(msg):

rospy.loginfo('x: {}, y:{}, orientation_z:{},' .format(x,y, orientation_z))

def main():

if __name__ == '__main__':

This code was working well when I had to subscribe on a topic with just rospy.Subscriber("/odom",Odometry,callback), but as soon as I switched the program and the topic became /robot0/odom type I began having problems.

Any help would be really appreciated.

edit retag flag offensive close merge delete



I guess you have the file properly indented and not as you posted it here, otherwise, the node would not work at all.

Check if you actually subscribed to the correct topic: rosnode info YOURNODE, rostopic info /robot0/odom

mgruhler gravatar image mgruhler  ( 2016-12-16 02:05:45 -0500 )edit

Hmm, so when I write rostopic info /robot0/odom I get back:

Type: nav_msgs/Odometry

Publishers: * /robot_manager ( http://tomo:41302/ )

Subscribers: None

What do you think could be the problem here?

AkaTomo93 gravatar image AkaTomo93  ( 2016-12-16 03:29:45 -0500 )edit

WOW? It just started to work without me changing anything, I dont even understand?

I just went to sleep and tried to run the code again.

Thank you so much for helping me anyway, I definitely learned a lot from trying to fix this issue :)

AkaTomo93 gravatar image AkaTomo93  ( 2016-12-16 03:32:38 -0500 )edit