Actions_Quiz - GradeBot Failed even though code works correctly

I am taking the actions_quiz, the drone takes off and lands (without the drone taking off first) correctly in the simulation. However, Gradebot marked the landing as incorrect. The code I have is as follows.


#!/usr/bin/env python
import rospy
import actionlib
from actions_quiz.msg import CustomActionMsgAction, CustomActionMsgFeedback
from std_msgs.msg import Empty
from geometry_msgs.msg import Twist  # Import Twist for velocity control

class DroneActionServer:
    def __init__(self):
        # Create the action server
        self._as = actionlib.SimpleActionServer('/action_custom_msg_as', CustomActionMsgAction, self.execute_callback, False)
        self._as.start()

        # Publishers for takeoff, landing, and velocity control
        self.takeoff_pub = rospy.Publisher('/drone/takeoff', Empty, queue_size=1)
        self.land_pub = rospy.Publisher('/drone/land', Empty, queue_size=1)
        self.velocity_pub = rospy.Publisher('/cmd_vel', Twist, queue_size=1)  # Velocity control publisher

        self.feedback = CustomActionMsgFeedback()
        self.rate = rospy.Rate(1)

    def execute_callback(self, goal):
        if goal.goal == "TAKEOFF":
            rospy.loginfo("Taking off...")

            # Publish Empty message to takeoff topic (if necessary)
            rospy.sleep(1)
            self.takeoff_pub.publish(Empty())

            # Use velocity control to simulate takeoff by increasing the z-axis velocity
            takeoff_twist = Twist()
            takeoff_twist.linear.z = 0.5  # Positive z velocity to go up
            self.velocity_pub.publish(takeoff_twist)

            self.feedback.feedback = "Taking off"
            rospy.sleep(2)  # Let the drone ascend for 3 seconds

            # Stop the drone by setting zero velocity
            takeoff_twist.linear.z = 0.0
            self.velocity_pub.publish(takeoff_twist)

        elif goal.goal == "LAND":
            rospy.loginfo("Landing...")

            # Use velocity control to simulate landing by decreasing the z-axis velocity
            landing_twist = Twist()
            landing_twist.linear.z = -0.5  # Negative z velocity to go down
            rospy.sleep(1)
            self.velocity_pub.publish(landing_twist)

            self.feedback.feedback = "Landing"
            rospy.sleep(6)  # Let the drone descend for 3 seconds

            # Stop the drone by setting zero velocity
            landing_twist.linear.z = 0.0
            self.velocity_pub.publish(landing_twist)

            # Optionally, publish to land topic (if needed for integration with other nodes)
            self.land_pub.publish(Empty())

        self._as.set_succeeded()

if __name__ == '__main__':
    rospy.init_node('drone_action_server')
    DroneActionServer()
    rospy.spin()

The feedback from the gradebot is as attached.
image

I can manually see in the simulation that the drone is landing. Kindly advice on why this is happening and how I can fix it.

I see that you have two different DroneActionServer classes.

  • Why is that?
  • Which one are you using?

I also see that you are publishing to /cmd_vel on one of the classes - were you asked to do this in the quiz?

One of the DroneActionServer class was commented which I have now removed it from the code. I am publishing to /cmd_vel to control the velocity of the drone during takeoff and landing.

You should remove the publishing to /cmd_vel if it’s not required by the quiz.

I fixed the issue, thank you for your help.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.