Fuzzy tuning of PID gains

This forum is dedicated to software development related to MultiWii.
It is not the right place to submit a setup problem.
Software download
Post Reply
ned
Posts: 9
Joined: Tue Mar 04, 2014 9:12 am

Fuzzy tuning of PID gains

Post by ned »

Hi,
May i ask how do we manually change the pid gains without using the GUI and potentiometer. Can we assign a value to the pid gains in the multiwii codes?If its possible,where can i assign the values.
Apart from that, i want to use fuzzy logic to self tune the pid gains constantly according to the errorangle.Can anyone help me with that?
Welcome any value feedbacks.Thanks.

timecop
Posts: 1880
Joined: Fri Sep 02, 2011 4:48 pm

Re: Fuzzy tuning of PID gains

Post by timecop »

What was wrong with keeping this discussion in the previous thread you made for this?

e_lm_70
Posts: 297
Joined: Fri Aug 09, 2013 8:35 pm

Re: Fuzzy tuning of PID gains

Post by e_lm_70 »

ned wrote:Hi,
May i ask how do we manually change the pid gains without using the GUI and potentiometer. Can we assign a value to the pid gains in the multiwii codes?If its possible,where can i assign the values.
Apart from that, i want to use fuzzy logic to self tune the pid gains constantly according to the errorangle.Can anyone help me with that?
Welcome any value feedbacks.Thanks.


Hi Ned

After have spend 1h on tuning my multiwii micro quad with ropes (stick the copter between two chairs, with only 1 free rotation axis left) ... I may realize how untrivial is make a PID tuning.

On ropes, it is simple, but time consuming .. without this, it is hard and a big waste of time ... many people may gave up without finding quickly the ideal PID.

Anyhow, sorry for long introduction.

I think PID autotuning is quote simple and it could be done on top of current multiwii.

The assumption here is that the copter can at least in autolevel mode, but fine tuning is rewuired for reduce vibrations/oscillations

My approach would be:
Define a initial step, like +/- 30%.
Define the order of tuning .. I would say, P, then I and then D
Auto tune only one axis at time, roll, then pitch then yaw

Auto tune should be done as following per single axi per single PID component:
Hover in angle mode ... ideally no signal roll/pitch/yaw should be provided, and power should be constant for keep as steady in altitude as possible

Run a cycle with current PID, and calculate the average square error

Run with the +30% in the single factor of PID, same cycle same average to be defined
Run with -30%, and make same cycle

At the end of 3 cycle, there are 3 error result.
If the lowesr error is the original position, it means the ideal PID is between +30% and -30%, if lower PID was having better error then higer bid, then next step is to check at -15% the error, if the higer PID was the better one, then next cyle should be to check at +15%

If the lowest error was at -30%, then next cycle should be at -30%*-30% (that is around -50%)
If the lowesr error was at +30%, then next cycle should be at +30% * +30%

So .. this sound for me a way to automaticall scan for the best PID

What do you think ?

o_lampe
Posts: 117
Joined: Sat Nov 02, 2013 5:09 pm

Re: Fuzzy tuning of PID gains

Post by o_lampe »

How about a more detailed description of the copter in config.h? ( more than just quadX, xyz-GPS, abc-flightcontroller )
Add variables for size, weight, motorpower, desired flight-characteristic ( acro or FPV ) a.s.o.
That way the PID-start values could be calculated closer to the Optimum. ( a good PID-database could be gathered here in the forum )

e_lm_70
Posts: 297
Joined: Fri Aug 09, 2013 8:35 pm

Re: Fuzzy tuning of PID gains

Post by e_lm_70 »

o_lampe wrote:How about a more detailed description of the copter in config.h? ( more than just quadX, xyz-GPS, abc-flightcontroller )
Add variables for size, weight, motorpower, desired flight-characteristic ( acro or FPV ) a.s.o.
That way the PID-start values could be calculated closer to the Optimum. ( a good PID-database could be gathered here in the forum )

There are too many variables ... and the exact model can be missing.
For example, each ESC can have a different response time and difference accuracy on impress the required RPM to the prop.

More then put the copter data and try to extract PID by some heuristic formula, the real approach would be an extensive data logging during the fly ... and then post process data logging for calculate ideal PID

MultiWii does not support data logging, and very few board have this.

At the end this approach should be ideal for the latest NAZE32 ... maybe there is already something done in this area by TimeCop

PeeBee
Posts: 7
Joined: Thu Jun 12, 2014 8:12 pm

Re: Fuzzy tuning of PID gains

Post by PeeBee »

How about doing the auto tuning in the Processing GUI app? No RAM/code size issues...

I am using an XBee 2.4GHz to get in-flight access via the GUI (and others are using bluetooth) so all the interface needs is a button next to each PID set saying 'Auto tune'.
Additional features could be starting low value for P, and a max. And perhaps a 'mode': smooth, middle, and twitchy. An even perhaps a 'Tune all' button.

Z-N could be used by first gradually increasing P until sustained oscillation occurs, and then using the Z-N table to get I and D.

Altitude would need to be a special case due to the non-standard PID usage.

o_lampe
Posts: 117
Joined: Sat Nov 02, 2013 5:09 pm

Re: Fuzzy tuning of PID gains

Post by o_lampe »

Since the mWII-NAV-version appeared, we are forced to use the Mega-boards anyways. With plenty of space for additional code for fuzzy-logic a.s.o.
But I also like the idea of a GUI-routine to preset the PIDs to a desired copter behaviour ( smooth, middle, and twitchy )

PeeBee
Posts: 7
Joined: Thu Jun 12, 2014 8:12 pm

Re: Fuzzy tuning of PID gains

Post by PeeBee »

Auto tune/assist tune from the GUI shouldn't be hard... start at a PID = 0, then increase P in steps, say every 10 seconds. The user can decide when oscillations set in, then fix P, then move onto I, etc. This would work for any board 8 or 32 bit. ANyone think this is worthwhile/useful?

o_lampe
Posts: 117
Joined: Sat Nov 02, 2013 5:09 pm

Re: Fuzzy tuning of PID gains

Post by o_lampe »

Actually the board/IMU itself should be able to recognize oscillations and react accordingly. Autotuning should be a matter of seconds for all PIDs.
The fastest way to get a value tuned, is to start at 50% => Overshoot? Yes: goto 25%/ No: goto 75%...a.s.o
Every Iteration cuts the remaining "value range" by half. ( 50% from the former value )

Post Reply