Where would I start from programming my own quadcopter firmware

Hi there,
So I've flown a lot of Quadcopters recently and I love robotics. So I came up with the idea developing my own quadcopter from scratch. Coding the whole firmware on my own.

Later on I want to use the drone with Sensors to avoid collision and use Computer Vision on it, and maybe a Flow Sensor.
The thing is the Drone will be 130mm in diameter.

The board I picked for the Project is the ESP32 from Espressif.

I found a lot of materials about that topic but none of the one I've found covered the topic how to actually program a drone. The IMU programming the PID tuning and all the other stuff.
Most of the suggestions were just to use existing code and apply it to my project. But thats not the thing I want to do.

What would be good resources to learn quadcopter Programming and how the IMU of a quadcopter works and stuff?
Which books or courses would be useful?


Have you programmed a controller?

Can you tell us your electronics, programming, arduino, hardware experience?

Thanks.. Tom.. :slight_smile:

Study other people's code in order to understand what they did and why. For any given topic, like PID control and IMU orientation calculations, there are on line tutorials.

Once you do understand the groundwork and implementations, you will be in a great position to write your own. Plan on months (full time) to years (part time) of effort.

Maybe start by defining the problem? What exactly is the desired behavior of your firmware? What sort of input will it take?

One of the simplest would be to take target pitch/yaw/roll rates and total combined propeller speed (throttle). That translates fairly directly into speed commands for the four propellers.

Slightly more complicated would be to specify a target pitch and roll angle, yaw rate, and total combined propeller speed. Then you PID the pitch and roll rates using the target angles and IMU data.

Slightly more complicated than that would be to specify target acceleration in each direction and use a bit of trigonometry to figure out the necessary pitch/roll angles and throttle. You'll need to decide whether the target accelerations are relative to the current heading (forward/back/left/right) or north/south/east/west.

A level up from that would be a system where the AI tries to maintain a fixed position in 3D space until commands are given, and the commands would be something like target forward/back speed, left/right speed, up/down speed, and either yaw rate or compass heading or automatically point in the direction it's moving. This gets tricky because the IMU can only sense acceleration, not speed. GPS would be one way to measure horizontal speed, and altimeter for vertical. For this you need to PID the target acceleration in each direction to maintain the target speed. But I don't think GPS or altimeter will be all that precise, so it may take more than simple PID tuning to get good behavior out of it.

A level up from that would be to specify a target position in 3D space (and maybe time of arrival) and have it figure out how to get there on its own.

You could potentially build the system up in layers so each mode gives commands to the next lower level mode. But it might be easier to just choose one and send speed commands to the ESC's directly from there.