Skip to content

Commit fcb954d

Browse files
committed
mavproxy_SIYI: add option to stow the camera when vehicle starts to land
1 parent d8a2ab5 commit fcb954d

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

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

+40
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ def __init__(self, mpstate):
295295
MPSetting('thresh_climit_dis', int, 20, range=(10,50)),
296296
MPSetting('thresh_volt_dis', int, 40, range=(20,80)),
297297
MPSetting('thresh_ang_dis', int, 40, range=(30,4000)),
298+
('stow_on_landing', bool, True),
298299
])
299300
self.add_completion_function('(SIYISETTING)',
300301
self.siyi_settings.completion)
@@ -366,6 +367,12 @@ def __init__(self, mpstate):
366367
self.last_getconfig = time.time()
367368
self.click_mode = "Flag"
368369

370+
# support for stowing the camera when we start to land:
371+
self.extended_sys_state_received_time = 0
372+
self.extended_sys_state_request_time = 0
373+
self.extended_sys_state_warn_time = 0 # last time we warned about not being able to auto-stow
374+
self.last_landed_state = None
375+
369376
if mp_util.has_wxpython:
370377
menu = MPMenuSubMenu('SIYI',
371378
items=[
@@ -1470,6 +1477,14 @@ def mavlink_packet(self, m):
14701477
self.show_fov()
14711478
except Exception as ex:
14721479
print(traceback.format_exc())
1480+
elif mtype == 'EXTENDED_SYS_STATE':
1481+
if self.settings.stow_on_landing:
1482+
self.extended_sys_state_received_time = time.time()
1483+
if (m.landed_state == mavutil.mavlink.MAV_LANDED_STATE_LANDING and
1484+
self.last_landed_state != mavutil.mavlink.MAV_LANDED_STATE_LANDING):
1485+
# we've just transition into landing
1486+
self.cmd_angle([0, 0])
1487+
self.last_landed_state = m.landed_state
14731488

14741489
def receive_thread(self):
14751490
'''thread for receiving UDP packets from SIYI'''
@@ -1510,6 +1525,31 @@ def idle_task(self):
15101525
self.check_thermal_events()
15111526
self.therm_capture()
15121527

1528+
# we need EXTENDED_SYS_STATE to work out if we're landing:
1529+
if self.settings.stow_on_landing:
1530+
now = time.time()
1531+
delta_t = now - self.extended_sys_state_received_time
1532+
delta_sent_t = now = self.extended_sys_state_request_time
1533+
if delta_t > 5 and delta_sent_t > 5:
1534+
self.extended_sys_state_request_time = now
1535+
self.master.mav.command_long_send(
1536+
1, # FIXME, target_system
1537+
1, # FIXME, target_component
1538+
mavutil.mavlink.MAV_CMD_SET_MESSAGE_INTERVAL,
1539+
0, # confirmation
1540+
mavutil.mavlink.MAVLINK_MSG_ID_EXTENDED_SYS_STATE, # p1
1541+
1e6, #p2 interval (microseconds)
1542+
0, #p3 instance
1543+
0,
1544+
0,
1545+
0,
1546+
0
1547+
)
1548+
delta_warn_t = now - self.extended_sys_state_warn_time
1549+
if delta_warn_t > 60:
1550+
self.extended_sys_state_warn_time = now
1551+
print("SIYI: no EXTENDED_SYS_STATE, can't auto-stow")
1552+
15131553
def show_horizon_lines(self):
15141554
'''show horizon lines'''
15151555
if self.rgb_view is None or self.rgb_view.im is None:

0 commit comments

Comments
 (0)