Skip to content

Commit ea52169

Browse files
committed
mavproxy_misc: add support for MAV_CMD_DO_CHANGE_ALTITUDE
falls back to the mission item way if we get UNSUPPORTED
1 parent acac2f8 commit ea52169

1 file changed

Lines changed: 43 additions & 1 deletion

File tree

MAVProxy/modules/mavproxy_misc.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ def __init__(self, mpstate):
121121

122122
self.repeats = []
123123

124+
# support for changing altitude via command rather than mission item:
125+
self.accepts_DO_CMD_CHANGE_ALTITUDE = {} # keyed by (sysid, compid)
126+
124127
def altitude_difference(self, pressure1, pressure2, ground_temp):
125128
'''calculate barometric altitude'''
126129
scaling = pressure2 / pressure1
@@ -300,14 +303,37 @@ def cmd_time(self, args):
300303
print("%s (%s)\n" % (time.ctime(tusec * 1.0e-6), time.ctime()))
301304

302305
def _cmd_changealt(self, alt, frame):
306+
'''send commands. May send both if we don't know which is the
307+
right one to set'''
308+
key = (self.target_system, self.target_component)
309+
supports = self.accepts_DO_CMD_CHANGE_ALTITUDE.get(key, None)
310+
if supports or supports is None:
311+
self.master.mav.command_long_send(
312+
self.settings.target_system,
313+
self.settings.target_component,
314+
mavutil.mavlink.MAV_CMD_DO_CHANGE_ALTITUDE,
315+
0, # confirmation
316+
alt, # p1
317+
frame, # p2
318+
0,
319+
0,
320+
0,
321+
0,
322+
0
323+
)
324+
print(f"Sent change altitude command for {alt:.2f} meters")
325+
326+
if supports is True:
327+
return
328+
303329
self.master.mav.mission_item_send(self.settings.target_system,
304330
self.settings.target_component,
305331
0,
306332
frame,
307333
mavutil.mavlink.MAV_CMD_NAV_WAYPOINT,
308334
3, 1, 0, 0, 0, 0,
309335
0, 0, alt)
310-
print("Sent change altitude command for %.1f meters" % alt)
336+
print("Sent change altitude mission item command for %.1f meters" % alt)
311337

312338
def cmd_changealt(self, args):
313339
'''change target altitude'''
@@ -661,6 +687,22 @@ def cmd_landing_gear(self, args):
661687
0, 0, 0, 0, 0, 0
662688
)
663689

690+
def mavlink_packet(self, m):
691+
'''handle an incoming mavlink packet'''
692+
mtype = m.get_type()
693+
694+
if mtype == "COMMAND_ACK":
695+
# check to see if the vehicle has bounced our attempts to
696+
# set the current mission item via mavlink command (as
697+
# opposed to the old message):
698+
if m.command == mavutil.mavlink.MAV_CMD_DO_CHANGE_ALTITUDE:
699+
key = (m.get_srcSystem(), m.get_srcComponent())
700+
if m.result == mavutil.mavlink.MAV_RESULT_UNSUPPORTED:
701+
# stop sending the commands:
702+
self.accepts_DO_CMD_CHANGE_ALTITUDE[key] = False
703+
elif m.result in [mavutil.mavlink.MAV_RESULT_ACCEPTED]:
704+
self.accepts_DO_CMD_CHANGE_ALTITUDE[key] = True
705+
664706
def idle_task(self):
665707
'''called on idle'''
666708
for r in self.repeats:

0 commit comments

Comments
 (0)