Hi, I’m a little confused as to where I’m going wrong with the Topics Quiz.
I’ve only gotten the robot to move and turn left for now, but I think I’m not actually using the data from the subscriber? When I do rostopic echo /kobuki/laser/scan, nothing is returned.
Can someone check my code and see where I’m going wrong or what I’ve misunderstood about the quiz? My launcher is defined correctly.
#! /usr/bin/env python
import rospy
from geometry_msgs.msg import Twist
from sensor_msgs.msg import LaserScan
rospy.init_node('tp')
pub = rospy.Publisher('/cmd_vel', Twist, queue_size=1)
rate = rospy.Rate(2)
move = Twist()
#function that recieves parameter msg and prints data in msg
def callback(msg):
a = msg.ranges[360]
print(a)
if a > 1 :
move.linear.x = 0.5
move.angular.z = 0
elif a < 1:
move.angular.z = 0.5
move.linear.x = 0
#sub object listens to topic and calls callback every time it reads
sub = rospy.Subscriber('/kobuki/laser/scan', LaserScan, callback)
while not rospy.is_shutdown():
# Publish the message
pub.publish(move)
# Make sure the publish rate maintains at 2 Hz
rate.sleep()
Thank you!