Hi there. I am trying to change my planes altitude while flying in auto via a lua script. I’d like similar functionality to the “change altitude” button in the actions tab in mission planner. I’m sure this is really simple - but I just can’t figure this out. @Yuri_Rage I’ve watched a bunch of your videos - any chance you can help out a total lua newbie please?
You’re struggling because (as far as I can tell), there is no direct Lua binding/access to DO_CHANGE_ALTITUDE. So you’d need to pass a MavLink command via gcs:run_command_int(). See this wrapper module for some examples.
@Yuri_Rage appreciate it. And I just found that. So I’m looking at that link you sent, and also this: ardupilot/libraries/AP_Scripting/examples/land_hagl.lua at master · ArduPilot/ardupilot · GitHub
So I define my mavlink message:
local MAV_CMD_NAV_CONTINUE_AND_CHANGE_ALT = 30 MAVLINK Common Message Set (common.xml) | MAVLink Guide which i got from here
Then I have:
gcs:run_command_int(MAV_CMD_NAV_CONTINUE_AND_CHANGE_ALT, {p7=ALT_TGT}) where I previously defined ALT_TGT = 10. But the aircraft isn’t reacting. Does that wrapper module need to have the MAV_CMD in there to be able to use it? Am I missing something else?
No, use DO_CHANGE_ALTITUDE (186), like I linked before.
You rock. It’s changing the altitude now. Thanks a lot!
I sent this: gcs:run_command_int(MAV_CMD_DO_CHANGE_ALTITUDE, {p1=ALT_TGT, p2=3})