I have got an interesting idea and wanted to get some input from the experts here.
I have a copter which I was not able to tune well after a long saga of tests and trial and errors, mainly due to different behaviour in different flight stages, and to fly safely I had to set the PIDs values in such a way that it would be generating small amplitude oscillations (overtuned what I call it).
The idea is to use LUA script to change PIDs based on the flight stage.
For instance, one problem is when descending vertically, the PIDs necessary to keep my copter stable are generally higher. So:
If I do something like: if Vz is larger than 2 m/s and roll and pitch are less than 5 degrees average for the last 1 second, increase PI by 15 %.
However, if I descend vertically and fly horizontally, the PIDs necessary required are generally lower than the stadanrd ones,SO:
if Vz is larger than 2 m/s and roll or pitch is more than 15 degrees on average for the last 2 or 3 seconds (equivalent to about 15 m/s horizontal speed. 3 seconds minimum wait times are necessary to allow the copter to accelerate to that speed), then decrease PI by about 15 %. I do not want to use GPS speed, because in high wind situations that would result in incorrect evaluation of the air speed.
WEIGHT ADJUSTMENT
The other interesting ideas I can see for instance is to automatically adjust PIDs for weight. I would tune manually the copter for two weights with two sets of PIDs and P Angle, etc. Then, when flying off, the LUA would do something like:
if Vz close to zero and roll and pitch close to zero for 3 seconds during first 30 seconds after take off, do power evaluation, obtain power needed for hover (I x V). Based on power, estimate copter weight, interpolate PIDs obtained manually, and load the interpolated values. If the pilot does not do this short hover, then ignore, and just keep the preset PIDs.
Similar adjustments could be easily made for altitude.
OSCILLATION DETECTOR
Also, I am not sure if it is possible to implement an oscillation detector. A very crude method I found to cut off the oscillations is to set SMAX rates for limiting the PD gain. But it works as ON/OFF method. Oscillations appear, are killed, and then may reappear.
But, one can detect higer frequency oscillations (3…8 Hz) quite easily using LUA:
something like if Roll or Pitch varies from average Roll or Pitch by more than 0.5º and the max variance has a period which is within 20 % of the previous 3 max variance events, then there are oscillations in that axis, then decrease PD for that axis, wait for 2 seconds, then reevaluate. If no oscillations detected, increase PD in steps gradually, like every 1 second. Obviously, this decrease of PD should be limited to no more than a certain amount from the base PD, may be 20 %.
HIGH SPEED DESCENT
Another interesting idea is high speed descent. The idea of my copter is to fly in high mountains where you may have to kill several hundreds or even thousands of meters of altitude at the end of the flight. Using vertical Loiter descent is usually out of question, because you can not have Vz higher than 3 m/s for stbility and it takes ages. The way I do it is in acro mode, but it requires a very precise flying and watching over Vz, speed, power, and inclination.
However, making a LUA script which would do the following could solve the problem:
Put in acro mode, incline gradually to 45 degrees forward, set power equal to 80 % of normal hover power, then keep Vz within 10…14 m/s. if Vz increases above 12 m/s decrease pitch angle gradually and proportionally (but never change thrust power). if Vz decreases below 12 m/s increase pitch angle (up to a certain max angle). When exiting the descent, gradually decrease inclination angle to 0 and revert to the flight mode the copter was in before the descent was activated. One could implement limited pilot input, i.e. forward stick would have a limited influence over the Vz speed, like pushing of the stick forward, would increase target Vz from 12 to 15, and pulling on it would reduce target Vz from 12 to 8 m/s. Yaw and roll inputs should be ignored completely. A good way of exiting the high descent speed mode would be to read the stick, if it is pulled all the way back, that means it is time to stop the descent… Now, if for some reason, the exit from descent mode is not detected… it will be a lot of fun gathering copter pieces after a crash at 150 km/h…
Any input on these ideas?