IPM Motor Simulation and FOC Software

User avatar
Ev8
Posts: 801
Joined: Sat Jan 30, 2021 11:05 am
Has thanked: 41 times
Been thanked: 149 times

Re: IPM Motor Simulation and FOC Software

Post by Ev8 »

Brilliant yes I do suffer from this, can you point me to the bit of code with the idle offset calibration function so I can test a build with it commented out?
User avatar
johu
Site Admin
Posts: 5682
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 153 times
Been thanked: 960 times
Contact:

Re: IPM Motor Simulation and FOC Software

Post by johu »

This line: https://github.com/jsphuebner/stm32-sin ... c.cpp#L112
Delete anything left of "||" i.e. leave just the initwait condition in place. I'll commit new code soon
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: 5682
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 153 times
Been thanked: 960 times
Contact:

Re: IPM Motor Simulation and FOC Software

Post by johu »

Finally, a Touran test run with latest commit. Performance is now also very good with the Leaf motor, allowing idMtpa to be up to 2xiqMtpa in vlim case has cured the torque dropoff.

At the first try I had some unwanted acceleration:
unwanted accel.png
So now I did some coasting tests, first with syncadv=0:
coasting.png
Aha! ud is frequency dependent.

Ok, lets give it syncadv=5
coasting syncadv5.png
Better, but lets go higher, syncadv=10
coasting syncadv10.png
Alright, close enough. Lets hit it again:
good run.png
And again:
good run2.png
Well that's better! Fully controlled at any speed, nice torque at any speed, regen at any speed.

Lets go home. 3rd gear. Bonk! Oh, whats that? Over current shutdown when planting your foot at standstill. I had been driving with curkp=150 as suggested by the simulator. Ok, lets dial that back to 60. Launches ok. Too much oscillation with high curkp and low speed. Now I should do another high speed test run but then the last one with the "accidental" syncadv worked fine with curkp=50. So won't test that today.

Bottom line having syncadv is super important, it alone cured the unwanted acceleration. The coasting graph suggests that 10 is quite ok.

EDIT: flux linkage calculation:
uq=25000, udc=360, fstat=300
uac = uq/37813*udc/sqrt(2)=169V
V/Hz = 169/300=0.56 V/Hz = 90 mWeber
Attachments
stm32_foc.bin
(48.41 KiB) Downloaded 41 times
touran 2022-11-10.json
(1.4 KiB) Downloaded 119 times
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
User avatar
Ev8
Posts: 801
Joined: Sat Jan 30, 2021 11:05 am
Has thanked: 41 times
Been thanked: 149 times

Re: IPM Motor Simulation and FOC Software

Post by Ev8 »

johu wrote: Thu Nov 10, 2022 12:22 pm This line: https://github.com/jsphuebner/stm32-sin ... c.cpp#L112
Delete anything left of "||" i.e. leave just the initwait condition in place. I'll commit new code soon
Thanks, will give that a go,

looks like you’ve had a productive day, I have yet to manage to get a comparable level of performance from the latest code compared to say 5.20 i think this is possibly due to my setup relying more on low end and mid range power something mtpa and no fw provided very well, thanks to a choice of gears and the large amount of torque the rx400h mg2 can create I don’t need more than a maximum of 4 or 5krpm whereas with the Prius transaxle you are more focused on trying to achieve even power over a wider range of motor speeds.
User avatar
johu
Site Admin
Posts: 5682
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 153 times
Been thanked: 960 times
Contact:

Re: IPM Motor Simulation and FOC Software

Post by johu »

The image above has this fixed anyway, won't shut off PWM when detecting Prius Gen2 controller
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
User avatar
Bigpie
Posts: 1585
Joined: Wed Apr 10, 2019 8:11 pm
Location: South Yorkshire, UK
Has thanked: 74 times
Been thanked: 299 times

Re: IPM Motor Simulation and FOC Software

Post by Bigpie »

Are you still building this agains your own fork of stm32-sine or using Johannes now?
VW Beetle 2003
Outlander front generator
Prius Gen 3 inverter (EVBMW logic board)
Outlander charger
3x Golf GTE batteries
Chademo Charging
Outlander water heater
Pete9008
Posts: 1801
Joined: Sun Apr 03, 2022 1:57 pm
Has thanked: 102 times
Been thanked: 347 times

Re: IPM Motor Simulation and FOC Software

Post by Pete9008 »

I'm still using mine but it shouldn't take much to build it with Johannes code (probably just a change to the function call that sets the PI gains). I think he has been using it with his code so should be able to better advise what's needed.

Once Johannes code is stable Ill do a final version that supports both.
User avatar
Ev8
Posts: 801
Joined: Sat Jan 30, 2021 11:05 am
Has thanked: 41 times
Been thanked: 149 times

Re: IPM Motor Simulation and FOC Software

Post by Ev8 »

Bigpie wrote: Thu Nov 10, 2022 5:17 pm Are you still building this agains your own fork of stm32-sine or using Johannes now?
I’ve been having odd issues today with the tool chain erroring out while building things but was using a local clone of johannes, I do have a fork on my GitHub so I will use that if I do any side development,

As I was having the above issues (which a quick uninstall/ reinstall of Ubuntu for wls seems to have fixed) I tested the latest build as posted above by Johannes o the drive home, it’s a massive improvement in drivability for anything with a Prius gen2 inverter and in the first tune I’ve got 90% of the power I had squeezed out of 5.20 no unwanted acceleration and no unwanted regen. No inverter shorting the phases whilst slowly rolling forward and going out of sync when it switches the pwm back on. Motors sound quieter and smoother I’m very impressed
User avatar
Bigpie
Posts: 1585
Joined: Wed Apr 10, 2019 8:11 pm
Location: South Yorkshire, UK
Has thanked: 74 times
Been thanked: 299 times

Re: IPM Motor Simulation and FOC Software

Post by Bigpie »

Done a fresh clone of both IPMMotorSim and stm32-sine both from pete9008 github

Code: Select all

/Users/jamiejones/open-inverter/IPMMotorSim/IPMMotorSim/cpp_teststubs.cpp:172: error: too many arguments to function call, expected 5, have 7
cpp_teststubs.cpp:172:188: error: too many arguments to function call, expected 5, have 7
         PwmGeneration::SetControllerGains(Param::GetInt(Param::curkp), Param::GetInt(Param::curki), Param::GetInt(Param::fwkp), Param::GetInt(Param::fwki), Param::GetInt(Param::vlimkp), Param::GetInt(Param::vlimki), Param::GetInt(Param::fwmargin));
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                                                                                                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stm32-sine/include/pwmgeneration.h:38:19: note: 'SetControllerGains' declared here
      static void SetControllerGains(int kp, int ki, int fwkp, int fwki, int fwmargin);
                  ^
The definition is missing ylimki and ylimkp?

Code: Select all

void PwmGeneration::SetControllerGains(int kp, int ki, int fwkp, int fwki, int fwmargin)
{
   qController.SetGains(kp, ki);
   dController.SetGains(kp, ki);
   fwController.SetGains(fwkp, fwki);
   fwController.SetRef(FOC::GetMaximumModulationIndex() - fwmargin);
}
VW Beetle 2003
Outlander front generator
Prius Gen 3 inverter (EVBMW logic board)
Outlander charger
3x Golf GTE batteries
Chademo Charging
Outlander water heater
Pete9008
Posts: 1801
Joined: Sun Apr 03, 2022 1:57 pm
Has thanked: 102 times
Been thanked: 347 times

Re: IPM Motor Simulation and FOC Software

Post by Pete9008 »

You should just need to remove the two extra arguments in the function call in the test stubs file.

Edit - sorry were they both checked out of my repos or was the simulator out of mine and the firmware from Johannes? If the former it should just work, if the later you probably need to delete the extra arguments in the function call (you may need to tweak the param file too)

@johu, let me know when you consider your code/parameters to be stable and Ill mod the simulator to support it properly.
User avatar
Bigpie
Posts: 1585
Joined: Wed Apr 10, 2019 8:11 pm
Location: South Yorkshire, UK
Has thanked: 74 times
Been thanked: 299 times

Re: IPM Motor Simulation and FOC Software

Post by Bigpie »

Thanks, got it building now. QString sprintf is deprecated and wouldn't build, had to use asprintf instead.

Not to read back and understand the changes and new param icrit, try and understand the graphs output and get something similar to what's going on in the car.
VW Beetle 2003
Outlander front generator
Prius Gen 3 inverter (EVBMW logic board)
Outlander charger
3x Golf GTE batteries
Chademo Charging
Outlander water heater
Pete9008
Posts: 1801
Joined: Sun Apr 03, 2022 1:57 pm
Has thanked: 102 times
Been thanked: 347 times

Re: IPM Motor Simulation and FOC Software

Post by Pete9008 »

Just checked, the simulator only works out the box with the experimental firmware branch, the main branch is the one you have been using for logging and it will need the extra arguments removing.

Its only the experimental branch that uses icrit, the main is based on the original fw approach.
Pete9008
Posts: 1801
Joined: Sun Apr 03, 2022 1:57 pm
Has thanked: 102 times
Been thanked: 347 times

Re: IPM Motor Simulation and FOC Software

Post by Pete9008 »

Bigpie wrote: Thu Nov 10, 2022 7:24 pm Thanks, got it building now. QString sprintf is deprecated and wouldn't build, had to use asprintf instead
Thanks for letting me know. Ill sort that when doing the other changes. Could you update your fork then I can pull the changes needed from there?
User avatar
johu
Site Admin
Posts: 5682
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 153 times
Been thanked: 960 times
Contact:

Re: IPM Motor Simulation and FOC Software

Post by johu »

I let the compiler point me to the errors. Remember to copy the param_prj.h of the branch you're building into the IPMMotorSim directory. Maybe modify the default values to match what you're testing. Most of all I had to default polepairs and respolepairs to 4.

Then just review parameters that no longer exist in mainwindow.cpp. Either comment out their propagation completely or redirect them. For example I let fwkp from the simulator set vlimflt in the control code.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
User avatar
Ev8
Posts: 801
Joined: Sat Jan 30, 2021 11:05 am
Has thanked: 41 times
Been thanked: 149 times

Re: IPM Motor Simulation and FOC Software

Post by Ev8 »

Ok so now it’s looking like we have a fairly stable build thanks to the huge amount efforts put in here by Johannes and Pete, then pete’s simulator could actually come in useful for simulating changes made to tune parameters for best performance which is exciting.

Is there a simple way to calculate icrit (max fw current) based on measured inductance, and what are the expected results of allowing too much?
RetroZero
Posts: 702
Joined: Tue Oct 29, 2019 2:48 pm
Location: France
Has thanked: 311 times
Been thanked: 38 times
Contact:

Re: IPM Motor Simulation and FOC Software

Post by RetroZero »

I might just hold off with swapping out my Gen2 transaxle after all this hard work 👍
Pete9008
Posts: 1801
Joined: Sun Apr 03, 2022 1:57 pm
Has thanked: 102 times
Been thanked: 347 times

Re: IPM Motor Simulation and FOC Software

Post by Pete9008 »

Ev8 wrote: Fri Nov 11, 2022 12:38 pm Is there a simple way to calculate icrit (max fw current) based on measured inductance, and what are the expected results of allowing too much?
Icrit is flux linkage over Ld. Since you have measured Ld you just need a value for the flux linkage.

If you have a motor on the bench you can spin it up and measure the voltage generated and calculate it from that. If the motor is in the car you need to measure, or idealy log, ud, uq, id and iq while coasting and it can then be calculated from those (see viewtopic.php?p=47861#p47861)

I've been meaning to do a post explaining field weakening on high inductance motors and the relevance of icrit but not thinking clearly enough to do it at the moment. Essentially for a low L motor icrit is likely to be above the max current allowed, so will never be exceeded and so is not something to worry about. On a high L motor it is possible to exceed icrit so it does need bearing in mind.

Icrit is the -Id current that produces a uq voltage component that perfectly balances the back emf of the motor, i.e. it effectively reduces the back emf at the motor terminals to zero; if you go above this value the back emf will start to increase again. What this means for the amplitude limiter control loop is if it goes above this -Id value then it makes amplitudes bigger not smaller, which makes the controller add more -Id, which makes the amplitudes even bigger which makes the controller try to add more -Id and so on - essentially the controller will lose control, the amplitudes will increase too far, the iq and/or id controllers will then lose control at which point the inverter has lost control of the motor - generally not good. As long as the limiting value is set to something sensible this should not happen.

As far as the simulator goes it's not perfect but does now seem to do a pretty good job of simulating reality. The main omission I'm aware of is that it doesn't simulate driveline play/shunt and adding this would probably help it to model trips off the line (the play allows the motor to accelerate very rapidly for part of a rotation from stationary before it is forced to slow rapidly, and I think this it what can cause the trip). There are comments in the source code suggesting how to add this but it's not been done yet.

Edit - It also doesn't simulate saturation in the motor. Adding this would be a big project in itself and also has the potential to reduce simulation accuracy considerably if done wrong. As long as motor currents are kept to sensible limits and users are aware of the limitation it shouldn't be an issue.

The goals in doing the simulator were to learn more about IPM motors and their control, investigate/fix the poor performance and trips that were being experienced and allow the evaluation of different control approaches. I think it now does all this and so I'm pretty much done with it for the time being. I'll do one more release to better support Johannes code, once it's stable, but I don't expect to add much more in the way of features for the foreseeable future. Hope it proves to be useful!
User avatar
Ev8
Posts: 801
Joined: Sat Jan 30, 2021 11:05 am
Has thanked: 41 times
Been thanked: 149 times

Re: IPM Motor Simulation and FOC Software

Post by Ev8 »

Cool well I have a usb Wi-Fi adapter with a high gain antenna on its way so hopefully I’ll finally manage a stable connection for some logging
User avatar
johu
Site Admin
Posts: 5682
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 153 times
Been thanked: 960 times
Contact:

Re: IPM Motor Simulation and FOC Software

Post by johu »

With the latest knowledge (syncadv=10) I did another test drive in the Audi. I think this is production ready now. I didn't get a single trip for the entire run even though I was pushing it and I do get a very stable 80A (x370V) battery current in the constant power region.

Here is a plot of accelerating from standstill to 120 kph and regenning back down (didn't fit entirely from and to standstill...)
audi good run.png
The d-controller is very close to saturation but is never saturated.
You can even see the DC current limit working as speed decreases iq increases. I have posted the parameters here https://openinverter.org/parameters/view.html?id=29

I will draft a new release of the firmware now. I was going to include the logging code but having some minor trouble with it, so will include it in the next release.

At this point I'd actually consider this topic solved. As you know I have been struggling with this for years and I think it would not have been possible to solve this without Petes input and his simulator. So huge thanks for that :D

EDIT: thanks also to the mystery forum member who brought up the critical current (and deleted his post a day later) and thanks to celeron for analyzing it further.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
User avatar
Ev8
Posts: 801
Joined: Sat Jan 30, 2021 11:05 am
Has thanked: 41 times
Been thanked: 149 times

Re: IPM Motor Simulation and FOC Software

Post by Ev8 »

Just want to again say how happy I am with the latest code, it has transformed my car from feeling like some guy built it in a shed to something that feels much more oem!
RetroZero
Posts: 702
Joined: Tue Oct 29, 2019 2:48 pm
Location: France
Has thanked: 311 times
Been thanked: 38 times
Contact:

Re: IPM Motor Simulation and FOC Software

Post by RetroZero »

That sounds very promising 👍👌😁
User avatar
mjc506
Posts: 343
Joined: Wed Sep 09, 2020 9:36 pm
Location: Wales, United Kingdom
Has thanked: 30 times
Been thanked: 28 times

Re: IPM Motor Simulation and FOC Software

Post by mjc506 »

If there is to be another release, lines 406 and 407 in mainwindow.cpp should set Vb and Vc I think (current sets Va to 0 three times :) )
Pete9008
Posts: 1801
Joined: Sun Apr 03, 2022 1:57 pm
Has thanked: 102 times
Been thanked: 347 times

Re: IPM Motor Simulation and FOC Software

Post by Pete9008 »

Oops! Good catch, yes that needs sorting :oops:
User avatar
Romale
Posts: 441
Joined: Fri May 20, 2022 4:16 pm
Location: Romania
Has thanked: 204 times
Been thanked: 45 times

Re: IPM Motor Simulation and FOC Software

Post by Romale »

johu wrote: Fri Nov 11, 2022 3:34 pm ...
I will draft a new release of the firmware now. I was going to include the logging code but having some minor trouble with it, so will include it in the next releas...
This is amazing news.
Just one request, I think many will support it: Johu, please do not forget to return the free roll on the neutral!

I was also going to test the latest tested firmware version on a green buggy tomorrow. with the fixed neutral version, there are problems with torque from the very beginning (when starting in a steep climb) I'll see how the new firmware version behaves.
evil neodymium :twisted:
User avatar
johu
Site Admin
Posts: 5682
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 153 times
Been thanked: 960 times
Contact:

Re: IPM Motor Simulation and FOC Software

Post by johu »

Yes I've changed the way this is handled, please test
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
Post Reply