Hello there,
for the 9.4 actions_quiz, when I launch the action_custom_msg.launch myself it works as expected. Taking off with TAKEOFF message and Landing with LAND message. However, the grader says the landing is not fine and the drone will taking off after landing (8/10) while I did not see this action when I manually used roslaunch.
Here is my code:
#! /usr/bin/env python
import time
import rospy
import actionlib
from actions_quiz.msg import CustomActionMsgAction, CustomActionMsgResult, CustomActionMsgFeedback
from std_msgs.msg import Empty
class MoveDrone(object):
def __init__(self):
self._as = actionlib.SimpleActionServer(
"action_custom_msg_as", CustomActionMsgAction, self.goal_callback, False)
self._as.start()
self.ctrl_c = False
self.rate = rospy.Rate(10)
self._feedback = CustomActionMsgFeedback()
self._result = CustomActionMsgResult()
def goal_callback(self, goal):
r = rospy.Rate(1)
success = True
self._pub_takeoff = rospy.Publisher(
'/drone/takeoff', Empty, queue_size=1)
self._takeoff_msg = Empty()
self._pub_land = rospy.Publisher('/drone/land', Empty, queue_size=1)
self._land_msg = Empty()
command = goal.goal
while command.upper() == "TAKEOFF":
if self._as.is_preempt_requested():
rospy.loginfo('The goal has been cancelled/preempted')
self._as.set_preempted()
success = False
break
self._pub_takeoff.publish(self._takeoff_msg)
rospy.loginfo('Taking off...')
self._feedback.feedback = "taking off"
self._as.publish_feedback(self._feedback)
r.sleep()
i = 0
while command.upper() == "LAND" and i != 3:
# check that preempt (cancelation) has not been requested by the action client
if self._as.is_preempt_requested():
rospy.loginfo('The goal has been cancelled/preempted')
# the following line, sets the client in preempted state (goal cancelled)
self._as.set_preempted()
success = False
break
self._pub_land.publish(self._land_msg)
rospy.loginfo('Landing...')
self._feedback.feedback = "landing"
self._as.publish_feedback(self._feedback)
time.sleep(1)
i += 1
if success:
self._result = 'success'
self._as.set_succeeded(self._result)
if name == ‘main’:
rospy.init_node(‘move_square’)
MoveDrone()
rospy.spin()
I would appreciate if anyone can help me in this regard.