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

Mission download protocol implementation #1039

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions dronekit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1232,13 +1232,20 @@ def listener(self, name, m):
self._wp_loaded = True
self._wp_uploaded = None
self._wpts_dirty = False
#
self._wp_downloading = False
self._wp_mission_count = False
self._wp_request_timestamp = 0.0
self._wp_timeout = 0.5
#
self._commands = CommandSequence(self)

@self.on_message(['WAYPOINT_COUNT', 'MISSION_COUNT'])
def listener(self, name, msg):
if not self._wp_loaded:
self._wploader.clear()
self._wploader.expected_count = msg.count
self._wp_mission_count = True
self._master.waypoint_request_send(0)

@self.on_message(['HOME_POSITION'])
Expand All @@ -1261,11 +1268,12 @@ def listener(self, name, msg):
pass
else:
self._wploader.add(msg)

if msg.seq + 1 < self._wploader.expected_count:
self._wp_request_timestamp = time.time()
self._master.waypoint_request_send(msg.seq + 1)
else:
self._wp_loaded = True
self._wp_downloading = False
self.notify_attribute_listeners('commands', self.commands)

# Waypoint send to master
Expand All @@ -1277,7 +1285,26 @@ def listener(self, name, msg):
self._master.mav.send(wp)
self._wp_uploaded[msg.seq] = True

# TODO: Waypoint loop listeners
@handler.forward_loop
def listener(_):
# Waypoint loop listener
dt = time.time() - self._wp_request_timestamp
if self._wp_downloading is True and dt >= self._wp_timeout:
# Initiated wp download process but timeout occured
if self._wp_mission_count is False:
# Re-request whole mission in case mission count did not arrive
self._wp_request_timestamp = time.time()
self._master.waypoint_request_list_send()
else:
# Re-request next mission item to keep up with the rest items
if not self._wploader.wpoints:
# if none of the items did not arrive
seq = 0
else:
seq = self._wploader.wpoints[-1].seq + 1

self._wp_request_timestamp = time.time()
self._master.waypoint_request_send(seq)

# Parameters.

Expand Down Expand Up @@ -2960,7 +2987,10 @@ def download(self):
self.wait_ready()
self._vehicle._ready_attrs.remove('commands')
self._vehicle._wp_loaded = False
self._vehicle._wp_mission_count = False
self._vehicle._wp_request_timestamp = time.time()
self._vehicle._master.waypoint_request_list_send()
self._vehicle._wp_downloading = True
# BIG FIXME - wait for full wpt download before allowing any of the accessors to work

def wait_ready(self, **kwargs):
Expand Down