IPM Motor Simulation and FOC Software

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 »

130 is the recommended value for the Gen3 so should be OK, need to check the data sheet to see what it is in us. Not much idea on inductance, about the only numbers I've seen are for the Toyota MGR of a few mH. Your motor is bigger but higher revving so maybe similar? Could really do with getting the firmware to measure it.

What was the failure mode of the Prius inverter that you had before the Yaris one?
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 »

What killed it? My old charging code didnt check the contactors was closed, the outlander charger ignores the voltage and respects the requested current. I did a firmware update while charging, silly right?, contactors opened. Charger filled inverter caps to 420v, voltage was above precharge so contactors closed right away. Blew the fuse and inverter could no longer report voltage hv so precharge error.

Still got the power stage and driver board.
Attachments
20220926_201913.jpg
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 »

Oops :(

Safe to assume that it was nothing to do with the cutt outs then!

Wonder what failed, the inverter shouldn't have had a problem with 420V, IGBTs should have been off, should have been no current through the boost inductor?

Just one thought, you are powering it direct to the DC bus terminals rather than through the Prius battery input connections aren't you?
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 »

Direct to dc bus.

Didn't spend any time looking in to why. My only thought was the rapid discharge damaged something.

Use the car daily so just threw in what I could source quickly and was offered a yaris inverter with a smashed capacitor for 20 quid.
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 »

Bigpie wrote: Tue Sep 27, 2022 7:23 am Direct to dc bus.

Didn't spend any time looking in to why. My only thought was the rapid discharge damaged something.

Use the car daily so just threw in what I could source quickly and was offered a yaris inverter with a smashed capacitor for 20 quid.
Thought it would be but it just occurred to me that the boost inductor in series could explain the dead Prius inverter and possibly even the cutouts so worth mentioning just in case.

Bargain on the Yaris inverter! Don't bin the Prius one, may well be some bits worth salvaging.

On the data logger I'm going to order a couple of dev kits. Thought the best approach might be if I put it together and do the C bits and then send the hardware over to you to do the web bits. Let me know if you'd be happy with that?
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 »

I've got plenty of esp32s etc so no need to send any hardware but sure I'll do the web stuff
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 »

Ok, the module Ive gone for has a ESP32-WROOM-32E on it and Im going to try and get the card working in sdio rather than spi mode so anything compatible with those should work fine. Will start a new thread for it once the bits turn up.
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 »

Did you get a dev module with built in sdcard or a separate one? Got a link?
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 »

Couldnt find one with an integrated SD so went for one of these https://shop.pimoroni.com/products/adaf ... kout-board, should be here tomorrow.

Edit - once the coding is done ill have no real use for the dev boards (plan to build the bits directly onto my board eventually) so happy to pass it on if it helps.
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 »

Got a few pretty similar on desk next to me atm. Just need to pickup an sdcard breakout.
Attachments
20220927_130046.jpg
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 »

That should work fine.
Ive also ordered an I2C rtc to use with it to time stamp files. I have sd card logging on the ecu of one car and it just uses sequential file names, its always a right PITA figuring out which file is the one that needs downloading.

Edit - do you use the Arduino environment or Platformio to code for the esp32?

Edit2 - For further details of data logger see here viewtopic.php?t=2690
User avatar
johu
Site Admin
Posts: 5684
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 »

Went for another test drive on the different terrain around my dads place. More straight and level roads.
I changed the maximum d-controller amplitude to max-3000 (was max-1000) to leave more room for the q-controller and set fwmargin=4500.

Before I had driven with fwmargin=2500 and experienced a short burst of acceleration when coming OFF throttle

Shocking result: unwanted acceleration. At about 7000 rpm I came off throttle and the car accelerated happily to 8500 rpm or 100 kph in 2nd gear. Would be nice if it did so on demand. Had to force it back down to 3500 rpm, then came a bang and regulation recovered. No over current. Unfortunately no logging as it was just a quick test and one I certainly don't want to repeat as it is harsh on the battery.

Pete, can you simulate above settings? I know I could but you are more savvy with the simulator. The settings are as posted here viewtopic.php?p=45280#p45280 but fwmargin=4500 and maxVd=max-3000 in PwmInit()
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
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 »

Sure, afraid it won't be till this evening though. Once the code has settled down I need to do a new version of the simulator that supports it.

Not sure I'd exactly call it shocking, I seem to remember mentioning that you were running open loop most of the time in FW and that wasn't a good place to be :o. (sorry, couldn't resist ;) )

Have a look at code mod I posted over in the logger thread viewtopic.php?p=46462#p46462 - I'm fairly sure that those changes to the way Ifw and mtpa are integrated should help when coming off the throttle. The sync compensation should help with acceleration/deceleration above base freq too (sure I've posted the code for it somewhere but can't find it right now, will have a look later when I'm on the PC).

Edit - what would have been nice here is to have had a SD card log. But what that thought then made me think is wouldn't it be nice if the log also contained all the parameter settings too. Wondering if a list of all the parameter settings should be add to the front of log files?
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 »

johu wrote: Wed Oct 05, 2022 5:52 am Went for another test drive on the different terrain around my dads place. More straight and level roads.
I changed the maximum d-controller amplitude to max-3000 (was max-1000) to leave more room for the q-controller and set fwmargin=4500.

Before I had driven with fwmargin=2500 and experienced a short burst of acceleration when coming OFF throttle

Shocking result: unwanted acceleration. At about 7000 rpm I came off throttle and the car accelerated happily to 8500 rpm or 100 kph in 2nd gear. Would be nice if it did so on demand. Had to force it back down to 3500 rpm, then came a bang and regulation recovered. No over current. Unfortunately no logging as it was just a quick test and one I certainly don't want to repeat as it is harsh on the battery.

Pete, can you simulate above settings? I know I could but you are more savvy with the simulator. The settings are as posted here viewtopic.php?p=45280#p45280 but fwmargin=4500 and maxVd=max-3000 in PwmInit()
Here are the plots, two for each. One run just accelerating and one accelerating to around 7krpm and then coasting.

fwmargin=2500, d-controller max-1000:
5_2 fwmargin2500.png
5.20 fwm2500_vdm1000_coast.png
fwmargin=4500, d-controller max-3000:
5_20 fwm4500_vdm30001.png
5_20 fwm4500_vdm3000_coast.png
The differences are fairly subtle and there is no significant difference between the behaviour of the two coming off the throttle. None of them look stable though and they are both going open loop at times when moving to coast. My gut feel is that you were lucky with the 2500 version (it was still going unstable/open loop but not in a way that produced the nasty effects) and it only took a small change to push it outside that sweet spot. Without more detail (a high speed log for example ;) ) I'm not sure it's worth spending much more time looking at this. Once it goes unstable it becomes highly unpredictable and I don't believe my model is good enough to be representative at that point.

The goal has got to be to get the control loops stable and staying within the closed loop region. I think part of the problem is that when you come off the throttle the Mtpa pulls a lot of -Id out. Up to that point that -Id has been helping with the FW but with it gone the FW controller has to suddenly add a lot more -Id to replace it to stop the motor voltages shooting up (you can see this in the plots where Vd and Id shoot up to full scale positive before being slowly pulled back down). This required a very fast FW loop response which then compromises the normal FW control and causes all the noise problems that can be seen in the plots. By changing to the FW and Mtpa scheme I suggested above you avoid this discontinuity completely and can instead tune the FW controller to be a lot slower which avoids all the noise and avoids a lot of the stability issues.

Edit - you can also see the difference between the controller view and motor view of the currents in the plots. Sync compensation should help with this and allow better separation of the q and d components.

Edit2 - That's interesting, based on the simulation FW isn't needed at 7k, will have a look at the settings as see what that means!

Edit3 - Ignore the above for now, flux linkage of 90 seems a bit low for the leaf motor, 150 would seem more reasonable. Need to redo the simulations to see what effect that has.
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 »

Two new plots, both accelerating to around 7k and then coasting but with the value of 150 for flux linkage so that FW is now active at that point.

fwmargin=2500, vd = max-1000:
fwm2500_vdm1000.png
fwmargin=4500, vd = max-3000:
fwm4500_vdm3000.png
Except that I got two of the plots swapped on screen :oops: they look very similar. The fwmargin=2500 is slightly more stable (bigger overshoots on the currents on the fwmargin=4500 plot) but there is not that much in it. All the comments in the above post still apply.
User avatar
johu
Site Admin
Posts: 5684
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 »

Thanks for taking a look, strange the unwanted acceleration doesn't show.

Would really like to do high speed logging but it means draining the cooling system, undo plumbing, remove everything from the top of the inverter and remove the inverter itself... I wonder if there's a way to stream out data to a connected linux PC with the ESP8266, like mentioned on the logger thread. I can get a pretty stable connection when using an external Wifi adapter with high gain antenna.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
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 »

The trouble is that there are so many parameters to play with. I'm sure I could get it to show acceleration but I wouldn't know whether it was an accurate representation or just coincidence. It needs better data hence the logger.

Not sure about the 8266, the data I've seen was inconclusive, it might just manage it it might not. Gut feel is that a cut down app that wasn't servicing anything else probably could. Been thinking a bit more about the tcp stream too and it would probably make most sense for it to just relay the serial port, that way you could set up a virtual tcp comm port and treat it like a direct wired connection.

Edit - still plan to improve the simulator but want to do it based on real data so this thread is likely to go a little quiet till the logger (or 8266 streaming!) starts to produce results.
User avatar
johu
Site Admin
Posts: 5684
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 »

Ok, will take it to the logger thread also
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
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 »

Sorry didn't explain that too well, just don't want to spend a lot of time on developing the simulator until I can be confident that the model is giving a reasonable representation of a real motor and the only way I can see of doing that is by comparing results from it to real data.
User avatar
johu
Site Admin
Posts: 5684
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, it was clear to me. I started a new thread on 8266 streaming to not pollute the ESP32 thread.

Speaking of real data. If we know the battery voltage, frequency and modulation index to obtain a certain d or q current - doesn't that provide us with Ld and Lq?
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
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 »

Sort of :? Its not quite that simple though.

First imagine a locked rotor, in that case the DC currents are defined by the winding resistance. The inductance only determines the ripple current at the pwm frequency (lower inductance - higher ripple). This is how I proposed to measure lq and ld a while back, slowly rotate the motor while measuring how the hf ripple changes as the poles pass the stator.

Then as the rotor starts to spin you get three more terms coming in, the back emf in phase with the vq and dependant on flux linkage and speed, a term in phase with d proportional to speed, Lq and lq and one in phase with q that is proportional to speed, Ld and ld. The model doesn't currently include the last two (I don't fully understand their origin and would like to before I add them,). These may well be why the unwanted acceleration isn't there in the model? The other problem including them is I really don't have a good handle on sensible values for ld and lq.

The last complication is the the voltages commanded via the modulation index do not take effect till the next pwm cycle. This delay is a fixed time and therefore a variable angle as speed changes and so the q and d voltages set by the controller do not match those seen by the motor which causes some interaction from the controllers perspective.

Bear in mind all the above is from memory and I may find it is completely wrong when I go back and look at the equations!

Once we have real data I'm wondering if the best way to tune the model to match a motor is to have a process that just randomly adjusts the parameters and looks for the best fit rather than trying to calculate them.

Edit - forgot to say unwanted acceleration or deceleration can easily be produced in the model by playing with the delay based interaction mentioned above. Having set it to what I think is an accurate representation of the controller timings I tend not to adjust it though. The model suggests that unwanted acceleration or deceleration can occur when -id current commanded by the controller is actually seen by the motor as either +iq or -iq due to the pwm and calculation delays. This is what the sync compensation is meant to fix.

Edit2 - corrected extra terms description above to include Ld and Lq
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 »

The following is copied from Johannes A2 thread as it seems relevant here.
Pete9008 wrote: Thu Oct 13, 2022 11:18 am Think I may have figured out what's going on here. Need to add some missing terms to the simulator equations and test it out later but what I think is happening is this.

There is a term in the IPM equations for uq which is proportional to Ld, Id and speed. This doesn't include flux linkage so isn't affected by field weakening which means it just increases with frequency. This could well be causing the positive feedback on the fw. What it means is that there is a max -Id beyond which further increases do more harm than good; this will vary from motor to motor but it may be possible to calculate the optimum value.
The plan was to spend some time today adding these terms but that hasn't happened. Instead I've been going over the IPM motor equations, the simulator code and the inverter code trying to see why I can't make sense of real world id, iq, uq and ud plot data. So far just seem to be wasting time, no further forward :(

There are a couple of things in particular that bother me. Firstly there seems to be far more interaction between the d and q components than I would expect. Secondly Mtpa seems to make much more of a difference to motors than I would expect based on the reading I've done. Not sure how to address the first until my motor is spinning (a fair way off yet!) but it seems likely that the two are related so -

Could anyone explain to me the difference in the way a real car drives with Mtpa disabled and Mtpa enabled (no other changes, just disabling or enabling Mtpa)? In particular what's the typical difference in torque/acceleration seen (roughly, 10%, 20%, 30%, more?), does it alter how the car coasts or regens, does it alter where in the rev range torque is present or are there any other differences?
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 »

Not sure whether this is the best place for this but need to put it somewhere or will forget about it. Just updating the simulator to support the latest inverter code and found a divide by zero error, line 70 of pwmgeneration-foc.cpp:

Code: Select all

s32fp fwMax = FP_DIV(50 * FP_MUL(Param::Get(Param::throtcur), (ffwstart - frq)), (Param::Get(Param::fmax) - ffwstart));
Only happens if fmax and ffwstart are set to the same value (they are in the github param file) so shouldn't happen in normal use but would be a pain to find if it does.
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 »

Added the previously omitted equation terms to the simulator and the results are significantly different to before but there is also some very odd behaviour and it is very, very sensitive to motor parameters (with Lq/Ld inductances of more than a couple of mH the results just make no sense at all!).

Can't see any point spending more time on it until better data is available to calibrate it against (either accurate motor data or high quality logged data) so it's on hold till one of these is available.
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 »

Looking a bit more at this and I'm wondering whether the simulation is right and the inductance values I'm using are wrong. I've never been able to find any really good Ld and Lq data for motors so it has been a bit of a guess but I'm wondering if the 2-10mH typical values I've been using are waaay too big.

The only data I can find is here https://macsphere.mcmaster.ca/bitstream ... _Ph.D..pdf, Fig4.9 on page 98 (p122 of pdf). It gives values for the leaf motor of Lq ranging from 550uH at 0A reducing to 330uH at 300A and values for Ld ranging from 150uH to 100uH for the same currents. Now these are 10-100 times lower than the values that I have been using in the simulations (and also much, much lower than the values typically used for the Mtpa calcs in the inverter software) and would make a massive difference to the results - the latest simulator results with the extra equation terms might actually start to make sense at that point!

So the question, does anyone have data for the Lq and Ld inductance for other motors?

Note - once we have a good set of logged data these values can also be worked out from that.

Edit - just tried the lower values on the new model and the results look very good :)
Hoping that someone can provide some evidence that the motor inductances are typically in the low hundreds of uH rather than mH.

Edit2 - Even the extra torque generated by Mtpa looks sensible now (which has always previously bothered me as being way too high)!
Post Reply