Now we have access to the input from the RC receiver, and the current orientation from the gyro and accelerometer, the next big hurdle is to actually process these into motor outputs.

Now the algorithm for the job is called a proportional integral derivative controller, or a PID loop. There is plenty of stuff out there on this, but basically it takes the desired value (setpoint), and the actual value (input), calculates the error value and then puts this through 3 different terms to calculate an output.

Here’s a diagram explaining this:

**(continued)**