Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Race condition when updating and fetching commands #227

Closed
hamishwillee opened this issue Jul 22, 2015 · 6 comments
Closed

Race condition when updating and fetching commands #227

hamishwillee opened this issue Jul 22, 2015 · 6 comments
Labels
Milestone

Comments

@hamishwillee
Copy link
Contributor

Consider the code below (gist at https://gist.github.com/hamishwillee/9607b3707fb942d59abf#file-gistfile1-txt-L36)

"""
Tests race condition when downloading items
"""

import time
import math
from droneapi.lib import VehicleMode, Location, Command
from pymavlink import mavutil


api = local_connect()
vehicle = api.get_vehicles()[0]


def currentmission():
    """
    Print the current mission
    """
    print "current mission:"
    mycmds = vehicle.commands
    mycmds.download()
    mycmds.wait_valid()
    for cmd in mycmds:
        print cmd


currentmission()

print 'Add dummy waypoint'
vehicle.commands.add(Command( 0, 0, 0, mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT, 
                mavutil.mavlink.MAV_CMD_NAV_WAYPOINT, 0, 0, 
                0, 0, 0, 0, 10, 10, 10))
vehicle.flush() # Send commands

print "Wait 2s for update"
time.sleep(2)

print 'Show mission'
currentmission()

The code works as is, but if the time.sleep(2) is removed then all waypoints are wiped (except the home waypoint).

This shouldn't happen because in theory the flush means that the new waypoint is sent, and this should occur before flush returns - ie before we have a chance to do the new download of the current commands.

I think either we're not doing this properly and the vehicle.command is being wiped by the second call before the flush returns OR the autopilot is confused by our messaging.

@tcr3dr Thoughts?

@hamishwillee
Copy link
Contributor Author

I THINK this is fixed by #384.

@tcr3dr
Copy link
Contributor

tcr3dr commented Nov 3, 2015

We could stand to have a test for this, heh.

@hamishwillee
Copy link
Contributor Author

Well, my test worked against dronekit-sitl copter 3.3. But I suspect that proves nothing. Yes, a proper test is a very good idea.

tcr3dr added a commit that referenced this issue Nov 9, 2015
@tcr3dr
Copy link
Contributor

tcr3dr commented Nov 9, 2015

@hamishwillee Check that #439 is a good reduction of the test case?

@tcr3dr tcr3dr modified the milestone: v2.0.0 Nov 10, 2015
@hamishwillee
Copy link
Contributor Author

@tcr3dr Yes, the #430 verifies that the mission is flushed before the subsequent download occurs (and can swamp it)

tcr3dr added a commit that referenced this issue Nov 10, 2015
tcr3dr added a commit that referenced this issue Nov 10, 2015
@tcr3dr
Copy link
Contributor

tcr3dr commented Nov 10, 2015

#439 merged, so this issue should not suffer from a regression.

@tcr3dr tcr3dr closed this as completed Nov 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants