Skip to content

Commit 2cf6b14

Browse files
committed
mission_item_protocols: add support for opaque mission IDs
only support for warning of stale fences/rallypoints/missions ATM
1 parent efd6720 commit 2cf6b14

File tree

4 files changed

+70
-8
lines changed

4 files changed

+70
-8
lines changed

Diff for: MAVProxy/modules/lib/mission_item_protocol.py

+58-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from pymavlink import mavutil
1616
from MAVProxy.modules.lib import mp_module
17+
from MAVProxy.modules.lib import mp_settings
1718
from MAVProxy.modules.lib import mp_util
1819
if mp_util.has_wxpython:
1920
from MAVProxy.modules.lib.mp_menu import MPMenuCallFileDialog
@@ -50,6 +51,33 @@ def __init__(self, mpstate, name, description, **args):
5051
self.upload_start = None
5152
self.last_get_home = time.time()
5253
self.ftp_count = None
54+
self.mip_settings = mp_settings.MPSettings([
55+
('autorefresh', int, 1),
56+
])
57+
58+
class OpaqueInformation():
59+
'''class to keep track of what sysid/compid pair has what'''
60+
def __init__(self):
61+
self.have_id = -100 # meaning "we don't know"
62+
self.autopilot_id = -100
63+
self.mission_stale = False
64+
self.mission_stale_warn_time = 0
65+
self.expected_opaque_id = None
66+
67+
def set_autopilot_id(self, value):
68+
self.autopilot_id = value
69+
70+
def set_have_id(self, value):
71+
self.have_id = value
72+
73+
def set_expected(self, value):
74+
'''value we are expecting to have after a transfer'''
75+
self.expected_opaque_id = value
76+
77+
def transfer_complete(self):
78+
self.have_id = self.expected_opaque_id
79+
80+
self.opaque = OpaqueInformation()
5381

5482
if self.continue_mode and self.logdir is not None:
5583
waytxt = os.path.join(mpstate.status.logdir, self.save_filename())
@@ -250,10 +278,7 @@ def mavlink_packet(self, m):
250278
if mtype in ['MISSION_COUNT']:
251279
if getattr(m, 'mission_type', 0) != self.mav_mission_type():
252280
return
253-
if self.wp_op is None:
254-
if self.wploader.expected_count != m.count:
255-
self.console.writeln("Mission is stale")
256-
else:
281+
if self.wp_op is not None:
257282
self.wploader.clear()
258283
self.console.writeln("Requesting %u %s t=%s now=%s" % (
259284
m.count,
@@ -262,7 +287,10 @@ def mavlink_packet(self, m):
262287
time.asctime()))
263288
self.wploader.expected_count = m.count
264289
self.send_wp_requests()
290+
self.opaque.set_expected(getattr(m, 'opaque_id', 0))
265291

292+
elif mtype in ['MISSION_CURRENT']:
293+
self.opaque.set_autopilot_id(getattr(m, self.MISSION_CURRENT_opaque_id_attribute(), 0))
266294
elif mtype in ['MISSION_ITEM', 'MISSION_ITEM_INT'] and self.wp_op is not None:
267295
if m.get_type() == 'MISSION_ITEM_INT':
268296
if getattr(m, 'mission_type', 0) != self.mav_mission_type():
@@ -293,6 +321,7 @@ def mavlink_packet(self, m):
293321
self.wp_op = None
294322
self.wp_requested = {}
295323
self.wp_received = {}
324+
self.opaque.transfer_complete()
296325

297326
elif mtype in frozenset(["MISSION_REQUEST", "MISSION_REQUEST_INT"]):
298327
self.process_waypoint_request(m, self.master)
@@ -309,6 +338,7 @@ def idle_task(self):
309338
self.send_wp_requests(wps)
310339

311340
self.idle_task_add_menu_items()
341+
self.idle_task_check_opaque_id()
312342

313343
def idle_task_add_menu_items(self):
314344
'''check for load of other modules, add our items as required'''
@@ -331,7 +361,27 @@ def idle_task_add_menu_items(self):
331361
else:
332362
self.menu_added_map = False
333363

364+
def idle_task_check_opaque_id(self):
365+
'''the vehicle may return an identifier for its onboard mission.
366+
Check it against what we think is on the vehicle, emit stale
367+
message if we detect a mismatch'''
368+
if self.opaque.have_id == self.opaque.autopilot_id:
369+
# reset so we work on things straight away:
370+
self.opaque.mission_stale_warn_time = 0
371+
return
372+
now = time.time()
373+
if now - self.opaque.mission_stale_warn_time < 30:
374+
return
375+
self.opaque.mission_stale_warn_time = now
376+
if self.mip_settings.autorefresh:
377+
self.say(f"Refreshing {self.itemstype()}")
378+
self.cmd_list([])
379+
return
380+
self.opaque.mission_stale_warn_time = now
381+
self.say(f"{self.itemstype()} mismatch vehicle vs MAVProxy")
382+
334383
def has_location(self, cmd_id):
384+
335385
'''return True if a WP command has a location'''
336386
if cmd_id in mavutil.mavlink.enums['MAV_CMD'].keys():
337387
cmd_enum = mavutil.mavlink.enums['MAV_CMD'][cmd_id]
@@ -899,12 +949,16 @@ def commands(self):
899949
"savelocal": self.cmd_savelocal,
900950
"show": (self.cmd_show, ["(FILENAME)"]),
901951
"status": self.cmd_status,
952+
"setting": self.setting,
902953
}
903954

904955
def usage(self):
905956
subcommands = "|".join(sorted(self.commands().keys()))
906957
return "usage: %s <%s>" % (self.command_name(), subcommands)
907958

959+
def setting(self, args):
960+
self.settings.command(args[1:])
961+
908962
def cmd_wp(self, args):
909963
'''waypoint commands'''
910964
if len(args) < 1:

Diff for: MAVProxy/modules/mavproxy_fence.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ def count(self):
6969
'''return number of waypoints'''
7070
return self.wploader.count()
7171

72+
def MISSION_CURRENT_opaque_id_attribute(self):
73+
return "fence_id"
74+
7275
def circles_of_type(self, t):
7376
'''return a list of Circle fences of a specific type - a single
7477
MISSION_ITEM'''
@@ -223,8 +226,10 @@ def handle_sys_status(self, m):
223226
self.console.set_status('Fence', 'FEN', row=0, fg='red')
224227

225228
def mavlink_packet(self, m):
226-
if m.get_type() == 'SYS_STATUS' and self.message_is_from_primary_vehicle(m):
229+
mtype = m.get_type()
230+
if mtype == 'SYS_STATUS' and self.message_is_from_primary_vehicle(m):
227231
self.handle_sys_status(m)
232+
228233
super(FenceModule, self).mavlink_packet(m)
229234

230235
def apply_function_to_points(self, function):

Diff for: MAVProxy/modules/mavproxy_rally.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ def command_name(self):
3030
'''command-line command name'''
3131
return "rally"
3232

33+
def MISSION_CURRENT_opaque_id_attribute(self):
34+
return "rally_point"
35+
3336
def cmd_rally_add(self, args):
3437
'''add a rally point at the last map click position'''
3538
if not self.check_have_list():
@@ -122,9 +125,6 @@ def itemtype(self):
122125
'''returns description of item'''
123126
return 'rally item'
124127

125-
def mavlink_packet(self, p):
126-
super(RallyModule, self).mavlink_packet(p)
127-
128128
def gui_menu_items(self):
129129
ret = super(RallyModule, self).gui_menu_items()
130130
ret.extend([

Diff for: MAVProxy/modules/mavproxy_wp.py

+3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ def index_from_0(self):
7171
def command_name(self):
7272
return "wp"
7373

74+
def MISSION_CURRENT_opaque_id_attribute(self):
75+
return "mission_id"
76+
7477
def mavlink_packet(self, m):
7578
'''handle an incoming mavlink packet'''
7679
mtype = m.get_type()

0 commit comments

Comments
 (0)