Testing FOC for synchronous motor

doobedoobedo
Posts: 260
Joined: Sat Jan 12, 2019 12:39 am
Location: UK

Re: Testing FOC for synchronous motor

Post by doobedoobedo »

OK I've finished playing for now, that worked as described except, don't set throtid to exactly zero (I set 0.05) otherwise the motor doesn't move at all.

Lots of scope for tuning once it's in the car I think :).
User avatar
johu
Site Admin
Posts: 5789
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 157 times
Been thanked: 1023 times
Contact:

Re: Testing FOC for synchronous motor

Post by johu »

Reposting:
I did some more testing. Something still isn't right. It seems the car accelerates less above 4000rpm at full throttle than at, say, half throttle.
Also at high revs the transition to regen can become so brutal that the inverter desats.
I got it a lot tamer by dialing down curki and therefor raising curkd. It never reaches the id set point though, so it lacks the liveliness of that reluctance torque.
So with curkp=96 and curki=64 at least it stops doing "cruise control" at higher rpm and also regen transition is not overshooting so much.
I'm not sure if this is just a matter of tuning the controllers or if something else is wrong also.

I'm playing with the thought of getting rid of fweak and idweak and instead cascade another controller on top of the d-controller that makes sure the q-current doesn't become too large due to lack of field weakening.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
User avatar
johu
Site Admin
Posts: 5789
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 157 times
Been thanked: 1023 times
Contact:

Re: Testing FOC for synchronous motor

Post by johu »

I think I understand the problem now. Basically I'm having a PI controller calculate the voltage needed for a certain current. But that voltage increases with frequency. So while the proportional part might do something at lower frequencies it becomes irrelevant at higher ones. Only the integral part saves the day by integrating quite a lot. Thats why Ki is higher than Kp which is very unusual for PI controllers. The integral part is also very slow, because when the error becomes small or negative and takes a long time to "de-integrate" again. Thus we are seing large gulps of current when going into regen or prolonged periods where the car seems to not react to throttle input at all.

So I found this paper here: http://educypedia.karadimov.info/library/curbldc3.pdf . They suggest to at a voltage proportional to the frequency to the controllers output. So we are sort of back to V/Hz control. So V/Hz controls the voltage coarsely while the PI controllers still do the finer current regulation. Worth a try, will do so today.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
User avatar
johu
Site Admin
Posts: 5789
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 157 times
Been thanked: 1023 times
Contact:

Re: Testing FOC for synchronous motor

Post by johu »

So did some testing.
  • ud is negative when accelerating and sortof linearly increases with frequency
  • ud becomes positive when regenning and seems to not vary much with frequency
  • uq is positive in both regen and acceleration and also linearly increases with frequency
  • both quantities vary a fair bit depending on throttle input, thats the part that the PI controller must handle
I haven't tested reverse direction yet.
So while q-current/voltage is well suited to be supported by a V/Hz profile, d current is a bit more complex. Not sure what the physical connections are.
Red trace: d-voltage as commanded by the PI controller, blue: d-voltage from V/Hz profile
Red trace: d-voltage as commanded by the PI controller, blue: d-voltage from V/Hz profile
Attachments
potnom_vs_ud.png
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
User avatar
johu
Site Admin
Posts: 5789
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 157 times
Been thanked: 1023 times
Contact:

Re: Testing FOC for synchronous motor

Post by johu »

So tested the combination today:
  1. Always adding x*frq digits to q-controller output
  2. Add -x*frq to d-controller output when accelerating, do not add anything on regen. Ramp from one case to another
  3. A P-controller on iq can override the throttle input to d-current
So the 1. and 2. let me drop curkp=64 and curki=32. Thats good as there is not so much integral build up and the controller responds much faster to changes in set point. Also the weird "cruise control" effect is gone.
#3 still needs more thinking, so at high rpm both regen and acceleration were extremely pronounced, so much that pushing the throttle just above 0 would cause full acceleration. hellofatime :D

I'm also still wondering if some phase lag creeps in at higher rpm causing the Park-transformation to be off. It seemed like what is pure d-current at standstill causes acceleration at higher speed.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
kiwifiat
Posts: 99
Joined: Sat Dec 22, 2018 9:39 pm
Location: Vancouver, Canada
Been thanked: 10 times

Re: Testing FOC for synchronous motor

Post by kiwifiat »

johu wrote: Thu Oct 17, 2019 6:22 pm
I'm also still wondering if some phase lag creeps in at higher rpm causing the Park-transformation to be off. It seemed like what is pure d-current at standstill causes acceleration at higher speed.
You are correct, Lq and Ld are a moving target with both phase current magnitude and frequency. Attached snip from the US based Oakridge Labs review of the 2010 Prius describes the phenomena. In another report from Oakridge there is a table showing the changes in Lq and Ld with respect to phase current and frequency for a number of Toyota IPM motors but I can't put my hands on it at the moment.

Does your current control algorithm require stator inductance and resistance to be known for correct operation? If not you could take a look at Paul Holmes implimentation to see how he handles it, his source code is available on github. It is possible to model and calculate it on the fly which is how the lebowski controller operates at maximum torque per amp but sadly it is closed source. Another option maybe to take a look at stm32 motor control workbench available as a free download from ST.COM and see how they handle the issue. I wish I could help you but my coding skills are limited to year one computer science 101 & 102.
IPM_MTPA.PNG
User avatar
johu
Site Admin
Posts: 5789
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 157 times
Been thanked: 1023 times
Contact:

Re: Testing FOC for synchronous motor

Post by johu »

Thanks, that is very interesting. No I do not take any inductance or resistance into account so I will take a look at Pauls code. More of a rabbit hole than I thought.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
User avatar
johu
Site Admin
Posts: 5789
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 157 times
Been thanked: 1023 times
Contact:

Re: Testing FOC for synchronous motor

Post by johu »

Just skimmed over Pauls Code heer: https://github.com/MPaulHolmes/AC-Contr ... ntroller.c
At first I was excited about some rotor time constant array in the beginning but then it turns out they are only used for induction motors. Not much magic going on in case of Leaf motor (starting line 936). It's basically just "get angle", "Clarke/Park", "Clamp", "Park⁻¹" and SVPWM. No rotor time constant is used. The code is a bit convoluted because he had to play a lot of tricks to keep the runtime in check. Thank god we have more horse power on the stm32.

I guess I'll do some more research on MTPA (most torque per amp) to find out how to vary iq/id over the speed range.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
User avatar
johu
Site Admin
Posts: 5789
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 157 times
Been thanked: 1023 times
Contact:

Re: Testing FOC for synchronous motor

Post by johu »

So I found this in a TI paper (www.ti.com/lit/pdf/spracf3)
Bildschirmfoto vom 2019-10-18 19-56-49.png
It does not take speed into account, only the differences in the inductance and the flux linkage. I found another paper that has some actual data on these: https://www.mdpi.com/1996-1073/11/6/1385/pdf

Typical values at medium currents and 90° phase angle are Lq=2.5mH, Ld=1.2mH, Flux linkage=0.09 Wb.

These values plugged into MTPA at 100A total current would result in Id=-57A and Iq=82A. The ratio varies quite a lot with current set points.

So a first approach would be using constant values.

The TI paper also has something on field weakening, just have to find out when to deploy it.
Attachments
MTPA results with varying inductance
MTPA results with varying inductance
MTPA results with varying current
MTPA results with varying current
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
doobedoobedo
Posts: 260
Joined: Sat Jan 12, 2019 12:39 am
Location: UK

Re: Testing FOC for synchronous motor

Post by doobedoobedo »

Looking forward to seeing the results of this :)
arber333
Posts: 3265
Joined: Mon Dec 24, 2018 1:37 pm
Location: Slovenia
Has thanked: 80 times
Been thanked: 234 times
Contact:

Re: Testing FOC for synchronous motor

Post by arber333 »

Johannes and Kiwifiat

I have seen Oakridge report on Prius 2010 motors I remembered it stated best motor drive torque vector offset at 35deg electrical. Then i remembered a study about how IPM motor starts with 0deg for more omph and then offset those degrees for smoother torque under RPM.
I also remembered Paul had a lot to say about Leaf motor saliency. I remember when playing with his code, if i would used correct parameter and start his inverter i could turn Leaf axle by hand even though i didnt apply any throttle-torque.
I think you should consider IPM rotor pushback (cogging) when changing from torque to regen excitation.
Also you could try to program your code that you could rotate your motor by hand easily and see where is the resultant vector is pointing. Consider the precision required to frewheel motor without any regen or torque. And i think that would be good emergency mode to drop out of FW in case of some problems. May save your power stage.
Hm... maybe you could now build the PMSM vs ACIM dyno now :).
PoloLbricolo
Posts: 78
Joined: Wed Apr 10, 2019 2:32 pm
Location: France
Been thanked: 1 time

Re: Testing FOC for synchronous motor

Post by PoloLbricolo »

Really looking forward to do more testing on my car, i should be able to do it by the begining of november.
User avatar
crasbe
Posts: 243
Joined: Mon Jul 08, 2019 5:18 pm
Location: Germany
Has thanked: 44 times
Been thanked: 107 times

Re: Testing FOC for synchronous motor

Post by crasbe »

I found this Application Note AN205344 from Cypress. They describe a motor controller with not one but three PI-Controllers for Speed Control.

The other two probably go along, AN205403 explains how they do the angle and speed estimation. It's interesting to see that they are able to control the motor with so little information.
Attachments
002-05403_AN205403_Inverter_Platform_Rotor_Position_for_PMSM_Motors.pdf
(443.98 KiB) Downloaded 95 times
002-05345_AN205345_Coordinate_Transform_in_Motor_Control.pdf
(698.48 KiB) Downloaded 96 times
002-05344_AN205344_PI_Theory_in_Motor_Control.pdf
(527.18 KiB) Downloaded 91 times
PoloLbricolo
Posts: 78
Joined: Wed Apr 10, 2019 2:32 pm
Location: France
Been thanked: 1 time

Re: Testing FOC for synchronous motor

Post by PoloLbricolo »

Hi,
Is there a build for the improved version you were talking a few weeks ago ?
I'm with the car for the week, if you need testing.
User avatar
johu
Site Admin
Posts: 5789
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 157 times
Been thanked: 1023 times
Contact:

Re: Testing FOC for synchronous motor

Post by johu »

Yes there is!
Much success today. I added the "syncadv" parameter again, that shifts "syncofs" upwards with frequency. I thought it is necessary because FOC works with an increasingly old angle and current as speed increases. So at 8.8kHz the value is about 80µs in the past. So at 4000 [rpm] = 266erpm [Hz] = 96000 °/s = 7.68° / 80µs. So an angular error of about 8° at 4000rpm. That makes quite a difference.

So to make it short I'm now compensating with 12 dig/Hz = 0.065°/Hz which over-compensates above calculation but it makes a hell of a difference. Try yourself.

Moreover I added a field weakening controller that tries to limit BEMF AC voltage to udc/sqrt(3) with a simple P-controller. I set its gain to 100, but tuning is needed.

Only glitch left over is transitioning from acceleration to regen at high rpm. That always ends up with a big lump of regen which then slowly (after about 1s) diminishes to the value you actually want.

Use attached parameter set for testing.
Attachments
Leaf 2019-11-07.json
(1.15 KiB) Downloaded 85 times
stm32-foc.zip
(64.73 KiB) Downloaded 71 times
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
arber333
Posts: 3265
Joined: Mon Dec 24, 2018 1:37 pm
Location: Slovenia
Has thanked: 80 times
Been thanked: 234 times
Contact:

Re: Testing FOC for synchronous motor

Post by arber333 »

Is it possible to make a "frewheel" function in code?
You can use it at least thrice.
1. When at such a low speed regen is not desired you can switch to "freewheel" to stop at trafic light.
2. If you dont desire regen say in winter time you switch on BMS pin and motor frewheels untill you apply brakes.
3. You can cheat the code and command freewheel for 1/10th second everytime throttle would pass 0 position. From there you apply regen torque in %.

Do you think that would cure the spike?
PoloLbricolo
Posts: 78
Joined: Wed Apr 10, 2019 2:32 pm
Location: France
Been thanked: 1 time

Re: Testing FOC for synchronous motor

Post by PoloLbricolo »

So i've tried the latest version (4.63) with most of johannes parameters exept the motors parameters that are for my motor.
Uploading the parameters, the fweak and idweak are now unknown (is that normal ?)
Also, now the car is not moving at all, no errors present, inverter in RUN mode and potnom is moving according to my pedal movement.
The currents don't move at all.
Attached my parameters if that can help.

The car moved quite well with those parameters in version 4.57R-FOC.
Attachments
Roadster4.63.7_11_19.json
(1.03 KiB) Downloaded 73 times
User avatar
johu
Site Admin
Posts: 5789
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 157 times
Been thanked: 1023 times
Contact:

Re: Testing FOC for synchronous motor

Post by johu »

Sorry, did some last minute changes that I didn't test. Silly. Always disabled PWM at 0Hz.

Yes I deleted some unused parameters.

Try attached version
Attachments
stm32-foc.zip
(64.76 KiB) Downloaded 81 times
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
PoloLbricolo
Posts: 78
Joined: Wed Apr 10, 2019 2:32 pm
Location: France
Been thanked: 1 time

Re: Testing FOC for synchronous motor

Post by PoloLbricolo »

Thanks, will try that first thing in the morning :)
doobedoobedo
Posts: 260
Joined: Sat Jan 12, 2019 12:39 am
Location: UK

Re: Testing FOC for synchronous motor

Post by doobedoobedo »

Good to see you're getting the bugs ironed out. Hopefully I'll get a chance to do some testing tomorrow evening. Motor's still on the bench though.
User avatar
johu
Site Admin
Posts: 5789
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 157 times
Been thanked: 1023 times
Contact:

Re: Testing FOC for synchronous motor

Post by johu »

arber333 wrote: Thu Nov 07, 2019 4:56 pm Is it possible to make a "frewheel" function in code?
You can use it at least thrice.
1. When at such a low speed regen is not desired you can switch to "freewheel" to stop at trafic light.
2. If you dont desire regen say in winter time you switch on BMS pin and motor frewheels untill you apply brakes.
3. You can cheat the code and command freewheel for 1/10th second everytime throttle would pass 0 position. From there you apply regen torque in %.

Do you think that would cure the spike?
Yes that could actually work. I'll keep exploring the "mathy" solutions. For example I could try if a PID in place of PI controller cures some problems.
It seems in many papers they throw in PI controllers while hardly ever talking about the drawbacks.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
arber333
Posts: 3265
Joined: Mon Dec 24, 2018 1:37 pm
Location: Slovenia
Has thanked: 80 times
Been thanked: 234 times
Contact:

Re: Testing FOC for synchronous motor

Post by arber333 »

johu wrote: Thu Nov 07, 2019 11:03 pm Yes that could actually work. I'll keep exploring the "mathy" solutions. For example I could try if a PID in place of PI controller cures some problems.
It seems in many papers they throw in PI controllers while hardly ever talking about the drawbacks.
Well i dont think PID will cure the regen surge just by itself. Remember, it is still "proportional" first, If you dampen the initial surge you may have a lame response from regen regulator.
Maybe you could retain PI response but you could just cut or blank out torque of initial regen surge and turn torque back "on" when it is on downslope. This should only effect one time after throttle passes through 0%. For example if i would pump throttle back and forth this would cut in every time throttle goes down.

What happens when throttle is going from 0% to positive? Is there also a positive throttle surge? I can tell you with ACIM there is. I have succesfuly dampened it by streaching FW point further on slip graph. However this turned Mazda into an average car.
PoloLbricolo
Posts: 78
Joined: Wed Apr 10, 2019 2:32 pm
Location: France
Been thanked: 1 time

Re: Testing FOC for synchronous motor

Post by PoloLbricolo »

I did some testing this morning, the car behaves much better !!
I can now achieve 120kph wich is nice ;)

There is still some tuning to do i think, as the "cruise control" effect is still present, but at lower speeds, i think syncadv might need some tuning on my part (i set it to 11 and it seems to be a bit better overall)
I don't relly know what knobs to turn to improve the "cruise control" effect if you can point me ?
Still using the same parameters as yesterday, just incresed the amps ( = more fun)
User avatar
johu
Site Admin
Posts: 5789
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 157 times
Been thanked: 1023 times
Contact:

Re: Testing FOC for synchronous motor

Post by johu »

I think "cruise control" is caused by integrator. I also see you set frqfac=0 which means the PI controller gets no help at all to reach appropriate output at higher frequencies. And that means the integrator has to wind up a lot. I set it to 70 for Leaf+360V battery. 70 means 70 digits/Hz is added to controller output where 37813 digits is full voltage.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
PoloLbricolo
Posts: 78
Joined: Wed Apr 10, 2019 2:32 pm
Location: France
Been thanked: 1 time

Re: Testing FOC for synchronous motor

Post by PoloLbricolo »

It worked great !!!!!!!
The car is very fun to drive now, no more "cruise control" effect with frqfac=50 (i am at arround 250V)
I still have to check top speed, but power is there with arround 66kW at the BMS

I still experience the too much regen when going from acceleration to regen, especialy a higher speeds ( as mentioned in previous posts)

Thanks a lot i'm super happy with the car now :D

attached are the parameters i used
Attachments
paramsRoadster8_11_19.json
(1.01 KiB) Downloaded 85 times
Post Reply