The problem to be solved is wind-drift, and the solution will require multiple PIDs – somewhere between 2 and 4. The light bulb is the flash of inspiration that I need to get the choice of PIDs right.

Thinking about it too mathematically / logically, I initially thought four PIDs : a desired horizontal speed (to counteract the wind drift), via its PID sets a desired horizontal acceleration which via its PID sets a desired tilt angle causing the horizontal acceleration, which via its PID sets a desired angular speed which via its PID updates the motors speed to tilt Phoebe into the wind, and hold herself steady. What bothers me with this is simply that it’s making minimal used of the whole point of a PID: feedback. Also the accelerometers really aren’t good enough to rely on directly – they are just too noisy, and that will produce noise in the motor power.

The 3 PID solution makes better sense to me – it uses the horizontal speed PID (akin to the the vertical speed PID used for 0 vertical speed for a hover), the angular PID and angular speed (horizontal stability) PID. Selection of a horizontal speed as the target causes the angle PID to tilt the drone to an angle kept stable by the stability PID; the tilted quad accelerates speeding up the horizontal motion; as the horizontal velocity rises towards its target, the output it feeds to the desired angle reduces, ultimately back to 0, where momentum carries the quad along. As drag reduces the momentum speed, the horizontal velocity PID will once more dip the angle PID to get acceleration again.

The 2 PID solution takes out the angle PID, and just uses horizontal speed PID to feed the angular speed PID. Two things put me off here.

- the degree of mathematical separation between these two PIDs – which means too much guesswork in or too sensitive results from PID tuning
- the lack of usage of the absolute angle – internet discussions of quadcopter functions always go on about Kalman or Complimentary filters to maintain angluar accuracy, but this solution doesn’t use them.

But after a good night’s sleep, dreaming of PIDs (sad monkey, I know), 2 is the right answer; put simply, to counteract some backward drift due to wind, the horizontal speed PID “output” is fed directly into the pitch speed PID as its “target”. This tilts Phoebe over be some amount compensating for the wind. As Phoebe’s forward speed matches her rearward wind drift, then the horizontal speed PID “output” (and hence the pitch speed PID “target”) becomes 0, meaning the pitch speed is 0 i.e. the pitch acquired to stall Phoebe’s drift is maintained. Simples!

More on angle accuracy and interpretation in the next chapter.