I am building a quadcopter drone, with Arduino Nano, which has the sole purpose of flying vertically, without remote control, but will have the MPU6050 which will have to autocalibrate, that is, always keep it horizontally.
I tried to make a sketch of the program, putting too much “if”, which is totally unacceptable, but I don’t know what kind of algorithm there may be behind the autocalibration of the drone, in the sense:
If the drone is skewed on the X axis by 40 degrees, how long should I turn on the right 2 motors and also at what speed?
The same thing for the Y axis and also with degrees less than 0
And I leave you below the components and the code that I am using for the drone.
If anyone has some kind of algorithm or code that they have already been able to try I would be really grateful if you could help me with this problem I am having.
Thanks for the attention
Programma_Drone.ino (12 KB)