Why did I fail to change flight mode like this?

I’m using Blue Rov2. I wanted the ROV to dive for 3 seconds and then hold the depth, but the ROV came up immediately after diving, why? Thank you for your answer.

Hi @robotmark, welcome to the forum :slight_smile:

Your code seems to disarm the vehicle right after you set depth hold mode, so even if the mode change is successful the thrusters would then turn off immediately when the vehicle is disarmed.

You also seem to try to make the same mavlink connection in multiple files, which may cause issues.

In future, I would recommend you post code in code blocks, so that it’s easier to read and test with. You can learn more about that in the How to Use the Blue Robotics Forums post :slight_smile:

1 Like

Hello, EliotBR. Thank you for your answer. I run my improved code like this, but the computer terminal outputs this and does not terminate the process. I went to the reading I copy down the code from https://www.ardusub.com/developers/pymavlink.html#change-flight-mode, found that function there is a cycle.Am I stuck in a loop? Another question is how do I switch to another flight mode when I’m in depth hold mode? Thank you again for your answer.

Here is the terminal running the application:

Would you be able to try changing that check to see if it fixes the issue?

You can also try checking for both, like in this example.

I’m not sure what you mean by this. Depth hold is a flight mode. If you have a mode change function that allows you to change into it, you should be able to use the same function to change into a different mode :slight_smile:

By the way, you seem to have print(<number>) calls littered throughout your code, including re-using the same numbers in multiple files. I’d recommend instead using the logging module, which comes with Python.

Thanks for your recovery! the problem has been solved with your help. :slightly_smiling_face: