inav icon indicating copy to clipboard operation
inav copied to clipboard

NAV - Althold problems

Open digitalentity opened this issue 11 years ago • 35 comments

Setup: use_midrc_for_althold=1, throttle input=1500, altitude drifts. Possible cause - insufficent I-term to compensate for thermals, algorithm flaw, barometer problems.

digitalentity avatar Jun 20 '15 10:06 digitalentity

Increasing I term to 0.25 solved the problem for some degree. Need to shield the baro from sunlight and test more. Looks like default PIDs for ALTHOLD (#4) need to be revised.

digitalentity avatar Jun 23 '15 10:06 digitalentity

Shielding baro from sunlight helped. Increasing I-term helps as well. However, I've encountered Engaging ALTHOLD when climbing results in drop in throttle and altitude. Scary. Should record ALTHOLD PID internals to blackbox and investigate.

digitalentity avatar Jun 27 '15 10:06 digitalentity

With default baro_tab_size = 21 and baro_noise_lpf = 0.6 barometric altitude gets delayed too much - we can not trust it for velocity calculations. Data would be reliable only on prolonged (several seconds at least) ascent or descent.

digitalentity avatar Jul 01 '15 09:07 digitalentity

using a kalman filters should probably help instead of using a lpf and we get velocty calculation for free

bk79 avatar Jul 01 '15 10:07 bk79

I am not a math guy, it you can help with kalman - please don't hesitate to do so :+1:

digitalentity avatar Jul 01 '15 10:07 digitalentity

there is already an implentation for GPS on Kalma filter https://github.com/lacker/ikalman that's the starting point since it uses the same variables. I have only one concern do we have enough cpu and ram to run it? Kalman filter is very heavy in terms of calculation even if I can assure you that the result is AMAZING, I used it to perform tracking of a coax during my thesis long ago but it was a a laptop performing the filtering and sending command to the RC copter. Consider that we need to math on matrixes that means lot's of time spent to calculate the status of the system

bk79 avatar Jul 01 '15 10:07 bk79

Thanks for the link, I'll have a look at it. You are probably right, kalman may be too taxing on CPU. However if it will be sufficient to update it with i.e. 1/10 looptime calculations can be split up and executed one-by-one. This needs to be looked into some time. I'll open an issue on this one as well.

digitalentity avatar Jul 01 '15 10:07 digitalentity

mmm...that's not the solution let me explain a little how it works: kalman filter has the status and the inputs of the system, according to the actual status and the actual input it will evaulate next status of the system, and the measure incoming will correct pulling the system to converge to the filtered status: in small terms Kalman evaluate where we are, according to the previous condition of speed and position, and will correct any drift in the calculation when new measure arrives, this means that we're not using anymore the real measure but an estimation coming out from the Status matrix. So evaluation of the status of the system should be done every cycle, and update as much as possible to avoid drifting too much

bk79 avatar Jul 01 '15 10:07 bk79

I understand, but taking a snapshot of sensor readings and doing calculations for several cycles can be a solutions for not having enough CPU power to do filter update every cycle. The only drwaback of this is that filter will be updated as less rate, but that's ok since we are limited to about 40Hz for baro and 5-10Hz for GPS. There is simply no point in updating Kalman filter at 400Hz (at 2500us looptime)

digitalentity avatar Jul 01 '15 10:07 digitalentity

mmm...looking that side then we can think of an update at 40 or also 50 Hz that is the servo signal update not considering oneshot in that case it should not be time critical, what I'm worried about is more about the ram and it comes to my mind the fact that we should focus for now only on one model, bacause a multicopter is not an airplane in terms of variable dependencies (I'm thinking about altitude)

bk79 avatar Jul 01 '15 11:07 bk79

Yep, fixed wing support is another problem. However if we use Kalman only for sensor fusion to get accurate position/altitude/velocity information, we should be fine. Control logic will be different for multirotor and fixed wing, but for both models input data is position+altitude+velocity. If Kalman can provide that information at i.e. 40Hz rate we should be fine. RAM is not a big problem - currently we are using about 13K of available 20K. Kalman will fit in the remaining 7K for sure.

digitalentity avatar Jul 01 '15 11:07 digitalentity

@bk79 What do you think of using Central Limit Theorem for fusing sensor data together (pos/alt/vel) https://en.wikipedia.org/wiki/Sensor_fusion#Example_sensor_fusion_calculations It's fairly simple to calculate even for small cpus and it can fuse together varying number of sensors. The only thing we should know is variances for different sensors, but that's faily easy to figure out. GPS is reporting PDOP values, for sonar, baro and accelerometer integration we'll have to figure that out by experiment.

digitalentity avatar Jul 01 '15 12:07 digitalentity

do you have some logs of the readings of both sensors? if you have them we can calculate the sigmas that would actually mitigate noises quite a lot

bk79 avatar Jul 01 '15 12:07 bk79

Not yet, I've just stumbled upon CLT. Do you think it's worth trying instead of Kalman? It looks fairly easy to implement.

digitalentity avatar Jul 01 '15 12:07 digitalentity

it's not a substitute for kalman but it will work better than an lpf on both, as long as we can calculate the sigma variance (that is actually measurement dependent=sensor dependent). It's nothing else than a normalization of the measure to average values, 90% of the IMU are standard so it could work

bk79 avatar Jul 01 '15 12:07 bk79

I'll get this implemented in a few days. Will try it out once I flight test 542a1bf3261a2f19666dd7e8d5e54d28b85e7c9e and 9cf2826ac88f5e839efd5301ae58e41be7148bb1 and close #14. Don't want to make lots of fixes to code and then struggle to figure out which one is failing :smiley:

digitalentity avatar Jul 01 '15 12:07 digitalentity

if you can implement and log it without using it for flight, we can have a comparison between data

bk79 avatar Jul 01 '15 12:07 bk79

Will look into it tomorrow, thanks for the idea!

digitalentity avatar Jul 01 '15 13:07 digitalentity

if you finish it in time I'll test it as well on my cc3d on the 260 class on the weekend

bk79 avatar Jul 01 '15 13:07 bk79

I still need to figure out variances for accelerometer and baro velocities. Will definitely take some time.

digitalentity avatar Jul 01 '15 13:07 digitalentity