@@ -296,6 +296,9 @@ def __init__(self, mpstate):
296
296
MPSetting ('thresh_volt_dis' , int , 40 , range = (20 ,80 )),
297
297
MPSetting ('thresh_ang_dis' , int , 40 , range = (30 ,4000 )),
298
298
('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
299
302
])
300
303
self .add_completion_function ('(SIYISETTING)' ,
301
304
self .siyi_settings .completion )
@@ -373,6 +376,13 @@ def __init__(self, mpstate):
373
376
self .extended_sys_state_warn_time = 0 # last time we warned about not being able to auto-stow
374
377
self .last_landed_state = None
375
378
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
+
376
386
if mp_util .has_wxpython :
377
387
menu = MPMenuSubMenu ('SIYI' ,
378
388
items = [
@@ -1555,6 +1565,47 @@ def idle_task(self):
1555
1565
self .extended_sys_state_warn_time = now
1556
1566
print ("SIYI: no EXTENDED_SYS_STATE, can't auto-stow" )
1557
1567
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
+
1558
1609
def show_horizon_lines (self ):
1559
1610
'''show horizon lines'''
1560
1611
if self .rgb_view is None or self .rgb_view .im is None :
0 commit comments