I have a simple subscriber class that I made but I’m having trouble using it.
#! /usr/bin/env python import rospy #from std_msgs.msg import Int32 from nav_msgs.msg import Odometry #from sensor_msgs.msg import LaserScan class OdomSub: def __init__(self): self.sub = rospy.Subscriber('/odom', Odometry, self.callback) def callback(self, msg): if __name__ == '__main__': print msg.pose.pose.position.y return msg if __name__ == "__main__": rospy.init_node('odom_subscriber') read_odom = OdomSub() rospy.spin()
And in another python file I want to return the msg from the callback whenever I call it. This is what I have.
import rospy from odom_sub import OdomSub rospy.init_node('odom_subscriber') read_odom = OdomSub() print read_odom rospy.spin()
I want it to print the odometry msg but instead it prints this in the terminal.
<odom_sub.OdomSub instance at 0x7f12e0f25128>
I’m still very new and i think i had this problem earlier in the course. Maybe i should be approaching this problem differently. If you could give me a hand to make it so I can use out the odometry msg from the other program that would be great. Thanks