Programming a flight controller

Hey I want to make a flight controller for arduino.

For now my plan is a arduino UNO attached with a mpu6050 gyro module and HC-12 wireless communication module and four signal pins of brushless motor connected to it.

So I want the arduino to balance the drone and when it receives signals it should act accordingly.

I couldn't find any examples in the internet which suits my condition.

Please help me with the code.


This is by no means a simple project.
I wrote one with a friend last year, as a university project, and it took us almost two months to get everything right.
The implementation and actually writing the code for the microcontroller are the least of your worries. You first have to come up with a mathematical model of the dynamics of the quadcopter, then write a simulator for that model (we used Dormand-Prince), linearize it, discretize it, design a discrete-time controller and state observer (using LQR+LQE), tune the controller and observer in simulation, then actually try to fly it, find out that the simulation doesn't really match up with reality, do some more tuning, etc.

Of course, there are some papers and other resources that propose controllers and observers, or even provide code, but understanding them takes some time as well. You could of course blindly copy their code and try to tune it without understanding what it's doing under the hood, but you're going to have a hard time doing so if you don't have a clue what each tuning parameter does.

We spent a good amount of time on understanding the underlying mathematics of optimal control theory, and wrapping our head around quaternions.
Steve Brunton's Control Bootcamp was really helpful: Control Bootcamp: Overview - YouTube

You'll also need a good sensor fusion algorithm for your IMU (accelerometer+gyroscope), we used an improved version of Sebastian Madgwick's algorithm. It combines the angular velocity and the acceleration vectors, numerically integrates the angular velocity to get the absolute position, and uses the direction of gravity to eliminate integration drift.

A note on safety as well: Drones kill people. I've heard horror stories of people losing fingers, eyes, and even one guy who was flying alone in a field somewhere: one of the propellers hit his neck, cut open his artery, and he bled to death.
At our university, we had a drone room with a heavy net around the flying zone, and strict rules: never fly alone, always wear safety goggles (propellers can and do shatter), no drones with battery connected and propellers outside of the drone cage.

I think this is a great project to learn about control theory and programming, just be careful, and don't expect to get a perfectly stable drone in a week.


Just some hints: "arducopter", "Multiwii", ...