# Actions\_Quiz - GradeBot Failed even though code works correctly

**URL:** <https://get-help.theconstruct.ai/t/actions-quiz-gradebot-failed-even-though-code-works-correctly/32639>\
**Category:** ROS Basics In 5 Days (Python)\
**Created:** [September 30, 2024, 5:45am UTC](https://get-help.theconstruct.ai/t/actions-quiz-gradebot-failed-even-though-code-works-correctly/32639 "2024-09-30T05:45:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![aryakurian](https://get-help.theconstruct.ai/letter_avatar_proxy/v4/letter/a/2acd7d/32.png) [@aryakurian](https://get-help.theconstruct.ai/u/aryakurian)\
**Post date:** [September 30, 2024, 5:45am UTC](https://get-help.theconstruct.ai/t/actions-quiz-gradebot-failed-even-though-code-works-correctly/32639/1 "2024-09-30T05:45:25Z")

</div>

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](https://get-help.theconstruct.ai/uploads/default/original/2X/b/b25c68962a5090b0dfb32666fbdf58eca686e7e1.png)

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.

---

<div class="post-metadata">

**Author:** ![bayodesegun](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/bayodesegun/32/10684_2.png) [@bayodesegun](https://get-help.theconstruct.ai/u/bayodesegun)\
**Post date:** [September 30, 2024, 9:37am UTC](https://get-help.theconstruct.ai/t/actions-quiz-gradebot-failed-even-though-code-works-correctly/32639/2 "2024-09-30T09:37:34Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![aryakurian](https://get-help.theconstruct.ai/letter_avatar_proxy/v4/letter/a/2acd7d/32.png) [@aryakurian](https://get-help.theconstruct.ai/u/aryakurian)\
**Post date:** [September 30, 2024, 9:58am UTC](https://get-help.theconstruct.ai/t/actions-quiz-gradebot-failed-even-though-code-works-correctly/32639/3 "2024-09-30T09:58:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bayodesegun](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/bayodesegun/32/10684_2.png) [@bayodesegun](https://get-help.theconstruct.ai/u/bayodesegun)\
**Post date:** [September 30, 2024, 10:27am UTC](https://get-help.theconstruct.ai/t/actions-quiz-gradebot-failed-even-though-code-works-correctly/32639/4 "2024-09-30T10:27:16Z")

</div>

> [@bayodesegun](#):
>
> were you asked to do this in the quiz?

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

---

<div class="post-metadata">

**Author:** ![aryakurian](https://get-help.theconstruct.ai/letter_avatar_proxy/v4/letter/a/2acd7d/32.png) [@aryakurian](https://get-help.theconstruct.ai/u/aryakurian)\
**Post date:** [September 30, 2024, 11:10am UTC](https://get-help.theconstruct.ai/t/actions-quiz-gradebot-failed-even-though-code-works-correctly/32639/5 "2024-09-30T11:10:59Z")

</div>

I fixed the issue, thank you for your help.

---

<div class="post-metadata">

**Author:** ![system](https://get-help.theconstruct.ai/uploads/default/original/2X/9/9d3ce8305cc0d0d9b6e07d15767a6f245c526f1b.jpeg) [@system](https://get-help.theconstruct.ai/u/system)\
**Post date:** [October 5, 2024, 11:11am UTC](https://get-help.theconstruct.ai/t/actions-quiz-gradebot-failed-even-though-code-works-correctly/32639/6 "2024-10-05T11:11:54Z")

</div>

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