I am able to Takeoff and Land the drone using below code as per the quiz.
But when submit the quiz , it just give me marks 6 and said not successfully take off and landing.
Please correct me if my understanding is not right.
Here is the code #! /usr/bin/env python
import rospy
import actionlib
import time
from actions_quiz.msg import CustomActionMsgFeedback, CustomActionMsgResult, CustomActionMsgAction
from std_msgs.msg import Empty
class drone_move(object):
_feedback = CustomActionMsgFeedback()
_result = CustomActionMsgResult()
def __init__(self):
self._as = actionlib.SimpleActionServer(
"action_custom_msg_as", CustomActionMsgAction, self.goal_callback, False)
self._as.start()
def goal_callback(self, goal):
success = True
#r = rate.sleep(1)
#r = rospy.Rate(10)
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()
if self._as.is_preempt_requested():
rospy.loginfo('The goal has been cancelled/preempted')
self._as.set_preempted()
success = False
drone_actions = goal.goal
if drone_actions == "TAKEOFF":
self._pub_takeoff.publish(self._takeoff_msg)
rospy.loginfo('Taking off...')
elif drone_actions == "LAND":
self._pub_land.publish(self._land_msg)
rospy.loginfo('LANDING...')
self._feedback.feedback = goal.goal
self._as.publish_feedback(self._feedback)
if success:
self._as.set_succeeded(self._result)
if name == ‘main’:
rospy.init_node(‘actions_quiz_node’)
rate = rospy.Rate(1)
drone_move()
rospy.spin()