Skip to content

Commit 4449b8a

Browse files
committed
SIYI: add heuristics-based camera stowage, for landing in LOITER
1 parent fe446d6 commit 4449b8a

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

Diff for: MAVProxy/modules/mavproxy_SIYI/__init__.py

+51
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ def __init__(self, mpstate):
296296
MPSetting('thresh_volt_dis', int, 40, range=(20,80)),
297297
MPSetting('thresh_ang_dis', int, 40, range=(30,4000)),
298298
('stow_on_landing', bool, True),
299+
('stow_heuristics_enabled', bool, True),
300+
('stow_heuristics_minalt', float, 20.0), # metres above terrain
301+
('stow_heuristics_maxhorvel', float, 2.0), # metres/second
299302
])
300303
self.add_completion_function('(SIYISETTING)',
301304
self.siyi_settings.completion)
@@ -373,6 +376,13 @@ def __init__(self, mpstate):
373376
self.extended_sys_state_warn_time = 0 # last time we warned about not being able to auto-stow
374377
self.last_landed_state = None
375378

379+
# support retracting camera based on heuristics:
380+
self.landing_heuristics = {
381+
"armed": True,
382+
"last_warning_ms": 0,
383+
"current_terrain_alt": 0,
384+
}
385+
376386
if mp_util.has_wxpython:
377387
menu = MPMenuSubMenu('SIYI',
378388
items=[
@@ -1555,6 +1565,47 @@ def idle_task(self):
15551565
self.extended_sys_state_warn_time = now
15561566
print("SIYI: no EXTENDED_SYS_STATE, can't auto-stow")
15571567

1568+
if self.siyi_settings.stow_heuristics_enabled:
1569+
self.check_stow_on_landing_heuristics()
1570+
1571+
def check_stow_on_landing_heuristics(self):
1572+
tr = self.master.messages.get('TERRAIN_REPORT', None)
1573+
vfr_hud = self.master.messages.get('VFR_HUD', None)
1574+
1575+
if tr is None or vfr_hud is None:
1576+
now = time.time()
1577+
if now - self.landing_heuristics["last_warning_ms"] > 60:
1578+
self.landing_heuristics["last_warning_ms"] = now
1579+
print("SIYI: missing messages, hueristics-stow not available")
1580+
return
1581+
1582+
# first work out whether we should "arm" the stowing; must
1583+
# meet minimum conditions to do so:
1584+
current_terrain_alt = tr.current_height
1585+
if current_terrain_alt > self.siyi_settings.stow_heuristics_minalt + 1:
1586+
# above trigger altitude
1587+
self.landing_heuristics["armed"] = True
1588+
1589+
# now work out whether to stow:
1590+
if not self.landing_heuristics["armed"]:
1591+
return
1592+
1593+
if current_terrain_alt > self.siyi_settings.stow_heuristics_minalt:
1594+
# above the minimum altitude
1595+
return
1596+
1597+
if vfr_hud.groundspeed > self.siyi_settings.stow_heuristics_maxhorvel:
1598+
# travelling rapidly horizontally
1599+
return
1600+
1601+
if vfr_hud.climb > 0:
1602+
# climbing
1603+
return
1604+
1605+
1606+
self.landing_heuristics["armed"] = False
1607+
self.retract()
1608+
15581609
def show_horizon_lines(self):
15591610
'''show horizon lines'''
15601611
if self.rgb_view is None or self.rgb_view.im is None:

0 commit comments

Comments
 (0)