0

I have a ROS subscriber node receiving Twist geometry messages from another computer.

I can see on the publisher side that the controls are working but the subscriber reports them as 0. I'm guessing that the detail is being lost in the string translation but I'm not sure?

For example: Publisher output: currently: speed 0.8052550000000004 turn 1.6105100000000008

Subscriber output (should reflect the publisher): [INFO] [1660107037.983795]: /listener_4078_1660106914890 Linear x: 0.0 y: 0.0 z: 0.0 Angular x: 0.0 y: 0.0 z: 0.0

from geometry_msgs.msg import Twist

def callback(data):
    global msg
    rospy.loginfo(rospy.get_caller_id() + "\n Linear \n" + str(msg.linear) + '\n Angular \n' + str(msg.angular))

def listener():
    global msg
    msg = Twist()
    rospy.init_node('listener', anonymous=True)
    rospy.Subscriber('/cmd_vel', Twist, callback)
    rospy.spin()

if __name__ == '__main__':
    listener()

Any thoughts about how I can extract the float values at the subscriber side?

Andres V
  • 19
  • 4

1 Answers1

1

Your printing out the value of msg which is just a global variable and not the Twist message received. You should either be outputting data in your log statement or assign it to msg like so:

def callback(data):
    global msg
    msg = data
    rospy.loginfo(rospy.get_caller_id() + "\n Linear \n" + str(msg.linear) + '\n Angular \n' + str(msg.angular))
BTables
  • 4,413
  • 2
  • 11
  • 30