AH
| Documentation/HOWTO | /AH |
How to set up the Altitude Hold Controller
As there are a few different possibilities on how to set up a PID controller you will find here two of them to set up the altitude hold controller.
Attention::
- Make sure to follow the instructions rested and concentrated to avoid accidents and injuries!
The amir-ng controller is the only one which supports the below described AH functionality.*
Chapter 1 - General setup
First of course we need a well tested and performing uavp-ng. The altitude hold (AH) controller uses and combines accelerometer and barometer measures supported by kalman filtering.
It is absolutely essential to dampen the barometric values against wind influence. Therefore we use a small 3mm plastic tube stowed with cotton for fc 0.22mini (see picture). From fc 0.24mini on we use a different barometric probe, which should be protected with some kind of foam material.
Chapter 2 - AH parameter
For AH we have a set of parameters influencing the behaviour of the controller:
| parameter | value | description |
| P.z | 70 | Height proportional factor |
| D.z | 125 | Height differential factor |
| I.z | 30 | Height integral factor |
| P.z.upfact | 100 | Upwards height correction (%) |
| P.z.limit | 15 | Height correction P limiter (<0 will beep) |
| I.z.limit | 15 | Height correction I limiter (<0 will beep) |
| CTRL.z.throttle | 0 | Control throttle while height-hold (value is offset) |
| HEIGHT.Kalman.Q | 0.05000000 | Height Kalman process var (Acc for Baro) |
| HEIGHT.Kalman.R.pos | 0.00800000 | Height Kalman position system var (Baro) |
| HEIGHT.Kalman.R.vel | 0.10000000 | Height Kalman velocity system var (Baro) |
| HEIGHT.PT1.comp.k1 | 800 | Height feedback PT1 compensation K1 (Baro) |
| HEIGHT.PT1.comp.t1 | 170 | Height feedback PT1 compensation T1 (Baro) |
Based on the above default setting for fc 0.22mini most of the copters ( tested weight 900-1250gr) should be able to keep the altitude fairly good.
Concerning CTRL.z.throttle it is important to know, that with a value of 0 we have full throttle control. Values > 0 and AH activated means throttle control is disabled and AH uses the actual throttle value plus CTRL.z.throttle as base.
The Kalman parameters are quite well optimized and hopefully don’t need to be modified.
Chapter 3 - Setting up the PID
As mentioned before a ‘standart’ UAVP-NG should work with the default setting. Depending on construction and all the other nasty details it may be necessary to set up the AH PID.
Note:: *For the following two options it is very important to realize, that during test phase you need enough height (at least 10 to 15m) to have time to act, because with small P.z values and AH switched on, the copter will immediately fall down fast and with higher values he starts to oszillate!
In case of trouble switch off AH very fast to have full throttle control in every case!*
Option 1: manual tuning method
It is performed by setting the I.z and D.z gains to zero. The P.z gain is then increased (starting from small amout, e.g. 30 in steps of 10 and fine tuning 5) until it reaches the state, at which the copter moves up and down (oscillates) with a constant amplitude.
At that point we leave P.z as it is and start to increase D.z stepwise (e.g. steps of 10, fine tuning with 5) until the copter stops to oszillate and stabilizes.
Then we have to add some I.z to allow the controller to stabilize always at the same height (Also interesting to have some weight compensation). Increasing I.z means also to reduce P.z in small amounts.
Option 2: Ziegler–Nichols tuning method
This is a heuristic method devided into two possibilities of tuning a PID controller developed by Ziegler and Nichols in 1940 (we will use the first one: setting on stability limit).
It is performed by setting the I.z and D.z gains to zero. The P.z gain is then increased (from small amout, e.g. 30) until it reaches the ultimate gain Kp,,krit,,, at which the copter moves up and down (oscillates) with a constant amplitude.
Now we have K,,pkrit,, and need to stop the time for a full up and down move (the oscillation period) T,,krit,, which are used to calculate and then set P.z, I.z, and D.z gains.
. Kp,,krit,,: gain for oszillation on constant amplitude . T,,krit,,: oszillation period in seconds . . Ki = Kp / Tn . Kd = Kp * Tv .
| controller | Kp | Tn | Tv |
| PID | 0.6 * Kpkrit | 0.5 * Tkrit | 0.12 * Tkrit |
. . . Example: . Kp,,krit,,: 120 . T,,krit,,: 7 .
| controller | Kp (P.z) | Tn | Tv | Ki (I.z) | Kd (D.Z) |
| PID | 72 | 3.5 | 0.84 | 21 | 60 |
For those who are familiar with PID controllers it may be interesting to investigate some additional time to optimize the AH performance manually.
