I’ve been PID tuning for the past couple of days, and it’s been very tricky (for that read “effing PITA”).
When Phoebe had her centre of gravity dangling between her legs (Gentlemen, behave!), she was virtually self levelling – equal power to all blades and gravity would do the rest.
But with the rebuild, her centre of gravity, though still below the plane of the propellers, isn’t much below. And that does make her very sensitive – a good thing as her reaction to disturbances will be super quick but only once I’ve got the PIDs tuned..
Thankfully, one of the reader’s, David, commented about mathematical tuning called the Ziegler-Nichols method. It’s not perfect as this “we have a chip-on-our-shoulder about Z-N PID tuning and suggest you pay us for our tuner instead” article describes in detail. However, the systems they name which should work match the dynamics of a quadcopter. The Z-N algorithm takes away two thirds of the tuning, and makes very clear and simple what you’re looking for in the remaining “third”. I strongly recommend you read it before carrying on reading here – it’s only a very small Wiki stub article.
The aim is to find the magical Ku, the ultimate gain, and the frequency of stable wobbles @ Ku. From that you can determined Kp, Ki and Kd for whatever kind of behaviour you might be looking for – mellow, jumpy or normal. Sounds too good to be true, doesn’t it!
And indeed it is, but it’s no fault of Ziegler-Nichols that it doesn’t work reliably. As my testing progressed, and the battery voltage reduces as a result, so do the resulting Ku values, and that can only be blamed on the ESC for not increasing the pulse widths of the PWM signal feeding the motors to compensate as it detects the reducing supply voltage of its battery.
The reducing supply voltage does change the speed of rotation since that driven directly by the PWM switching between the 3 phases of the motors coils. But it does affect the power applied to those coils.
The ESC should be able to compensate for the reduced power based upon the fact motors have a manufacturer Kv value relating rpm to voltage supplied linearly. The ESC PWM signal to the motors is effectively dividing the input voltage from the batteries to a lower voltage. So if the ESC tracked the input voltage, it could increase the PWM pulse width to the motors to compensate. But I suspect my ESCs don’t do that leading to the every decreasing Ku values I’m seeing.
Now I’ve never liked the idea of a microcontroller ESC sitting between the Raspberry Pi and the motors – I don’t like the separation of control – it’s like Dalek’s serving tea to Winston Churchill in the second World War – you just can’t trust them. And I think now I understand enough about what’s going on that I could make my own ESCs that are better. Here’s the ingredients list:
- Adafruit i2c 16-channel PWM servo driver which conveniently I have in stock
- A rewrite of the PWM code to drive 3-phase PWM per motor (12 channel for four 3-phase motors)
- 12 MOSFETs to switch the LiPo voltage across the motor phases according to the supplied PWM
- 12 opto-isolators to keep the Raspberry Pi / Adafruit PWM safely isolated from the LiPo battery current across the MOSFETs / motors
- An ADC converter tracking the voltage level of the LiPo where the value is used to increase the PWM pulse width in line with the decreasing voltage of the battery over time – this could also be used for an auto-landing / return home trigger for Phoebe as her batteries start running low.
The one missing piece of the puzzle is the connection between the ESC to motor PWM used to ‘reduce’ the power supplied. But, again, thanks to another comment conversation with David, it should be possible through a combination of audio spectrum analysis to determine rpm, combined with the motor’s Kv to infer the ESC to motor PWM power on / off ratio.
I’m really quite excited about this, thanks David. Having written all this up, I definitely owe you a couple of beers.
Sadly, I do still need to sort out the PID tuning for the tetchy Phoebe, but this was an interesting diversion, and has got me thinking about how to make Phoebe the 100% Raspberry Pi Quadcopter controller I’d always hoped to achieve. And that’s very exciting!
P.S. Just realized that the home grown ESC will need 2 PWM feeds per motors – the first provide the 3 phase output to a given motor at the required rotation speed, and the second uses Kv combined with the rotation speed to ensure the right voltage is supplied to the motors to run at that speed effectively / efficiently.