FOC low speed stuttering

User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: FOC low speed stuttering

Post by bexander »

Ok, I will have a look on the current inputs then.

Are you are referring to this SW, viewtopic.php?p=26478#p26478?
I thought that only was for a induction motor, i.e. sine and not FOC?
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: FOC low speed stuttering

Post by bexander »

Results from current plots during stuttering. I'm focusing on the stuttering between 2-3km/h as it is here it really oscillates. When I increase current by applying brakes simultaniously as a drive forward, the oscillation seem to increases in magnitude.

When looking at fstat in the first plot below, one can clearly see the area where it starts to oscillate. The oscillation also shows in the Iq and Id currents. In the second plot, very obvious effect on Iq during oscillation.
Id & Iq left, fstat right
Id & Iq left, fstat right
Id & Iq left, fstat right
Id & Iq left, fstat right
When looking at il1 and il2 it is much harders to so what is going on. Currents seem to chage shape and/or phase during the oscillation.
il1 & il2 left, fstat right
il1 & il2 left, fstat right
il1 & il2 left, fstat right
il1 & il2 left, fstat right
The question is, what causes what? If you send strange output to the motor it will behave strange and give strange input feedback...
Not sure this tells anything more than an oscillation occurs at certain speed. Could it be a issue in SW similar to what happend with the tested TIobserver speed calculation, that induced oscillation, but at standstill.
This behavior seem to always occur at the same speed.
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: FOC low speed stuttering

Post by mjc506 »

Ah, you're correct of course, that's sine and not foc. Although some of the techniques may transfer over, not sure. I'll get to that at some point I'm sure haha

Yes, almost impossible to work out if current oscillations are causing or caused by motor movement. Same with the encoder I guess. As it's always the same speed, my gut feeling is that a software oscillation is being magnified by mechanical resonance though.

Oscillation increases with higher currents... that's quite interesting, as noise will have less effect at higher currents (unless you've got a load of unshielded HV cable wrapped around something sensitive :) ) Your il1 and il2 plots seem pretty good too, I'm tempted to discount noise as a cause.

Thoughts: From your first two plots, it looks like the oscillation in fstat is 'always' there, but I can't make out if the frequency is fairly constant or changes with speed. What do you think, do you see oscillations in fstat on the plot at higher speeds (difficult to test, appreciated) or lower speeds? Do they seem to be constant frequency or related to speed? Increasing with speed could suggest a mechanical cause? (I had a similar fstat plot when my encoder was off centre, unlikely with your hardware. But bent driveshaft? Stiff bearing? Doesn't seem particularly likely, but worth asking, can you feel any 'stiff points' if you jack up the front wheels and turn by hand?) Have you checked resistance between each pair of phases?

It also looks like during the large oscillations, iq rises at the same time as fstat, and falls at the same time too? Which is the opposite to what I'd expect for a constant torque request. But fstat leads iq slightly? Certainly feels like a poorly adjusted control loop...

Your second two plots... I don't like the instantaneous changes in phase at all! And these are readings from the current sensors, so aren't just artefacts of calculations...

Have you played with curkp and curki? I remember reading a post fairly recently where someone had adjusted these and improved iq and id control. I'm not sure what the technique was... I'd suggest trying locking the wheels, apply a little throttle, and adjusting the gains, probably reduce at first?

fstat is calculated from turns per time period, so should always lag a little. But should change slowly relative to all the important variables (except at very low speeds.....) id and iq are the outputs of the Clarke Park transforms - I think these rely on angle and not speed so should be 'correct'. and then the pwm is set based on the transforms, and il1 and il2 are just measurements of actual phase currents. If there is oscillation causing id and iq to lag fstat (which already lags angle), that would point to excess integral gain in the loop I think...

I also note that fstat is around 10Hz as the oscillation gets really bad. Could be a coincidence, but this is when syncadv starts to kick in... I can compile a binary with no syncadv at all if you like? (as a test - it will ruin higher speed performance :) )

I don't suppose you'd be able to stick a camera pointing at your motor during one of these tests? It'd be interesting to see how much physical vibration there is.
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: FOC low speed stuttering

Post by johu »

One comment on these out of phase currents: they are plot artefacts, it pulls 1000 samples at a time.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: FOC low speed stuttering

Post by bexander »

Yes, the plots are not trustworthy when it comes to time due to the not constant sampling. Is it possible to somehow get constant sampling out via the WiFi-interface? It is hard to use a serial cable while driving the car.

In a theoretical ideal world I expect fstat to be a line without any oscillation, correct?

I'll be happy to test a SW without syncadv. Anything to get clues.

Will do test later today.
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: FOC low speed stuttering

Post by mjc506 »

Wouldn't that affect all variables though? Or does it do 1000 samples of one, then 1000 samples of the next etc?

Yes - fstat is set equal to 'frq', which in turn is set to polepairs * encoder::getrotorfrequency(), which just returns lastFrequency which is calculated (in the stock firmware) as turns per second (using turns since the last sample and the sample frequency) So at a constant speed, fstat should also be constant.

Here's the 5.03 firmware (stock, no observer code) with no syncadv. I don't expect this to magically fix everything, but it'd be good to be able to exclude it from the list of possibles :)
Attachments
stm32_foc_5.03_no_syncadv.hex
(115.8 KiB) Downloaded 99 times
stm32_foc_5.03_no_syncadv.bin
(41.15 KiB) Downloaded 103 times
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: FOC low speed stuttering

Post by bexander »

A bit higher speed fstat plot.
2021-04-25-101612_1024x600_scrot.png
A fstat plot at oscillation speed.
2021-04-25-101514_1024x600_scrot.png
Does not seem to vary with speed... but not obvious.

Stock I got curkp 32 and curki 20000.
A lower curki reduces the oscillation significantly. at curki 1000 I can still hear something but I can't feel it. Increasing to 50000 makes the oscillation larger.
Compare with the above at same fstat, curki 1000.
2021-04-25-103623_1024x600_scrot.png
A higher curkp seem to slightly reduce oscillation, but not at all as much as decreased ki. Tested up to 128.
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: FOC low speed stuttering

Post by mjc506 »

Still some oscillation in fstat then even away from 'vibration speed'... But it's only ~1Hz of variation, maybe not worth worrying about.

Good results with curki! Any negative drivability effects? Edit: Even if so, I wonder about setting curki over CAN based on speed... could be a nice workaround. Or in fact, I'd be happy to add some sort on curki ramp into the firmware for you if that's neater. (Still a dirty hack though hahah)
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: FOC low speed stuttering

Post by bexander »

Tested stm32_foc_5.03_no_syncadv.bin with no improvment.

Yes, the oscillation is still there at higher speeds (~10km/h) but with much less amplitude and not noticable during driving.

Regarding curki, I didn't puch hard but the car seem more slugish with low ki. I tested setting it to 0, got a hard bang in the drivetrain as soon as the car started rolling and triggered shutdown of the inverter. Took it a good bit more easy after that... I need to better understand the FOC before I can make any sens of the tuning.
However this doesn't explain what the cause is, it might only hide the effect of the problem.
Or could this just be a tuning issue?
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: FOC low speed stuttering

Post by mjc506 »

Ok, that's another one off the list :) good

Low ki making it sluggish makes sense. My understanding is that different motors have different 'optimum' kp and ki, but I don't know of any good tuning method. I'd tend to agree that large changes in ki is more likely to be masking the problem than solving it though (but equally, 'sluggish' at low speeds and small throttle is a good thing?)

I also need to learn more about FOC, I can follow most of the maths, but don't have a good grasp yet... I must admit that I would be tempted though, if I were in your position, to set up a curki ramp based on speed and throttle!
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: FOC low speed stuttering

Post by johu »

mjc506 wrote: Sun Apr 25, 2021 10:05 am Still some oscillation in fstat then even away from 'vibration speed'... But it's only ~1Hz of variation, maybe not worth worrying about.

Good results with curki! Any negative drivability effects? Edit: Even if so, I wonder about setting curki over CAN based on speed... could be a nice workaround. Or in fact, I'd be happy to add some sort on curki ramp into the firmware for you if that's neater. (Still a dirty hack though hahah)
Well that ramp already exists, parametrized by "curkifrqgain" and driven with a quite heavily filtered fstat.

I have to admit that the current default of curki isn't very scientific :) viewtopic.php?p=5899#p5899
I was very psyched when FOC finally performed on the Leaf motor that I could never be bothered to investigate further into controller tuning.

I mostly understand that the integral part has to make up for the increased voltage needed at higher speeds. The part that is played by V/f in async motor control. If the gain is too low, there will be much integrator windup and the controller becomes too slow. Or the integrator even saturates and the control target is no longer reached.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: FOC low speed stuttering

Post by bexander »

The document linked in the link you posted does not work any longer.
I think that "it works" is a good way to end up at avalue as well... :)

Ok, so maybe for my motor/inverter combination tuning is required. I found a video from Texas Instruments that explains the inner workings of FOC in a way I can understand. https://www.youtube.com/watch?v=cdiZUszYLiA
Makes it a bit easier to if I have at least an idea what is going on.

When looking at the paramerters awailable only curkp and curki should have a large effect at low speeds and then at higher speeds both curkifrqgain and syncadv comes into play. The when field weakning occurs fwkp and dmargin can effect the result as well. Is this somewhat correct?
Curkifrqgain at 50 should then result in that curki @ fstat=100Hz is 20000(base value) + 50*100 = 25000?
So to get as "clean" FOC as possible curkifrqgain and syncadv should be set to 0?
Now then wildly testing of different values of curkp and curki to find somthing that works well at low speed?

Will try to find more info on FOC tuning. Really fumbling in the dark here...
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: FOC low speed stuttering

Post by mjc506 »

Aaahhhh, so maybe a low curki and a high curkifrqgain?
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: FOC low speed stuttering

Post by bexander »

I'm still thinking that it is a bit strange I have a osciallation at a very specific speed but could be down to my mechanical setup.
The instability in the speed calculation from TIobserver, could this also be reduced by changing curki??
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: FOC low speed stuttering

Post by mjc506 »

I think that's just down to resonance, but I'm not sure how I'd prove it :) A datalog of angle might show some interesting things maybe.

The observer code calculates angle by integrating speed, and speed by integrating acceleration (plus some other terms to keep things 'lined up'), so will be more sensitive to short term acceleration, even if not enough to actually move the motor by much. The stock firmware works in the other direction so won't even see tiny oscillations in speed or acceleration. Curki won't directly affect the observer code, but if the motor vibrates less, then it's output will probably improve.
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: FOC low speed stuttering

Post by bexander »

It would be very interesting to test the TIobserver SW on a setup that has less or no stuttering to see if it works there as is.
I'm thinking, due to my somewhat unstable tuning the TIobserver is unstable and hence not really a problem with the TIobserver.

I would be happy to take data logs of angle and/or fstat but how do I do that? This would be a continuous sample of data.
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: FOC low speed stuttering

Post by bexander »

After some thought I still find it a bit odd that fstat seem to be oscillate at a specific frequency even with curki set low (1000).
How is fstat calculated from angle?
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: FOC low speed stuttering

Post by mjc506 »

Yeah, not sure of the best way to get a nice log of data, I'll have a play and see what I can think up... It'd 'only' be ~8kHz...

That's been bugging me too. It can't be the resolver being offset, or any friction/tight spots in the drivechain, otherwise you'd get an obvious speed/frequency relationship. It could just be resonance, but I'd expect that to disappear pretty quickly above a certain speed. And it seems too smooth to be a software timing issue? I'd suspect control loop, but the software controls torque, not speed.

Here's the section that calculates motor speed as lastFrequency (later converted to fstat)

Code: Select all

...
else if ((encMode == RESOLVER) || (encMode == SPI) || (encMode == SINCOS))
   {
      int absTurns = ABS(turnsSinceLastSample);
      if (startupDelay == 0 && absTurns > STABLE_ANGLE)
      {
         lastFrequency = (callingFrequency * absTurns) / FP_TOINT(TWO_PI);
         detectedDirection = turnsSinceLastSample > 0 ? 1 : -1;
      }
      else
      {
         lastFrequency = 0;
      }
      turnsSinceLastSample = 0;
   }
...
Lines 247 - 260 in inc_encoder.cpp
absTurns is in 'digits' (TWO_PI, or 65536 digits per turn). lastFrequency returns in turns per second. turnsSinceLastSample is set here:

Code: Select all

...
void Encoder::UpdateTurns(uint16_t angle, uint16_t lastAngle)
{
   int signedDiff = (int)angle - (int)lastAngle;
   int absDiff = ABS(signedDiff);
   int sign = signedDiff < 0 ? -1 : 1;

   if (absDiff > (TWO_PI / 2)) //wrap detection
   {
      sign = -sign;
      signedDiff += sign * TWO_PI;
      absDiff = ABS(signedDiff);
   }

   turnsSinceLastSample += signedDiff;
}
...
Lines 302 - 316 in inc_encoder.cpp
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: FOC low speed stuttering

Post by bexander »

Well, now that you mention it, my resolver tuning have been a bit odd. I have a fairly large dead band where the motor doesn't move while doing the resolver tuning. I don't have the exact numbers in my head but something like 31500 to 33700 the motor won't move applying 100A Id. I expect a narrower band of standstill like 500-1000 but I get the same or very similar result every time I have done the syncofs tuning.
I could of course test changing my syncofs while observing fstat to see if I get any changes in oscillation.
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: FOC low speed stuttering

Post by mjc506 »

I don't know whether that's fine or bad, but my dead band is much much larger hahah (whether I should blame my encoder or the shoddy used alternator motor I don't know :) ) I do have another motor with a resolver to test, I hope to get some time over the next few days.
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: FOC low speed stuttering

Post by bexander »

Anyone who are willing to test the TIobserver firmware on their setup?
The SW is found here:
viewtopic.php?p=26702#p26702
After the SW is uploaded you will need to change choose 'TIobserver' for 'anglemode' (beneath the dropdown to choose the encoder type on the web interface)? It defaults to the atan2 code.

Test at standstill and, if possible, for a very short drive. Look for instability on "angle"

I'm thinking it is my hardware setup and parameter tuning that messes this up so would be very valuable information testing this SW on other setups.
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: FOC low speed stuttering

Post by johu »

I was going to test today but went after the unwanted regen bug first. I do think I reduced low speed stuttering as well, can you test?
viewtopic.php?f=7&t=1628&p=27628#p27628

I set brkrampstr to 10 Hz now which brings the car almost to a complete stop with no jerkiness at all.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
arber333
Posts: 3241
Joined: Mon Dec 24, 2018 1:37 pm
Location: Slovenia
Has thanked: 74 times
Been thanked: 223 times
Contact:

Re: FOC low speed stuttering

Post by arber333 »

bexander wrote: Mon Apr 05, 2021 9:10 am johu: If you or anyone else is not experiencing what I'm experiencing then it is probably something I have done or something with my motor/inverter combination. Maybe has nothing to do with SW? Just don't want you to, again, put your time into something only I'm experiencing.
arber333 and Zapatero: Please describe a bit more in detail if you are experiencing what I'm experiencing or your behaviors are different.

I find it odd that if it is a signal/noise issue that it is so noticable at a specific speed only. Might be that when starting to move the disturbance increases and then at higher speeds it is masked by motor inertia, but still strange?
My observation with openinverter is valid for ACIM motor. And that has been largely remedied by Jon Volks patch.

With Lebowski i see some rough driveoff from stop like motor couldnt decide which way it is pointed to. This tapers off from 10km/h as motor gains some speed. This doesnt mean motor wont turn forwards, its just way more rumbling for my liking. Arlo told me he made it go away by introducing 15R resistor to GND line from encoder. For me it just wont work...
User avatar
bexander
Posts: 834
Joined: Tue Jun 16, 2020 6:00 pm
Location: Gothenburg, Sweden
Has thanked: 63 times
Been thanked: 89 times

Re: FOC low speed stuttering

Post by bexander »

johu wrote: Sun May 16, 2021 8:36 pm I was going to test today but went after the unwanted regen bug first. I do think I reduced low speed stuttering as well, can you test?
viewtopic.php?f=7&t=1628&p=27628#p27628

I set brkrampstr to 10 Hz now which brings the car almost to a complete stop with no jerkiness at all.
Ok, so I have tested 5.06 and with curki set to 3000 and brkrampstr 10 I get improved results over 5.00 for regen stops. Much less stuttering just before stop, but there are still some. My oscillation is at 2-3km/h is still there. Hard to tell if it have been effected or not but this is a minor thing.

Tested TIobserver with the same settings and disregarding oscillations at standstill this one have a perfect regen stop. No stuttering at all! But it can give very nasty oscillation at standstill.. had to quickly throw in N a couple of times, saw up to 5A battery current while at standstill and very much noise and rattle in the car so be careful with this one. But regen stops are perfect!!

Back to 5.06 with same settings, ok but some stuttering very close to standstill during regen stops.

Tested 5.00 with same settings. This really have bad/nasty regen stops when comparing to 5.06.

My conclusion is 5.00 is not usable with settings above for regen stops. 5.06 is useable but still room for improvment. TIobserver is perfect but needs improvment in other areas.
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: FOC low speed stuttering

Post by johu »

Sounds promising. Will test with observer, maybe I can fix the standstill issue. I think I'll make a special software with disabled PWM :)

EDIT: I also wonder whether the root cause of your low speed stuttering is the cogging? I rolled down my driveway the other day with the car completely off and there was a bit of stuttering.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
Post Reply