Arduino-FOC icon indicating copy to clipboard operation
Arduino-FOC copied to clipboard

Current PI Autotuning

Open Candas1 opened this issue 1 year ago • 8 comments

Shared by @mcells from his fork https://github.com/mcells/Arduino-FOC/blob/d40c7d7fddff4c3e58b26ebd2e2cc846fddfc09e/src/HFIBLDCMotor.cpp#L71

if phase resistance and phase inductance are known:

Will initialize Kp and Ki for q and d current PI controllers automatically based on phase resistance, phase inductance and current bandwidth (default 300). Needs to be adapted if Ld and Lq are available in the future. ⚠️ What if users have set phase resistance and phase inductance but were using default PI parameters ? Is there an impact ?

if phase resistance and phase inductance are not known:

Same SimpleFOC default values as before are used.

Users that have already tuned their PIs:

They will overwrite Kp and Ki from their code.

Candas1 avatar Jul 21 '24 22:07 Candas1

Great! One thing though, that part of the code is not by me, all credit goes to @Copper280z. I just had my fork on hand quicker when sharing this earlier🙈 Thanks for the mention regardless!

mcells avatar Jul 21 '24 22:07 mcells

To be clear, this method is really more like pole placement, rather than autotuning.

I would recommend also setting the filter cutoff based on the controller bandwidth, otherwise the controller will have a higher bandwidth than the filter likely leading to some integral windup or something else undesirable happening. The default filter for faster chips has a cutoff frequency of ~30hz. Something like 1.5-5x the controller bandwidth (so 450-1500hz) is probably a good place to start. In the hfi fork we've been using a fixed ~2khz lowpass for both controllers.

Copper280z avatar Jul 22 '24 03:07 Copper280z

Oohh, very very very nice! Do you guys have some refereces/papers about this?

askuric avatar Jul 22 '24 05:07 askuric

Some time ago I shared this: https://community.simplefoc.com/t/measuring-the-resistance-of-the-motor/3647/11?u=candas1

The blog and video in the the next post are great.

Candas1 avatar Jul 22 '24 05:07 Candas1

Nice, I'll look into it.

askuric avatar Jul 22 '24 07:07 askuric

Oohh, very very very nice! Do you guys have some refereces/papers about this?

I believe I used a combination of this Ben Katz blog post and Elwin's project when I wrote this. I did some algebra to convert the coefficients to the form used in SFOC. https://build-its-inprogress.blogspot.com/2016/08/desktop-inverted-pendulum-part-2-control.html

Extra fun fact is that this same method applies to tuning the velocity PI controller too! The units just change. I'd need to work it out though as I don't remember off the top of my head.

Copper280z avatar Jul 23 '24 12:07 Copper280z

Is it intended that q and d PI gains are the same, or would it be better to use inductance_q and inductance_d instead of the phase inductance (if you have them...)?

Igitigit2 avatar Mar 23 '25 10:03 Igitigit2

If the inductance for each axis is available then using it would be more accurate, but using the average is ok if that info isn't an option.

Copper280z avatar Mar 26 '25 17:03 Copper280z