I followed the instructions of the final drone exam but the gradebot always says that this is executed wrong. Can anyone check if my code is right?
Here is the error info
✖ [16:18:21] [assess] /rec_pose_as action not executed correctly.
Please check:
- Is your action server providing the list of Pose data after 20 seconds?
- The custom action message should be named RecordPose.action
- Start the server, manually call the action and check the output.
And here is the code for Task3
#! /usr/bin/env python
import rospy
import actionlib
from basics_exam.msg import RecordPoseAction, RecordPoseResult
from nav_msgs.msg import Odometry
class CheckDistanceActionClass(object):
_result = RecordPoseResult()
_poses = []
def startServer(self):
self._as = actionlib.SimpleActionServer('/rec_pose_as', RecordPoseAction, self.goal_callback, False)
self.sub = rospy.Subscriber('/ground_truth/state', Odometry, self.callback)
rospy.loginfo("Server Start.")
self._as.start()
def callback(self, msg):
global var
var = msg.pose.pose
self._poses.append(var)
def goal_callback(self, goal):
rate = rospy.Rate(1)
global var
for i in range(20):
if self._as.is_preempt_requested():
rospy.loginfo('Action Preempted.')
self._as.set_preempted()
rate.sleep()
self._result.poses = self._poses
self.sub.unregister()
for item in self._result.poses:
print(item)
self._as.set_succeeded(self._result)
if __name__ == "__main__":
rospy.init_node('rec_pose_as')
CheckDistanceActionClass().startServer()
rospy.spin()
BTW, the take off launched by gradebot sometimes flies too low so it may somehow crash into object, but manually launching the take off script does not cause this… Weird.