I'm new to PID-controllers and quadcopters, and I'm trying to write a very simple (but realistic) simulation for a quadcopter. I'm not trying to build an actual quadcopter controller.
I understand roughly how PIDs work, but I don't quite understand how to use them. I know I need at least three PIDs, one for each rotation axis, but I'm not sure if that's enough.
My simulation runs at 60 ticks per second, every tick the PIDs are updated and the drone is simulated.
Case 1)
This case has nothing to do with the drone simulation directly, it's just me trying to understand and get a feeling for PIDs. Let's say the drone is at the world coordinates (0 -60 0) (Y being the up-axis), and I want it to level out at the world origin (0 0 0), so it needs to accelerate upwards. For this case let's ignore the rotors completely, I can just magically apply force directly to the drone. The drone is also upright, and can only move up or down.
To smoothly accelerate towards the origin, I'd assume I need a PID (Let's call it PID0) and calculate it with the setpoint being 0 (y-coordinate of the world origin), and the process variable being the y-coordinate of the drone. However, the output isn't a force. I can apply the output directly as a velocity and that works just fine, but that's not what I want. Do I need an additional PID (PID1) with setpoint being the output of PID0 and process variable being the current drone velocity, to calculate the force?
That would mean I would need 6 PIDs (in addition to the 3 rotational PIDs) for movement on all axes? That doesn't seem right to me.
How do I calculate the force I need to apply from the result of PID0?
Case 2)
For this case let's assume the drone has free movement, and the drone's linear and angular velocities are determined by the rotor lift forces and rotor torques. Let's say the drone has the angles pitch = 20, yaw = 0 and roll = 0 (With positive pitch pointing downwards, meaing the drone is flying forwards), and I want it to level out at pitch = 0, yaw = 0 and roll = 0.
To rotate the drone I would need to increase the RPM on the front rotors (and/or decrease the RPM on the back rotors).
If I calculate the output of the PID for the pitch-axis, with setpoint being 0 and process variable being 20, I get another angle as result. How do I use that to change the power on the rotors?
I don't need tangible solutions for any of these questions, I just need some hints / a nudge in the right direction.