Problem with Autocorrection in Actions Quiz

Hello

I am currently on the Actions Quiz.
So I submitted my quiz and it does not finish the autocorrection (see screenshot).

It stays there for like forever.

When I run the code by myself everything was working fine.
After my second upload I received 8 points saying that the takeoff was not working appropriately.
Even tho it worked ok when I simulated it by my own.

So therefore I changed the takeoff loop. Before I had no argument which would end the takeoff while-loop, then I changed it to a loop which runs for 3 seconds. The Drone does then stay in the takeoff position.
This is the code:

#! /usr/bin/env python
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):

    rate = 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()

    ActionGoal = goal.goal

    i = 0
    while ActionGoal.upper() == "TAKEOFF" and i != 3:
        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('Drone is taking off')
        self._feedback.feedback = "TAKEOFF"
        self._as.publish_feedback(self._feedback)
        i += 1
        rate.sleep()
        
    i = 0
    while ActionGoal.upper() == "LAND" and i != 3:
        if self._as.is_preempt_requested():
            rospy.loginfo('The goal has been cancelled/preempted')
            self._as.set_preempted()
            success = False
            break
        self._pub_land.publish(self._land_msg)
        rospy.loginfo('Drone is landing')
        self._feedback.feedback = "LANDING"
        self._as.publish_feedback(self._feedback)
        i += 1
        rate.sleep()

    if success:
        self._result = 'success'
        self._as.set_succeeded(self._result)

if name == ‘main’:
rospy.init_node(‘action_custom_msg’)
MoveDrone()
rospy.spin()

But with this code the autocorrection freezes. Since I was not sure if it had to do something with my internet connection I reloaded the page. I was checking if it took me a trial away. It showed me first that I had still 3 trials left. So it looked like no trial was taken away. But then I tried to resubmit it came a message than I received 0 Points.
Then I resubmitted again and run into the same freeze issue (I was waiting for like 30min if something else happens) and had to reload again.

So now I am not even sure how many trials I have left (it shows me 1, but I fear that when I try to resubmit it will again give me 0 points and therefor taken away my last trial).

So therefore I would like to ask for help.

Why does the autocorrection freezes?
I was assuming if it had something to to with the rate.sleep() function.
I tried also with time.sleep(1), but ran into the same issue.
I mean I think it stays in the take-off loop and can’t go out of it, but I don’t know why since in my own simulation it ends the loop after 3 seconds.

Also could you maybe give me more trials?

Thanks in advance for your help

Cheers

Hello @Dkae ,

I’ve reset your trials so that you can keep testing. In any case, could you share your code with me so that I can have a better look at it? You can send me the actions quiz packages to aezquerro@theconstructsim.com

Hi @albertoezquerro

Thanks for your reply. I’ve just sent you the package by mail.

Cheers

Hi @albertoezquerro

Did you receive my email? Did you alreday had time to take a look at it?

Thanks in advance for your help.

Hi @Dkae ,

I think I understand why your program is not working well.

Going through your code, I noticed the following:

  1. You should define the rate, publisher for takeoff and land, and the message for takeoff and land in the __init__() function. Not inside goal_callback().
  2. Your feedback message should be “taking off” and “landing” instead of “TAKEOFF” and “LANDING” respectively.
  3. The drone must stay in the takeoff or landing position until the other command is given. Your code restricts takeoff for 3 seconds and landing for 3 seconds.
  4. Also use a if condition to quickly switch for the goal message. So if “LAND” is the message, your code not not have to evaluate the while loop for “TAKEOFF” and then come to the while loop for “LAND”.

If you fix these issues, you should have it passing in the GradeBot.

Let me know if this worked.

Regards,
Girish

Hi @girishkumar.kannan

Thanks for your reply.

I adjusted the code as you mentioned, but it still gets only 6 points.
What is confusing is that when the gradebot starts the takeoff or landing, I can see on the simulation how the drone is going up, staying in takeoff position and then going down like it is ment to be.
I have the same behaviour when I simulate it by my own.
Since the feedback message of the gradebot is only "Drone did not take off. Things your can check:

  • Is your code taking the drone off correctly?
  • Is your code landing the drone after taking it off? It should NOT. You should use the LAND call for that."

I can’t really figuring out why it does not fully pass the test. Since it does not mention what actually fails. If the message is not received, if the feedback message is not correct, something like this more specific.

Here the code:

#! /usr/bin/env python
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()
    self.rate = rospy.Rate(1)
    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()

def goal_callback(self, goal):

    ActionGoal = goal.goal
    success = True

    if ActionGoal.upper() == "TAKEOFF":
            self._pub_takeoff.publish(self._takeoff_msg)
            rospy.loginfo('Drone is taking off')
            self._feedback.feedback = "taking off"
            self._as.publish_feedback(self._feedback)
            
    if ActionGoal.upper() == "LAND":
            self._pub_land.publish(self._land_msg)
            rospy.loginfo('Drone is landing')
            self._feedback.feedback = "landing"
            self._as.publish_feedback(self._feedback)            
       
    self.rate.sleep()
    
    if success:
            self._result = 'success'
            self._as.set_succeeded(self._result)

if name == ‘main’:
rospy.init_node(‘action_custom_msg’)
MoveDrone()
rospy.spin()

I mean, what I else could expect, is that maybe it fails because the feedback is not sent every second. So I could place the whole thing inside a loop which gives the self._as.publish_feedback(self._feedback) evey second.

So I think if the gradebot could give a more specific response on why it fails, it would be quite helpful.

Sorry for asking so many questions, but it’s a little bit frustrating.

Hello @Dkae ,

Sorry for the inconvenience. I’ve been testing the package you sent me and it looks like the issue comes from the auto-grader (a weird timeout in the script). I’ve done a modification that I believe will solve the problem. In my tests, I was getting a score of 10. Could you please try to correct it again and let me know if it works for you as well?

1 Like

Hi @Dkae ,

Just some minor corrections to your modified code:

  1. You must include the block that checks for goal preemption in both goal message cases (takeoff and land).
  2. You should use if-else (or if-elif-else) instead of if-if.

But don’t bother with the if-else for now. Actually, your original code (the one that you posted before modification) will work fine. Just remove the time constraint there. That is, remove the i = 0 and i != 3 and i += 1 lines in your code. The rate.sleep() will handle the timing for you.

Everything else is fine.

Regards,
Girish

1 Like

Hi @girishkumar.kannan & @albertoezquerro

Thanks a lot for your help!

I was finally able to get the 10 score :smiley: