Testing FOC for synchronous motor
-
- Posts: 260
- Joined: Sat Jan 12, 2019 12:39 am
- Location: UK
Re: Testing FOC for synchronous motor
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 .
Lots of scope for tuning once it's in the car I think .
- johu
- Site Admin
- Posts: 5821
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 162 times
- Been thanked: 1044 times
- Contact:
Re: Testing FOC for synchronous motor
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.
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
- johu
- Site Admin
- Posts: 5821
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 162 times
- Been thanked: 1044 times
- Contact:
Re: Testing FOC for synchronous motor
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.
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
- johu
- Site Admin
- Posts: 5821
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 162 times
- Been thanked: 1044 times
- Contact:
Re: Testing FOC for synchronous motor
So did some testing.
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.
- 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
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.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
- johu
- Site Admin
- Posts: 5821
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 162 times
- Been thanked: 1044 times
- Contact:
Re: Testing FOC for synchronous motor
So tested the combination today:
#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
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.
- Always adding x*frq digits to q-controller output
- Add -x*frq to d-controller output when accelerating, do not add anything on regen. Ramp from one case to another
- A P-controller on iq can override the throttle input to d-current
#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
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
-
- Posts: 99
- Joined: Sat Dec 22, 2018 9:39 pm
- Location: Vancouver, Canada
- Been thanked: 10 times
Re: Testing FOC for synchronous motor
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.
- johu
- Site Admin
- Posts: 5821
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 162 times
- Been thanked: 1044 times
- Contact:
Re: Testing FOC for synchronous motor
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
- johu
- Site Admin
- Posts: 5821
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 162 times
- Been thanked: 1044 times
- Contact:
Re: Testing FOC for synchronous motor
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.
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
- johu
- Site Admin
- Posts: 5821
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 162 times
- Been thanked: 1044 times
- Contact:
Re: Testing FOC for synchronous motor
So I found this in a TI paper (www.ti.com/lit/pdf/spracf3)
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.
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.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
-
- Posts: 260
- Joined: Sat Jan 12, 2019 12:39 am
- Location: UK
-
- Posts: 3266
- 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
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 .
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 .
-
- Posts: 78
- Joined: Wed Apr 10, 2019 2:32 pm
- Location: France
- Been thanked: 1 time
Re: Testing FOC for synchronous motor
Really looking forward to do more testing on my car, i should be able to do it by the begining of november.
- crasbe
- Posts: 244
- Joined: Mon Jul 08, 2019 5:18 pm
- Location: Germany
- Has thanked: 44 times
- Been thanked: 108 times
Re: Testing FOC for synchronous motor
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.
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 98 times
-
- 002-05345_AN205345_Coordinate_Transform_in_Motor_Control.pdf
- (698.48 KiB) Downloaded 98 times
-
- 002-05344_AN205344_PI_Theory_in_Motor_Control.pdf
- (527.18 KiB) Downloaded 92 times
-
- Posts: 78
- Joined: Wed Apr 10, 2019 2:32 pm
- Location: France
- Been thanked: 1 time
Re: Testing FOC for synchronous motor
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.
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.
- johu
- Site Admin
- Posts: 5821
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 162 times
- Been thanked: 1044 times
- Contact:
Re: Testing FOC for synchronous motor
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.
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 87 times
-
- stm32-foc.zip
- (64.73 KiB) Downloaded 72 times
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
-
- Posts: 3266
- 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
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?
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?
-
- Posts: 78
- Joined: Wed Apr 10, 2019 2:32 pm
- Location: France
- Been thanked: 1 time
Re: Testing FOC for synchronous motor
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.
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 75 times
- johu
- Site Admin
- Posts: 5821
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 162 times
- Been thanked: 1044 times
- Contact:
Re: Testing FOC for synchronous motor
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
Yes I deleted some unused parameters.
Try attached version
- Attachments
-
- stm32-foc.zip
- (64.76 KiB) Downloaded 84 times
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
-
- Posts: 78
- Joined: Wed Apr 10, 2019 2:32 pm
- Location: France
- Been thanked: 1 time
-
- Posts: 260
- Joined: Sat Jan 12, 2019 12:39 am
- Location: UK
Re: Testing FOC for synchronous motor
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.
- johu
- Site Admin
- Posts: 5821
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 162 times
- Been thanked: 1044 times
- Contact:
Re: Testing FOC for synchronous motor
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.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?
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
-
- Posts: 3266
- 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
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.
-
- Posts: 78
- Joined: Wed Apr 10, 2019 2:32 pm
- Location: France
- Been thanked: 1 time
Re: Testing FOC for synchronous motor
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)
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)
- johu
- Site Admin
- Posts: 5821
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 162 times
- Been thanked: 1044 times
- Contact:
Re: Testing FOC for synchronous motor
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
-
- Posts: 78
- Joined: Wed Apr 10, 2019 2:32 pm
- Location: France
- Been thanked: 1 time
Re: Testing FOC for synchronous motor
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
attached are the parameters i used
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
attached are the parameters i used
- Attachments
-
- paramsRoadster8_11_19.json
- (1.01 KiB) Downloaded 87 times