Hello,
I have gotten my code foundation for ROS certificate at 90 percent but I really want to know why my task3.py runs perfectly but when the grading system runs it, I get this error “get_laser_readings method does not work properly” and the robot continues moving into the environment for a long time before it eventually stops. Please can you help me with this problem? My code is shown below, thank you.
#!/usr/bin/env python
import rospy
from geometry_msgs.msg import Twist
from sensor_msgs.msg import LaserScan
import time
class ExamControl(object):
def __init__(self):
rospy.init_node('Robot_move_2')
self._laser_sub = rospy.Subscriber('/kobuki/laser/scan', LaserScan, self.callback)
self._laser_scan = LaserScan()
self._cmd_pub = rospy.Publisher('/cmd_vel', Twist, queue_size=1)
self._twist_move = Twist()
#self.rate = rospy.Rate(2)
self.ctrl_c = False
rospy.spin()
rospy.on_shutdown(self.shutdownhook)
def callback(self, msg):
self.laser_msg = msg
self.get_laser_readings()
self.wait()
def get_laser_readings(self):
return [self.laser_msg.ranges[719], self.laser_msg.ranges[0]]
def wait(self):
self.main()
def main(self):
self._twist_move.linear.x = 0.4
self._twist_move.angular.z = -0.01
self._cmd_pub.publish(self._twist_move)
self.laser_msg.ranges[719]
self.laser_msg.ranges[0]
if self.laser_msg.ranges[0] > 6.9:
self._twist_move.linear.x = 0.0
self._twist_move.angular.z = 0.0
self._cmd_pub.publish(self._twist_move)
self.shutdownhook()
else:
pass
def shutdownhook(self):
# works better than the rospy.is_shut_down()
global ctrl_c
time.sleep(10)
rospy.signal_shutdown("Robot Execution done")
#self.stop()
print "shutdown time!"
self.ctrl_c = True
if name == ‘main’:
rospy.loginfo("Start Process")
#ExamControl_object = ExamControl()
rate = rospy.Rate(2)