I need some help with a Python program, I am now in the 5 days basic ROS program and I’m having truble with exercise 4.3 (Topics quiz).
In the Python program I want to publish to ‘/cmd_vel’ and I want to subscribe to ‘/kobuki/laser/scan’.
Every time I run it I have this error:
#! /usr/bin/env python import rospy from geometry_msgs.msg import Twist from sensor_msgs.msg import LaserScan rospy.init_node('topics_quiz_node') pub = rospy.Publisher('/cmd_vel', Twist, queue_size=1) rate = rospy.Rate(2) move = Twist() move.linear.x = 0 move.angular.z = 0 while not rospy.is_shutdown(): def callback(msg): print(msg) sub = rospy.Subscriber('/kobuki/laser/scan', LaserScan, callback) pub.publish(move) rate.sleep()
When I comment out the sub = rospy. … and def callback then the program works.
< !-- my package launch file →
< node pkg=“topics_quiz” type=“my_script.py” name=“topics_quiz_node” output=“screen”>
Thank you for helping me!