If I can find room to set up my book scanner, I'll scan some of the more interesting chapters.
IPM Motor Simulation and FOC Software
- SciroccoEV
- Posts: 370
- Joined: Thu Oct 10, 2019 1:50 pm
- Location: Luton UK
- Been thanked: 15 times
Re: IPM Motor Simulation and FOC Software
-
- Posts: 1801
- Joined: Sun Apr 03, 2022 1:57 pm
- Has thanked: 102 times
- Been thanked: 349 times
Re: IPM Motor Simulation and FOC Software
Thank you for the offer! The main thing that I'm interested in is the derivation of the IPM motor equations, in particular where the wLdId and wLqIq terms come from. If it has anything related to those then I would be very interested in seeing just those bits?SciroccoEV wrote: ↑Wed Nov 16, 2022 8:14 pm If I can find room to set up my book scanner, I'll scan some of the more interesting chapters.
I think I know where they come from. We treat Ld and Lq as if they are separate, and they are for a stationary motor. The trouble is some of the flux that contributes to them is in the rotor and some in the stator. The bits in the rotor move with it so effectively stay with Ld or Lq as it rotates. The bits that are in the stator (the majority) don't move though so as the motor rotates the bits that were associated with Lq become part of Ld and vice versa. I think this is where those terms come from. What surprises me is that they are that simple, I would have expected something much more complicated, and so I'm keen to know whether the equations we are using are approximations of whether the maths really does does all cancel down to something that elegant?
-
- Posts: 1801
- Joined: Sun Apr 03, 2022 1:57 pm
- Has thanked: 102 times
- Been thanked: 349 times
Re: IPM Motor Simulation and FOC Software
Thought it would be usefull to capture my thoughts on future enhancements for the simulator while it's fresh in my mind. I'm unlikely to get to any of these for a little while but at least if they are posted here I'm less likely to forget about them.
In a vague order of implementation:
2. 3. 4. and 5. are more to improve the realism of the simulation but also to allow the effect of different mtpa/mtpv schemes, particularly on efficiency, to be evaluated.
Really should also add some sanity checks on data entry fields and possibly allow changes to inverter parameters to be persisted across program restarts (rather than just reinitialising from the param_prj.h file each time - a button would also be needed to allow a manual refresh from the file though.
Any other ideas, or differing views on priorities, please let me know.
In a vague order of implementation:
- Logged data import and comparison - essentially allow the import of logged inverter data (ESP32 high speed log only). This would pop up another window which would allow a file to be selected, it would then run the logged motor voltage data through the motor model and correlate the results against the logged current data. Optionally it would allow a monte carlo style multiple run analysis to search for better matching motor parameters.
Edit Feb23 - Done see viewtopic.php?t=3047 - Motor Loss Modelling - At the moment the simulator reports motor shaft power. By also calculating electrical power going into the motor it would be possible to calculate and plot motor efficiency.
Edit Feb23 - Done, included in latest github repo - Inverter Modelling - Desat - At the moment there is no current limiting in the model, infinite currents are allowed! It would be better to have a configurable threshold at which point a likely desat event is flagged and the simulation paused.
- Inverter Modelling - Losses - At the moment the inverter is considered lossless. It would be possible to calculate the IGBT/diode voltage drops and IGBT switching losses and use these to reduce the DC bus voltage that is available to the motor. There is an accurate way and a simple way to do this. The accurate way is to break each control loop period down into the individual phase switching events and then run the motor model for each of these states. The simple way is to pro-rata the IGBT/diode voltage drops based on PWM value. The accurate way will give very good results but slow down the simulation. The simple way is likely to be 80-90% accurate and have no real impact on simulation speed. Not sure which way to go but probably the simple one. Either way switching losses would just be based on PWM frequency, configurable IGBT turn on/off times and estimates of average current decay profiles.
- Battery Loss Modelling - Very simple approach, just allow the battery internal impedance to be entered and use this to calculate a voltage drop and power loss.
2. 3. 4. and 5. are more to improve the realism of the simulation but also to allow the effect of different mtpa/mtpv schemes, particularly on efficiency, to be evaluated.
Really should also add some sanity checks on data entry fields and possibly allow changes to inverter parameters to be persisted across program restarts (rather than just reinitialising from the param_prj.h file each time - a button would also be needed to allow a manual refresh from the file though.
Any other ideas, or differing views on priorities, please let me know.
- johu
- Site Admin
- Posts: 6259
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 236 times
- Been thanked: 1286 times
- Contact:
Re: IPM Motor Simulation and FOC Software
Thumbs up on the above.
Got an early forum release for you
Got an early forum release for you
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
- johu
- Site Admin
- Posts: 6259
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 236 times
- Been thanked: 1286 times
- Contact:
Re: IPM Motor Simulation and FOC Software
Prius likes over modulation very much! Cranked up modmax to 44000 and went for a drive
I think on the next release I will made modmax a parameter that defaults to 2/sqrt(3)*32768 and can be increased up to... 45000 or so. Then by default over modulation is off and maybe brought in
So when we do (iq * uq + id * ud) / FOC::GetMaximumModulationIndex() we arrive at 43000*90/44000=88A DC (because uq=0) and that is pretty much what I saw on my power meter. So now I can maintain 30 kW across the constant power region.I think on the next release I will made modmax a parameter that defaults to 2/sqrt(3)*32768 and can be increased up to... 45000 or so. Then by default over modulation is off and maybe brought in
- Attachments
-
- stm32_foc.bin
- (47.81 KiB) Downloaded 111 times
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
- SciroccoEV
- Posts: 370
- Joined: Thu Oct 10, 2019 1:50 pm
- Location: Luton UK
- Been thanked: 15 times
- johu
- Site Admin
- Posts: 6259
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 236 times
- Been thanked: 1286 times
- Contact:
Re: IPM Motor Simulation and FOC Software
That's pretty much what it is. I reckon crank the amplitude up even higher, that's where you'd arrive. Don't know by how much though
EDIT: see waveform here https://openinverter.org/forum/viewtopi ... 638#p48638
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
Re: IPM Motor Simulation and FOC Software
Hmm gen2 inverter likes over modulation, makes you wonder if thats the intelligent gate drives doing something interesting, it would be interesting to go full square wave on the inverter input and scope the output
- Bigpie
- Posts: 1711
- Joined: Wed Apr 10, 2019 8:11 pm
- Location: South Yorkshire, UK
- Has thanked: 77 times
- Been thanked: 372 times
Re: IPM Motor Simulation and FOC Software
Some way of simulating a syncoffs error would be nice to have, both for simulating the affect and potential for developing code to auto tune.
Edit, just noticed it's already a parameter
Edit, just noticed it's already a parameter
BMW E91 2006
ZombieVerter
GS450h
Outlander Charger DC/DC
Renault Kangoo 36kWh battery
ZombieVerter
GS450h
Outlander Charger DC/DC
Renault Kangoo 36kWh battery
Re: IPM Motor Simulation and FOC Software
I can confirm that the Prius gen2 inverter does indeed love a bit of over modulation… I’ve now seen for the first time over 300amps on the dc bus, (twin motors remember) however I did once trip mg1 inverter and instead of it restarting and resuming as normal when lifting off the pedal it restarted with the motor chattering which persisted even when stationary…this stoped after a proper key off restart
- Romale
- Posts: 488
- Joined: Fri May 20, 2022 4:16 pm
- Location: Romania
- Has thanked: 273 times
- Been thanked: 62 times
Re: IPM Motor Simulation and FOC Software
is this release useful only for Toyota motors with high inductance, or will the latest official firmware be better for Nissan too?
evil neodymium
- johu
- Site Admin
- Posts: 6259
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 236 times
- Been thanked: 1286 times
- Contact:
Re: IPM Motor Simulation and FOC Software
It should squeeze more power from the Nissan also, but I haven't tested. For me Nissan is already powerful enough without it, I even don't max out the inverter (throtcur could be 6.5 but I set it to 5.5)
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
- Bigpie
- Posts: 1711
- Joined: Wed Apr 10, 2019 8:11 pm
- Location: South Yorkshire, UK
- Has thanked: 77 times
- Been thanked: 372 times
Re: IPM Motor Simulation and FOC Software
What sort of figures are high inductance vs low inductance? I'd assume my motor (0.1mH to 0.3mH) is low inductance?
BMW E91 2006
ZombieVerter
GS450h
Outlander Charger DC/DC
Renault Kangoo 36kWh battery
ZombieVerter
GS450h
Outlander Charger DC/DC
Renault Kangoo 36kWh battery
- johu
- Site Admin
- Posts: 6259
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 236 times
- Been thanked: 1286 times
- Contact:
Re: IPM Motor Simulation and FOC Software
I guess it's a pretty arbitrary classification and practically also linked to flux linkage. I'd say a motor whos base speed is below 150 Hz or so needs strong field weakening more than a motor whos base speed is above that.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
- Bigpie
- Posts: 1711
- Joined: Wed Apr 10, 2019 8:11 pm
- Location: South Yorkshire, UK
- Has thanked: 77 times
- Been thanked: 372 times
Re: IPM Motor Simulation and FOC Software
Trying to build with the 5.24R but struggling:
any ideas? Tried different QtKits but I'm not vary familiar with Qt. pwmgeneration.cpp does contain them definitions.
Code: Select all
/Users/jamiejones/open-inverter/IPMMotorSim/build-IPMMotorSim-Qt_6_3_2_for_macOS-Debug/pwmgeneration.o:-1: error: Undefined symbols for architecture x86_64:
"PwmGeneration::slipIncr", referenced from:
PwmGeneration::SetFslip(int) in pwmgeneration.o
PwmGeneration::CalcNextAngleAsync(int) in pwmgeneration.o
PwmGeneration::CalcNextAngleConstant(int) in pwmgeneration.o
BMW E91 2006
ZombieVerter
GS450h
Outlander Charger DC/DC
Renault Kangoo 36kWh battery
ZombieVerter
GS450h
Outlander Charger DC/DC
Renault Kangoo 36kWh battery
- Romale
- Posts: 488
- Joined: Fri May 20, 2022 4:16 pm
- Location: Romania
- Has thanked: 273 times
- Been thanked: 62 times
Re: IPM Motor Simulation and FOC Software
in firmware 5.20, it was intuitively clear how to disable the weakening completely and it worked. in new firmware, to completely disable, fwcurmax you need to put -1000 or 0
evil neodymium
- johu
- Site Admin
- Posts: 6259
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 236 times
- Been thanked: 1286 times
- Contact:
Re: IPM Motor Simulation and FOC Software
Almost seems like a CONTROL=FOC directive missing somewhere.Bigpie wrote: ↑Thu Nov 24, 2022 1:59 pm Trying to build with the 5.24R but struggling:
any ideas? Tried different QtKits but I'm not vary familiar with Qt. pwmgeneration.cpp does contain them definitions.Code: Select all
/Users/jamiejones/open-inverter/IPMMotorSim/build-IPMMotorSim-Qt_6_3_2_for_macOS-Debug/pwmgeneration.o:-1: error: Undefined symbols for architecture x86_64: "PwmGeneration::slipIncr", referenced from: PwmGeneration::SetFslip(int) in pwmgeneration.o PwmGeneration::CalcNextAngleAsync(int) in pwmgeneration.o PwmGeneration::CalcNextAngleConstant(int) in pwmgeneration.o
EDIT: no, it's probably because it's a debug build it doesn't dismiss unused functions. May nee to copy the definition of uint16_t PwmGeneration::slipIncr; from pwmgeneration-sine.cpp to pwmgeneration.cpp
-1000 to disable? nooooo. 0 it is
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
- Bigpie
- Posts: 1711
- Joined: Wed Apr 10, 2019 8:11 pm
- Location: South Yorkshire, UK
- Has thanked: 77 times
- Been thanked: 372 times
Re: IPM Motor Simulation and FOC Software
Looks to be already there.
BMW E91 2006
ZombieVerter
GS450h
Outlander Charger DC/DC
Renault Kangoo 36kWh battery
ZombieVerter
GS450h
Outlander Charger DC/DC
Renault Kangoo 36kWh battery
- johu
- Site Admin
- Posts: 6259
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 236 times
- Been thanked: 1286 times
- Contact:
Re: IPM Motor Simulation and FOC Software
That's just the declaration, doesn't allocate memory
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
- Bigpie
- Posts: 1711
- Joined: Wed Apr 10, 2019 8:11 pm
- Location: South Yorkshire, UK
- Has thanked: 77 times
- Been thanked: 372 times
Re: IPM Motor Simulation and FOC Software
Code: Select all
uint16_t PwmGeneration::slipIncr;
BMW E91 2006
ZombieVerter
GS450h
Outlander Charger DC/DC
Renault Kangoo 36kWh battery
ZombieVerter
GS450h
Outlander Charger DC/DC
Renault Kangoo 36kWh battery
- johu
- Site Admin
- Posts: 6259
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 236 times
- Been thanked: 1286 times
- Contact:
Re: IPM Motor Simulation and FOC Software
Forked IPMMotorSim https://github.com/jsphuebner/IPMMotorSim
It fixes above issue and also links in the matching firmware version as a submodule
Pull request created also
It fixes above issue and also links in the matching firmware version as a submodule
Pull request created also
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
Re: IPM Motor Simulation and FOC Software
At risk of exposing myself as the dummy I am could someone give me a step by step guide to building the simulator?
Obviously I start with GIT clone ……
Obviously I start with GIT clone ……
-
- Posts: 1801
- Joined: Sun Apr 03, 2022 1:57 pm
- Has thanked: 102 times
- Been thanked: 349 times
Re: IPM Motor Simulation and FOC Software
Sorry, been meaning to have a look at this but have been feeling a bit rough recently.johu wrote: ↑Sun Nov 27, 2022 7:01 pm Forked IPMMotorSim https://github.com/jsphuebner/IPMMotorSim
It fixes above issue and also links in the matching firmware version as a submodule
Pull request created also
Not too keen on commenting out that block without understanding why the simulator doesn't like it (in case it indicates a bug with the simulator) so have had a look at it.
This is the standard code: And this is with the block commented out: What you can see from this is that Vq does actually need to go negative during the acceleration to keep full control of Iq. You mostly get away with it but do partially loose control until the frequency reaches 30Hz and Vq is allowed to go negative. Can't see any reason why this would be any better in the real world in the car (unless the currents are lower, it doesn't show up at all on lower throttle current values?, or it might be hard to feel as it only lasts a fraction of a second). I'm sure that if you go looking for it you will find traces of it so I think it would be better to fix it rather than commenting out the code for the simulator.
This is the best fix I have come up with:
Code: Select all
if (frqFiltered < FP_FROMINT(5))
qController.SetMinMaxY(dir <= 0 ? -qlimit : 0, dir >= 0 ? qlimit : 0);
else
qController.SetMinMaxY(-qlimit, qlimit);
-
- Posts: 1801
- Joined: Sun Apr 03, 2022 1:57 pm
- Has thanked: 102 times
- Been thanked: 349 times
Re: IPM Motor Simulation and FOC Software
Again sorry should have done this sooner!
First install Qt, https://www.qt.io/download-qt-installer. I'm still using an old version but it should work fine with the latest too. The open source version is fine for this. Qt should be happy on Linux, Windows, Mac, etc.
Once it has downloaded create a directory and then clone the simulator code into it
Code: Select all
git clone https://github.com/Pete9008/IPMMotorSim
Code: Select all
git clone --recurse-submodules https://github.com/jsphuebner/stm32-sine
-
- Posts: 1801
- Joined: Sun Apr 03, 2022 1:57 pm
- Has thanked: 102 times
- Been thanked: 349 times
Re: IPM Motor Simulation and FOC Software
One other though on the above code mod. Wondering if this is what is actually causing the low speed trips when stepping hard on the throttle from standstill. It would fit all the symptoms - not allowing Vq to go negative means that Iq rises in an uncontrolled way to a much higher value (460A plus another 150A of Id in the above example - with the limit set to 300A!) which could well cause a desat event?
@Bigpie - might be worth a try?
@Bigpie - might be worth a try?