Hi there,
I`m trying to change the “flight” mode of ardusub via pymavlink. Most of the time there is no problem while changing the flight mode, but some times the mode is not changed. For example, when I boot my robot, I cannot change the mode to stabilize, first I have to change it to Depth Hold mode and then changing to stabilize mode works. And sometimes, this problem happens during the “flight”.
Here is my code while changing the mode:
def set_manual_mode():
MANUAL = 'MANUAL'
while not master.wait_heartbeat().custom_mode == 19:
master.set_mode(MANUAL)
and also the other mods are the same. When sending MANUAL and ALT_HOLD mode commands, the pymavlink print these to the terminal and they both works fine:
Unknown mode ‘MANUAL’
Unknown mode ‘ALT_HOLD’
The STABILIZE mod command does not return anything(do not print anything to terminal) but, it works some time and some time not.
To solve this, I tried to set the flight modes by virtually pushing buttons.
def set_manual_mode_wbutton():
send_button_control(MANUAL_MODE_BUTTON)
def send_button_control(btn):
buttons=1<<btn
print(buttons)
master.mav.manual_control_send(
master.target_system,
0,
0,
500,
0,
buttons)
master.mav.manual_control_send(
master.target_system,
0,
0,
500,
0,
0)
But this time, the qgroundcontrol keeps disarming the vehicle when I change the mode every time. Is there a way to prevent it? Also after this problem, I realized that I cannot disarm or control the vehicle when the qgroundcontrol is closed. Is there any way to let it happen without keeping the qgroundcontrol open?
Thanks very much for your answers in advance.