Skip to content
Merged
Show file tree
Hide file tree
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
16 changes: 13 additions & 3 deletions dronekit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

# Public re-exports
Vehicle = dronekit.lib.Vehicle
Command = dronekit.lib.Command
CommandSequence = dronekit.lib.CommandSequence
VehicleMode = dronekit.lib.VehicleMode
LocationGlobal = dronekit.lib.LocationGlobal
LocationLocal = dronekit.lib.LocationLocal
Expand Down Expand Up @@ -68,6 +70,7 @@ def __init__(self, master, vehicle_class=Vehicle):
# waypoints
self.wploader = mavwp.MAVWPLoader()
self.wp_loaded = True
self.wp_uploaded = None

# Attaches message listeners.
self.message_listeners = dict()
Expand Down Expand Up @@ -266,7 +269,11 @@ def send_all_waypoints(self):
"""
self.master.waypoint_clear_all_send()
if self.wploader.count() > 0:
self.wp_uploaded = [False]*self.wploader.count()
self.master.waypoint_count_send(self.wploader.count())
while False in self.wp_uploaded:
time.sleep(0.1)
self.wp_uploaded = None

def fix_targets(self, message):
pass
Expand Down Expand Up @@ -509,9 +516,12 @@ def mavlink_thread():
self.last_waypoint = msg.seq

# Waypoint send to master
# TODO
if msg.get_type() in ["WAYPOINT_REQUEST", "MISSION_REQUEST"]:
pass
if self.wp_uploaded != None and msg.get_type() in ["WAYPOINT_REQUEST", "MISSION_REQUEST"]:
wp = self.wploader.wp(msg.seq)
wp.target_system = self.target_system
wp.target_component = self.target_component
self.master.mav.send(wp)
self.wp_uploaded[msg.seq] = True

# Heartbeat: armed + mode update
if msg.get_type() == 'HEARTBEAT':
Expand Down
8 changes: 8 additions & 0 deletions dronekit/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,14 @@ def next(self, index):
"""
self.__module.master.waypoint_set_current_send(index)

def __len__(self):
'''
Return number of waypoints.

:return: The number of waypoints in the sequence.
'''
return self.__module.wploader.count()

def __getitem__(self, index):
return self.__module.wploader.wp(index)

Expand Down
32 changes: 28 additions & 4 deletions tests/sitl/test_waypoints.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,42 @@
import time
import math
from dronekit import connect, VehicleMode, LocationGlobal
from dronekit import connect, VehicleMode, LocationGlobal, Command
from dronekit.tools import with_sitl
from nose.tools import assert_not_equals
from nose.tools import assert_not_equals, assert_equals

# This test runs first!
@with_sitl
def test_parameter(connpath):
# Connect to the Vehicle
vehicle = connect(connpath, await_params=True)

# Initial
cmds = vehicle.commands
cmds.download()
cmds.wait_valid()
assert_equals(len(cmds), 1)

vehicle.commands.clear()
# After clearing
cmds.clear()
vehicle.flush()
cmds.download()
cmds.wait_valid()
assert_equals(len(cmds), 1)

# Upload
for command in [
Command(0, 0, 0, 0, 16, 1, 1, 0.0, 0.0, 0.0, 0.0, -35.3605, 149.172363, 747.0),
Command(0, 0, 0, 3, 22, 0, 1, 0.0, 0.0, 0.0, 0.0, -35.359831, 149.166334, 100.0),
Command(0, 0, 0, 3, 16, 0, 1, 0.0, 0.0, 0.0, 0.0, -35.363489, 149.167213, 100.0),
Command(0, 0, 0, 3, 16, 0, 1, 0.0, 0.0, 0.0, 0.0, -35.355491, 149.169595, 100.0),
Command(0, 0, 0, 3, 16, 0, 1, 0.0, 0.0, 0.0, 0.0, -35.355071, 149.175839, 100.0),
Command(0, 0, 0, 3, 113, 0, 1, 0.0, 0.0, 0.0, 0.0, -35.362666, 149.178715, 22222.0),
Command(0, 0, 0, 3, 115, 0, 1, 2.0, 22.0, 1.0, 3.0, 0.0, 0.0, 0.0),
Command(0, 0, 0, 3, 16, 0, 1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0),
]:
cmds.add(command)
vehicle.flush()

# After upload
cmds.download()
cmds.wait_valid()
assert_equals(len(cmds), 9)