Like the title says, I seem to have a bit of trouble getting topic quiz program to work. It runs but seems to get stuck in an infinite loop. I have consulted the solution but it takes a whole different approach than my effort, so I would like to know where I went wrong.
#! /usr/bin/env python import rospy from geometry_msgs.msg import Twist from sensor_msgs.msg import LaserScan import time class MoveRobot: def __init__(self, speed): rospy.init_node('topics_quiz_node',anonymous=True) self.speed = speed self.time_turn = 7.0 self.pub = rospy.Publisher('/cmd_vel', Twist, queue_size=1) self.sub = rospy.Subscriber('kobuki/laser/scan', LaserScan, self.callback) self.rate = rospy.Rate(2) self.cmd = Twist() def callback(self,msg): laser_msg = msg def get_front_laser(self): return self.laser_msg.ranges def avoid_wall(self): while not rospy.is_shutdown(): self.pub.publish(self.cmd) while self.get_front_laser > 1: self.cmd.linear.x = self.speed self.cmd.linear.x = 0 self.cmd.angular.z = self.speed time.sleep(self.time_turn) self.cmd.linear.x = self.speed self.rate.sleep() mr1 = MoveRobot(0.3) mr1.avoid_wall()