Page 26 of 40
Re: IPM Motor Simulation and FOC Software
Posted: Sat Oct 29, 2022 10:54 pm
by Pete9008
mjc506 wrote: ↑Sat Oct 29, 2022 10:23 pm
Built fine. A load of warnings (mostly 'depreciated') but that's probably a QT version thing. But it compiled and ran, and produced pretty graphs of control loops losing the will to live

(You don't want any notes on tuning from me hahaha)
That's good
The warnings are because QT doesn't like the old style casts used in the firmware, sure there is a way of suppressing them but I've not looked.
Re: IPM Motor Simulation and FOC Software
Posted: Sun Oct 30, 2022 6:02 am
by Ev8
Pete9008 wrote: ↑Sat Oct 29, 2022 9:41 pm
I think the converted numbers are:
MG2: Lq = 2mH, Ld = 1mH
MG1: Lq = 1.1mH, Ld = 0.6mH
Without spinning the rotor those could be plus or minus a bit but should be fairly close. The Lq measurement will be a bit low as the motor wouldn't have been correctly aligned for them so maybe 2.2mH and 1.2mH respectively??
Not low inductance but then nowhere near as high as some of the numbers we have been working with
Threw these numbers into the simulator and with 300V it gave a peak power of 100kW dropping to a steady 30kW at higher speeds for each of MG1 and MG2 (MG1 stronger at low speeds, MG2 happier spinning up to higher speeds). No idea how that compares to reality? (Edit - Hmm, those power numbers don't seem quite right, need to have another look at that)
In case the conversion equations are useful to anyone else:
Phase measurement to winding inductances La=(M1+M2-M3)/2, Lb=(M2+M3-M1)/2, Lc=(M1+M3-M2)/2
Winding inductance to Ld/Lq measurements L1 = La + ((Lb*Lc)/(Lb+Lc)), L2 = Lb + ((La*Lc)/(La+Lc)), L3 = Lc + ((La*Lb)/(La+Lb))
Assuming the motor has naturally come to rest aligned on one phase one measurement will be low and will be Ld the other two should be larger, roughly equal and a bit smaller than Lq (for example MG1 above came to 0.6mH, 1.1mH and 1.0mH).
Wow thanks for that, I would have expected mg1 to be happier at higher speeds as generally Toyota rates mg1 to higher rpm.
Re: IPM Motor Simulation and FOC Software
Posted: Sun Oct 30, 2022 7:05 am
by johu
Yes I also ran the simulator just fine and saw many kA of current while playing around
Also looked at the experimental control code and trying to understand:
- RunLimError() is like the normal Run() but it limits the error to the argument given. Is that to limit the slew rate?
- There is no dedicated ifw anymore (so I reckon the value could be removed) but instead the existing id from MTPA is modified by subtracting icrit, scaling it with the voltage limit controller output 0-100% and then adding icrit again. I don't quite understand

but numerical analysis seems to make sense.
Here are my Prius parametes
- throtcur 3.5
- icrit -70 (presumably)
So say I were coasting and am going 50% into the amplitude limit
id=(-0--70)*4096/8192+-70=-35
Then say I were going full throttle, assuming idMtpa=-300 and again 50% amp limit
id=(-300--70)*4096/8192+-70=-185
So as opposed to my code id is also reduced when hitting the amplitude limit. Yes, seems to make sense
Re: IPM Motor Simulation and FOC Software
Posted: Sun Oct 30, 2022 7:36 am
by Pete9008
There are a few earlier posts that should help understand what it is doing.
The RunLimError is trying to balance the slew rate in both directions (the limit probably should be set to fwmargin but I think I forgot to change it when moving from a fixed margin of 1000 to use fwmargin). Without it it can pull limiting out far to fast at it can in theory have an error of almost the full 65k in one direction (compared to 1000 in the other).
I've found the new operating point plot really useful for visualising what is going on when the limiting comes in.
Really ought to add some motor saturation simulation because at the moment the kA currents still produce torque!
Any feel for how the response to tuning the loops matches your experience of the real world?
Re: IPM Motor Simulation and FOC Software
Posted: Sun Oct 30, 2022 7:52 am
by Pete9008
Ev8 wrote: ↑Sun Oct 30, 2022 6:02 am
Wow thanks for that, I would have expected mg1 to be happier at higher speeds as generally Toyota rates mg1 to higher rpm.
Oops, got that the wrong way round when typing, MG1 was better at high speed! Fairly sure the peak power I mentioned is wrong too.
After posting it I added torque and power plots to the simulator and torque from the motor was impressive (450Nm on MG2!) but power less so (60kW). Need to go over the model calculations and see whether the power calculation is right.
Re: IPM Motor Simulation and FOC Software
Posted: Sun Oct 30, 2022 8:05 am
by Ev8
I’m seeing about 100kw on dc side with mg1 and mg2 combined at the 300v so seems about right, also 60kw at 300 volts is about right as I think the Lexus rating of 120kw for mg2 is at 600v
I need to find some more bmwphev modules and Increase to 96s to squeeze at little more power
Re: IPM Motor Simulation and FOC Software
Posted: Sun Oct 30, 2022 8:13 am
by Pete9008
That makes more sense, I also ran it at 500V to try and get to the Lexus rating but it seemed a bit low, didn't realise that they run it at 600V. Maybe the calculations are right then?
At 300V I got:
MG1 300Nm and 43kW
MG2 450Nm and 32kW
So a bit low compared to you measurement.
At 500V the torque was the same (as I left max current at 300A on each), power went up to 70kW and 60kW. If it is linear then 600V would give 85kW and 75kW. These all seem a bit low (MG1 and MG2 powers also seem the wrong way round) so should probably review the maths anyway!
Re: IPM Motor Simulation and FOC Software
Posted: Sun Oct 30, 2022 8:19 am
by Ev8
Re read the actual motor specs instead of using my poor memory
Specification MG1
Rated voltage: 650 V
Max Output HP (kW) @ rpm: 148 HP (109 kW) @ 13000 rpm
Max Torque Nm (lbf) @ rpm: 80 Nm (59 lbf) @ 0 - 13000 rpm
Specification MG2
Rated voltage: 650 V
Max Output HP (kW) @ rpm: 167 HP (123 kW) @ 4500 rpm
Max Torque Nm @ rpm: 333 Nm (246 lbf) @ 0 - 1500 rpm
Also I only hit close to 100kw peak with both and a fully charged pack so 328v
Edit I definitely don’t see anything like the torque you predict for mg1 more it’s definitely a lot less, mg2 is strong though, I generally drive everywhere I. 3rd gear unless I need to cruise at high speed and in 3rd I can spin the wheels from stationary
Re: IPM Motor Simulation and FOC Software
Posted: Sun Oct 30, 2022 8:24 am
by Pete9008
650V
I'll have another look, if the simulator is working properly then it should be possible to get it to get to those numbers but at the moment I don't think it can.
Edit - what current limit do you use?
Re: IPM Motor Simulation and FOC Software
Posted: Sun Oct 30, 2022 8:30 am
by Ev8
Inverter seems to handle 260a mg1 and 430a mg2 without tripping, not checked to see what I’m peaking at the motor
But those numbers should be possible with about 200amps at 650v???
Re: IPM Motor Simulation and FOC Software
Posted: Sun Oct 30, 2022 8:34 am
by Pete9008
Ev8 wrote: ↑Sun Oct 30, 2022 8:19 am
Edit I definitely don’t see anything like the torque you predict for mg1 more it’s definitely a lot less, mg2 is strong though, I generally drive everywhere I. 3rd gear unless I need to cruise at high speed and in 3rd I can spin the wheels from stationary
Thinking about it we are still guessing the flux linkage and that would make a difference for the calculated torque and power. Could do with an easy way of measuring it (at the moment a good quality data log is the only way that I can think of). For the above I just used the same value for both which is almost certainly wrong for MG1, will try a few different values to see how it affects things.
Edit, will use 260A and 430A too.
Re: IPM Motor Simulation and FOC Software
Posted: Sun Oct 30, 2022 8:40 am
by Ev8
Currently guessing at 90mW mg1 and 120mW mg2
Re: IPM Motor Simulation and FOC Software
Posted: Sun Oct 30, 2022 8:42 am
by Pete9008
Just a thought, have Lexus published any torque/power plots for those motors? If they have we could tune the values till the plots match theirs?
Re: IPM Motor Simulation and FOC Software
Posted: Sun Oct 30, 2022 8:49 am
by Ev8
I did once find a study paper online where there had mounted a rx400h mg2 to a Dyno but I tried looking the other day and can’t find it anymore, Lexus themselves haven’t published anything
Re: IPM Motor Simulation and FOC Software
Posted: Sun Oct 30, 2022 9:34 am
by mjc506
Apparently,

- image.png (2.76 KiB) Viewed 3323 times
where P is number of poles (or pole pairs?!) and Kb is the back emf constant (Volt seconds per radian - peak voltage divided by speed in rad/sec)
Kb is easy enough to measure, as is pole count? But that's assuming that the above equation is correct (I can't find the derivation)
Re: IPM Motor Simulation and FOC Software
Posted: Sun Oct 30, 2022 9:57 am
by Pete9008
Good idea
The first version of the simulator did have a calculator based on something similar to that (but with different constants). I took it out because the values didn't look right. Ill try yours to see if its better, if it is then that would be a good way of extracting it from a web plot, find a region where you were coasting below base freq (iq and id zero) and then just pull uq and frq and plug into the equation.
Re: IPM Motor Simulation and FOC Software
Posted: Sun Oct 30, 2022 10:05 am
by mjc506
I span my motor with a drill and measured frequency and peak phase voltage
Although I'm never sure with these equations if they want phase-phase voltage or that imaginary DC equivalent...
Re: IPM Motor Simulation and FOC Software
Posted: Sun Oct 30, 2022 10:22 am
by Pete9008
mjc506 wrote: ↑Sun Oct 30, 2022 10:05 am
I span my motor with a drill and measured frequency and peak phase voltage
Not quite so easy if the motor is already in the car though
mjc506 wrote: ↑Sun Oct 30, 2022 10:05 am
Although I'm never sure with these equations if they want phase-phase voltage or that imaginary DC equivalent...
I would guess the later as I've not seen many motor equations that use the former. Need to find a good book/reference that actually has the derivations, they would answer a lot of questions!
Edit - there was a TI app note that detailed a process for measuring the inductance and flux linkages, that would probably say which voltage is needed. Need to try and find it again.
Re: IPM Motor Simulation and FOC Software
Posted: Sun Oct 30, 2022 10:43 am
by celeron55
Do we want to create a list of motors that we do have the official power or torque plots for?
There's one here for the Q211 MGR (RX400H/450H/Highlander):
https://drive.google.com/file/d/1CGeDep ... s1gYn/view
(linked at
viewtopic.php?f=14&t=190)
Re: IPM Motor Simulation and FOC Software
Posted: Sun Oct 30, 2022 11:17 am
by Pete9008
Good idea
Just found this too, see figure1.
https://www.semanticscholar.org/pape ... 9322241 . Not sure how reliable it is though.
Edit - The Prius plots are interesting, this might explain why gen2 prius motors seem to be quite high inductance. Looks like the gen3 might be easier to drive (if I have my generations vs years right?).
Re: IPM Motor Simulation and FOC Software
Posted: Sun Oct 30, 2022 11:40 am
by Pete9008
mjc506 wrote: ↑Sun Oct 30, 2022 9:34 am
Apparently,
image.png
where P is number of poles (or pole pairs?!) and Kb is the back emf constant (Volt seconds per radian - peak voltage divided by speed in rad/sec)
Kb is easy enough to measure, as is pole count? But that's assuming that the above equation is correct (I can't find the derivation)
Thinking about it the equation I used was missing the 2root(2/3), wonder if that is to convert from pseudo DC to phase voltage?
Re: IPM Motor Simulation and FOC Software
Posted: Sun Oct 30, 2022 2:08 pm
by SciroccoEV
Re: IPM Motor Simulation and FOC Software
Posted: Sun Oct 30, 2022 3:55 pm
by Pete9008
Thanks, will have a look

Re: IPM Motor Simulation and FOC Software
Posted: Sun Oct 30, 2022 4:03 pm
by Pete9008
Just added a new power/torque window to the simulator

Since each plot I add slows it down (a 10sec simulation was taking 30sec to render) I've also made it so that you can select which plots are shown/processed; with a couple of windows up the same run only takes a couple of seconds.
I thought it would be interesting to try and model the motors we have data for so far. The flux linkage is sort of guessed, it's been tweaked until the plot shape is closish to the plots found here
https://www.semanticscholar.org/paper/S ... 5db9322241. The gains have been adjusted a bit for each but I wouldn't say they have been optimised, all the settings can be seen in the screen grabs.
First the Prius Gen2 (based on inductance data off the web):
If anyone has data for the Gen3 let me know, from the link above it looks like it might work better.
Leaf (based on @Bigpie's motor measurements):
Outlander rear (based on my motor measurements):
RX400H MG1 (based on Ev8's motor measurements) (note this is at the Lexus voltage of 650V):
RX400H MG2 (note this is at the Lexus voltage of 650V):
Not sure why but I couldn't get the RX400H figures much higher than this. We may need better flux linkage data to get much closer, I'm not sure how good the values we have at the moment are?
Re: IPM Motor Simulation and FOC Software
Posted: Sun Oct 30, 2022 4:20 pm
by Pete9008
And here are a few plots for @Ev8 with the Lexus motors running at 320V.
MG1:
MG2:
And MG2 again but with the flux linkage increased from 150mW to 200mWeber:
This seems to pull the power up by maybe 20% which is what is making me wonder whether we have our numbers right here?
Edit - Right, off to push the new simulator code to github then that's me done on the PC for the day
