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 »

Bigpie wrote: Sat Sep 10, 2022 10:17 am Attaching latest log as a method of getting it off my phone.

Getting in bother for experimenting with the kids in the car.

Cut outs always on acceleration, I'd love to get the bottom of why it's cutting out, maybe overshooting? I can sometimes get my foot to the floor, others not so.
"fwkp": 1,
"fwki": 1,
"fwmargin": 2000,

If I wanted to graph from my log, would I be plotting the avg columns?
Fwki and fwmargin are both a bit low, I'd increase both a bit. Johu seems to be having good results with higher kp too. The low values are probably why there is no Ifw in the plots.

I'm busy this afternoon but will try and have a look at the data this evening.

No idea on plots, I'd guess start with average and then look at the others if you need more detail on any values?

Does the Prius do desat detection internally, could it be that? Is a restart needed to get going again?

Edit - is there a second scale for the temperature values, surely they cant be that high?

Edit2 - would it be worth winding throtcur down a bit?

Edit3 - got to go but good luck with testing. Be careful!
User avatar
Bigpie
Posts: 1595
Joined: Wed Apr 10, 2019 8:11 pm
Location: South Yorkshire, UK
Has thanked: 75 times
Been thanked: 304 times

Re: IPM Motor Simulation and FOC Software

Post by Bigpie »

Prius inverter has internal protections.

Temperature shoots up and down pretty quickly so it can't be heatsink, must be die temperature?
I've got auto restart setup so if if lift throttle off it's good to go again after a second or so.

My motor is tiny, need all the current it can get. Hence needing first gear :D

Upgrading to a leaf motor when it arrives.
VW Beetle 2003
Outlander front generator
Prius Gen 3 inverter (EVBMW logic board)
Outlander charger
3x Golf GTE batteries
Chademo Charging
Outlander water heater
User avatar
johu
Site Admin
Posts: 5791
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 157 times
Been thanked: 1023 times
Contact:

Re: IPM Motor Simulation and FOC Software

Post by johu »

At this point just want to say that I regard this as a team effort. I much appreciate Petes second set of eyes on the code and the simulator as well as people who are testing. I know testing is scary if you don't know what surprises the controllers have prepared for you. So thanks very much everyone for being brave :)

Now, I did some "simulation" of the FW controller myself

Code: Select all

int main()
{	
	PiController c;
	
	c.SetGains(10,100);
	c.SetCallingFrequency(8800);
	c.SetMinMaxY(-FP_FROMINT(200), 0);
	c.SetRef(33000);
	
	printf("Cycles,integrator,output\n");
	
	for (int i = 0; i < 10000; i++)
	{
		float y = FP_TOFLOAT(c.Run(34000));
		
		if (i % 100 == 0)
			printf("%d,%d,%f\n", i, c.GetIntegrator(), y);
	}
	
	return 0;
}
And the astonishing result: after 10000 cycles or more than 1s only -120A FW current has built up and it's just about 160 mA per 100 cycles at a 1000 amplitude error. Must have missed some scaling in my previous calculation. Executing code never lies.
ki=1000 reaches -200A after 1800 cycles or like 0.2s
image.png
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: 5791
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 157 times
Been thanked: 1023 times
Contact:

Re: IPM Motor Simulation and FOC Software

Post by johu »

I have also modified anti windup once again:

Code: Select all

void PiController::SetIntegralGain(int ki)
{
   this->ki = ki;

   if (ki != 0)
   {
      minSum = FP_FROMINT((minY * frequency) / ABS(ki));
      maxSum = FP_FROMINT((maxY * frequency) / ABS(ki));
   }
}
The function is also called when modifying calling frequency and output saturation values.

The actual controller then does

Code: Select all

int32_t PiController::Run(s32fp curVal)
{
   s32fp err = refVal - curVal;
   esum += err;

   //anti windup
   esum = MIN(esum, maxSum);
   esum = MAX(esum, minSum);

   int32_t y = FP_TOINT(err * kp + (esum / frequency) * ki);
   int32_t ylim = MAX(y, minY);
   ylim = MIN(ylim, maxY);

   return ylim;
}
Objections?
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 »

Bigpie I’m thinking you’ll need to lower your throtramp significantly at 50 you can command 0-100% throttle in 20ms there no way the inverter is going to be happy with that!
User avatar
Bigpie
Posts: 1595
Joined: Wed Apr 10, 2019 8:11 pm
Location: South Yorkshire, UK
Has thanked: 75 times
Been thanked: 304 times

Re: IPM Motor Simulation and FOC Software

Post by Bigpie »

Will test that. :D
Just browsing other peoples parameters. https://openinverter.org/parameters/view.html?id=10 Gen 2 Prius inverter, but throtcur 6.25 :O hells bells
VW Beetle 2003
Outlander front generator
Prius Gen 3 inverter (EVBMW logic board)
Outlander charger
3x Golf GTE batteries
Chademo Charging
Outlander water heater
User avatar
johu
Site Admin
Posts: 5791
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 157 times
Been thanked: 1023 times
Contact:

Re: IPM Motor Simulation and FOC Software

Post by johu »

That's not Prius, it's Leaf :)
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
User avatar
Bigpie
Posts: 1595
Joined: Wed Apr 10, 2019 8:11 pm
Location: South Yorkshire, UK
Has thanked: 75 times
Been thanked: 304 times

Re: IPM Motor Simulation and FOC Software

Post by Bigpie »

Been out testing more. Lots of cutouts :D
Changed throtramp to 5 and throcur to 3 (cuts out)
throtcur_3_foot_to_floor_cutout.png
Throtcur at 2.5 (cuts out)
Throtcur_2_5.png
Throtcur at 2 (cuts out)
throtcur2.png
Throtcur 4.5 accelerated really well but also cuts out.
4_5_throtcur_cutout.png
VW Beetle 2003
Outlander front generator
Prius Gen 3 inverter (EVBMW logic board)
Outlander charger
3x Golf GTE batteries
Chademo Charging
Outlander water heater
User avatar
johu
Site Admin
Posts: 5791
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 157 times
Been thanked: 1023 times
Contact:

Re: IPM Motor Simulation and FOC Software

Post by johu »

I think the low throtcur values didn't really apply as total current is way higher than 200 or 250A, respectively.

I've also been out for a run and I think I've pretty much nailed it.
Only software change as been the anti-windup scheme from above, everything else untouched.
I increased fwki to 500 and started with fwmargin 4000. It never saturates, no weirdness when coming off throttle and regen works as expected. Remaining weirdness was non-linear throttle response, so as soon as FW starts, the car accelerates more.
run20.png
This next one was downhill. fwmargin 2700. I came off throttle but the car was merely coasting, no regen. Thus sped up past fmax, but by gravity, not electricity. Touched the brake pedal which increases regen and then regen came in nicely. What exactly limited it I'm not sure.
run21.png
Final run, fwki=300 and fwmargin=2500. We see saturation again but throttle response is now linear. Regen comes in without issues at 7000 rpm.
run22.png
EDIT: plots look a little different today as I took 100 sample bursts. All the jumps you see are artifacts
EDIT2: just realized I've been running without any syncadv all the time:

Code: Select all

FP_MUL(frqFiltered, Param::GetInt(Param::syncadv))
will evaluate as 0 when it is set to 0.5. Alright, I'll just remove it, one mistake less to be make

EDIT3: liking this so much that I drafted a new release viewtopic.php?t=2650
Attachments
stm32_foc.bin
(48.12 KiB) Downloaded 36 times
Leaf 2022-09-10.json
(1.42 KiB) Downloaded 64 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 »

Damm more software to test lol I’ve just been out the last 3hrs trying to tune the last build! (Unsuccessfully I might add) no matter what I tried I had lift off regen above 4K rpm and sustained brake pedal regen above 3krpm, both sustained down to 2k. I even set f/w gain to 0 to rule that out, strangely this gained me power, in fact in my trying everything efforts I can now peak 260amps and sustain 240amps ( dc current at the battery ) throughout the useable Rev range before was more like 220peak 180 tailing off. Anyway like I said played with everything controller gains, syncadv, even moved my syncofs forward and back 1000points at a time, nothing helped!

I will try this next build tomorrow I hope
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 »

I wish I was able to put some logs up but with 2 motors and 2 Wi-Fi adapters that’s not easy and I just can’t keep a sable Wi-Fi connection through a spirited drive
User avatar
Bigpie
Posts: 1595
Joined: Wed Apr 10, 2019 8:11 pm
Location: South Yorkshire, UK
Has thanked: 75 times
Been thanked: 304 times

Re: IPM Motor Simulation and FOC Software

Post by Bigpie »

Are your graphs with 100% throttle @johu? Your currents are much lower than mine
I've been forgetting to plot the q and d voltages
VW Beetle 2003
Outlander front generator
Prius Gen 3 inverter (EVBMW logic board)
Outlander charger
3x Golf GTE batteries
Chademo Charging
Outlander water heater
User avatar
johu
Site Admin
Posts: 5791
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 157 times
Been thanked: 1023 times
Contact:

Re: IPM Motor Simulation and FOC Software

Post by johu »

Bigpie wrote: Sat Sep 10, 2022 6:33 pm Are your graphs with 100% throttle @johu? Your currents are much lower than mine
I've been forgetting to plot the q and d voltages
No, I will take some when driving in 3rd gear
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: 5791
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 157 times
Been thanked: 1023 times
Contact:

Re: IPM Motor Simulation and FOC Software

Post by johu »

One word of warning: since we are now successfully putting throttle-independent current into the motor it is possible that the rev limiter no longer works in a no-load scenario. The slightest misalignment will create some small amount of torque which is not noticeable when attached to the weight of a car but could become very destructive on an unloaded rotor.

So do not rev up the motor beyond base speed when it is not loaded!
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 »

johu wrote: Sat Sep 10, 2022 4:42 pm EDIT3: liking this so much that I drafted a new release viewtopic.php?t=2650
Got to say I feel a bit awkward about this! I post saying I think there is a stability issue with the controller, you post saying it's all good and here is a new release. It's your code and your descision but it's not a way of working that I'm particularly comfortable with :?

At the risk of sounding like a broken record, please be careful. In your final plot both Iq and Id controllers look like they are maxed out for a lot of the run meaning that they are running open loop and not fully controlling the motor. It doesn't look like it caused any issues but it's not a good place to be above base frequency.
Bigpie wrote: Sat Sep 10, 2022 10:17 am Attaching latest log as a method of getting it off my phone.

Getting in bother for experimenting with the kids in the car.

Cut outs always on acceleration, I'd love to get the bottom of why it's cutting out, maybe overshooting? I can sometimes get my foot to the floor, others not so.
"fwkp": 1,
"fwki": 1,
"fwmargin": 2000,

If I wanted to graph from my log, would I be plotting the avg columns?

EDIT, Sorry wrong params attached. Updated

At 435 on the bottom axis looks to be where I had 3 coutouts in a row. The brown plot in the temperature from the inverter.
Had a look at this, pretty sure it's the desat. Although the individual currents aren't that high each point covers around 0.6sec, or around 5000 loops through the control loop so it's not telling the whole story. I've plotted it again including the min and max currents:
BigpieTrip.png
There is quite a big difference between the min and the max and it is pretty constant which suggest that there is a bit of oscillation in the controllers. Also plotted is the max combined current (Is) which is getting up to 500A at times (roughly the times where you have the trips) and I seem to remember Damien commenting that 500A is around the limit for the Gen3?. I realise that not all this current will be going through a single IGBT but a fair chunk will and the above is enough to convince me that desat is the issue.

It would be worth tweaking the ki and kp's a bit to see if you can reduce the difference between Imin and Imax.

Edit - Thinking about it a bit more it could also be noise in the system rather than stability issues?

I have also had a look at reducing the latency but have realised that Timer3 is used by the encoder modes as well as resolver modes and my planned mods would break that. Need to have another think and read of the data sheets to see what other options there may be.
User avatar
Bigpie
Posts: 1595
Joined: Wed Apr 10, 2019 8:11 pm
Location: South Yorkshire, UK
Has thanked: 75 times
Been thanked: 304 times

Re: IPM Motor Simulation and FOC Software

Post by Bigpie »

So apparently the prius will only cut for desat. My cutouts are always happening at around 380Hz so I've set fmax to 350 for now, limits me to around 6500 rpm vs 14k if I gently take it past that speed
Screenshot 2022-09-11 at 10.55.38 am.png
This is with the 5.20 release. Drives pretty well with fmax set to 350
VW Beetle 2003
Outlander front generator
Prius Gen 3 inverter (EVBMW logic board)
Outlander charger
3x Golf GTE batteries
Chademo Charging
Outlander water heater
User avatar
johu
Site Admin
Posts: 5791
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 157 times
Been thanked: 1023 times
Contact:

Re: IPM Motor Simulation and FOC Software

Post by johu »

Pete9008 wrote: Sun Sep 11, 2022 11:16 am Got to say I feel a bit awkward about this! I post saying I think there is a stability issue with the controller, you post saying it's all good and here is a new release. It's your code and your descision but it's not a way of working that I'm particularly comfortable with :?
Yes, I hear you, but: it is an improvement over the version before that (5.14.R) that certainly developed unwanted regen even at relatively low speeds.
Pete9008 wrote: Sun Sep 11, 2022 11:16 am At the risk of sounding like a broken record, please be careful. In your final plot both Iq and Id controllers look like they are maxed out for a lot of the run meaning that they are running open loop and not fully controlling the motor. It doesn't look like it caused any issues but it's not a good place to be above base frequency.
yes, agreed. Essentially that limits FW current but the cleaner solution would be to have an extra parameter for maximum FW current rather than just setting it to throtcur*50.
EDIT: in the first plot it looks much nicer but it felt much worse. Field weakening current also creates reactance torque creating large torque ripple as it comes and goes.
Bigpie wrote: Sat Sep 10, 2022 4:11 pm Been out testing more. Lots of cutouts :D
can you post your full parameter set? Especially interested in curkp/ki
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
User avatar
Bigpie
Posts: 1595
Joined: Wed Apr 10, 2019 8:11 pm
Location: South Yorkshire, UK
Has thanked: 75 times
Been thanked: 304 times

Re: IPM Motor Simulation and FOC Software

Post by Bigpie »

Full params attached. Not really done and PID tuning. I'm not 100% sure what I'm looking for when changing them.
Attachments
params (1).json
(1.45 KiB) Downloaded 42 times
VW Beetle 2003
Outlander front generator
Prius Gen 3 inverter (EVBMW logic board)
Outlander charger
3x Golf GTE batteries
Chademo Charging
Outlander water heater
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 »

Interested to hear how johu gets on tuning this latest software on the gen2 Prius, because I’ve spent another couple of hours on it today and still unsuccessful, no amount of controller tuning seems to stop unwanted regen, and I can’t use any amount of field weakening without uncontrollable throttle!
User avatar
johu
Site Admin
Posts: 5791
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 157 times
Been thanked: 1023 times
Contact:

Re: IPM Motor Simulation and FOC Software

Post by johu »

Yes that will be a couple of weeks as I'm away soon and still have to replace that shaft seal to be able to drive.
Did you try similar parameters to my Leaf ones?
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: 5791
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 157 times
Been thanked: 1023 times
Contact:

Re: IPM Motor Simulation and FOC Software

Post by johu »

Bigpie wrote: Sun Sep 11, 2022 2:55 pm Full params attached. Not really done and PID tuning. I'm not 100% sure what I'm looking for when changing them.
The integral gains seem a bit low, I wouldn't expect them to differ that much from the Leaf ones (curki=35000, fwki=300) but I don't know for sure.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
User avatar
Bigpie
Posts: 1595
Joined: Wed Apr 10, 2019 8:11 pm
Location: South Yorkshire, UK
Has thanked: 75 times
Been thanked: 304 times

Re: IPM Motor Simulation and FOC Software

Post by Bigpie »

Screenshot 2022-09-11 at 10.16.18 pm.png
Saw this post ages ago and just went with it :D
viewtopic.php?f=19&t=902&p=21451#p21451
Will have a play around though.
VW Beetle 2003
Outlander front generator
Prius Gen 3 inverter (EVBMW logic board)
Outlander charger
3x Golf GTE batteries
Chademo Charging
Outlander water heater
User avatar
johu
Site Admin
Posts: 5791
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 157 times
Been thanked: 1023 times
Contact:

Re: IPM Motor Simulation and FOC Software

Post by johu »

hmm, ok. My motor is slightly noisy as well. I'll try lowering it back down but that's after holiday ;)
Also I forgot to take out curkifrqgain. I had it set to 0 for all tests.
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: Sun Sep 11, 2022 8:33 pm Yes that will be a couple of weeks as I'm away soon and still have to replace that shaft seal to be able to drive.
Did you try similar parameters to my Leaf ones?
Yes tried similar to your leaf, about the only thing I haven’t tried is the inverse syncofs
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: Sun Sep 11, 2022 1:48 pm EDIT: in the first plot it looks much nicer but it felt much worse. Field weakening current also creates reactance torque creating large torque ripple as it comes and goes.
I'm not convinced it's reluctance torque. I think it's caused by the change in the rotor angle between the commanded Iq and Id being calculated and the time they actually take effect. This means that the motor sees a chunk of the -Id as torque producing Iq and a chunk of the commanded Iq is wasted generating positive Id. Something along these lines should help:

Code: Select all

in foc.c
void FOC::SetAngle(uint16_t angle, uint16_t syncadv)
{
   sin = SineCore::Sine(angle + syncadv);
   cos = SineCore::Cosine(angle + syncadv);
}

inpwmgeneration-foc.c
at the top
      CalcNextAngleSync(dir);
      FOC::SetAngle(angle, 0);
      
and lower down
      s32fp syncadv = FP_MUL(frqFiltered, Param::Get(Param::syncadv));
      syncadv = MAX(0, syncadv);
      FOC::SetAngle(angle, FP_TOINT(dir * syncadv));

      FOC::InvParkClarke(ud, uq);
More details of what it's doing is here viewtopic.php?p=45185#p45185. It should help by better aligning the Id and Iq to the rotor position. It should also reduce the magnitude of the commanded Uq which will help keep the Uq and Ud controllers running closed loop.

I may not help but without trying it we won't know (and in any case the results from trying it will help understand exactly what is going on).
Post Reply