True FOC: definition and examples

Electric Motors and Controllers
bww129   100 mW

100 mW
Posts: 35
Joined: Apr 14 2020 7:44am
Location: Lancaster PA, USA

Re: True FOC: definition and examples

Post by bww129 » Apr 29 2020 9:39am

Just to throw another definition out there, on page 38 of this ST presentation it states:
"The objective of the [FOC] algorithm is to control the vector components of the stator magnetic field (i.e. the phase currents) in order to obtain the target intensity and phase relation with the rotor magnetic field."

https://www.st.com/content/ccc/resource ... s_pres.pdf

There is also plenty of other good information/diagrams in the presentation.
Last edited by bww129 on Jun 04 2020 1:51pm, edited 1 time in total.

john61ct   100 GW

100 GW
Posts: 7262
Joined: Dec 18 2018 2:06pm

Re: True FOC: definition and examples

Post by john61ct » May 08 2020 2:25pm

Reference from @Bullfrog, not sure if a dupe

https://pdfs.semanticscholar.org/40ac/0 ... 1c74f6.pdf

john61ct   100 GW

100 GW
Posts: 7262
Joined: Dec 18 2018 2:06pm

Re: True FOC: definition and examples

Post by john61ct » May 12 2020 9:32am

Factoid from another relevant thread on IPM specifically, using Lebowsky as an example.
viewtopic.php?f=30&t=105572&start=25#p1554542
amberwolf wrote:Phase current sensors have nothing to do with motor position sensors.
Aren't the latter what is referred to as "encoders"? Are either also referred to as "resolvers"?

I inferred from the above that FOC calculations could be (usually are at least in the ebike world?) based on instantaneous tracking of the individual phase current levels.

Also, any clarification as to how "true FOC" can work in a sensorless setup would be greatly appreciated.

User avatar
Lebowski   1 GW

1 GW
Posts: 3399
Joined: Jun 28 2011 1:38am
Location: beautiful Zurich, Switzerland

Re: True FOC: definition and examples

Post by Lebowski » May 12 2020 10:00am

john61ct wrote:
May 12 2020 9:32am
Also, any clarification as to how "true FOC" can work in a sensorless setup would be greatly appreciated.
You can read the explanation of my stuff here :
viewtopic.php?f=30&t=104895#p1533225

john61ct   100 GW

100 GW
Posts: 7262
Joined: Dec 18 2018 2:06pm

Re: True FOC: definition and examples

Post by john61ct » Jun 03 2020 5:29pm


bww129   100 mW

100 mW
Posts: 35
Joined: Apr 14 2020 7:44am
Location: Lancaster PA, USA

Re: True FOC: definition and examples

Post by bww129 » Jun 06 2020 1:36pm

Vector control for dummies is a very good read with some excellent animations: https://www.switchcraft.org/learning/20 ... or-dummies

john61ct   100 GW

100 GW
Posts: 7262
Joined: Dec 18 2018 2:06pm

Re: True FOC: definition and examples

Post by john61ct » Jun 06 2020 1:43pm

bww129 wrote:Vector control for dummies is a very good read with some excellent animations: https://www.switchcraft.org/learning/20 ... or-dummies
Wow, thanks!

ProgramThyself   100 mW

100 mW
Posts: 35
Joined: May 20 2019 12:13pm
Location: Cambridge, MA
Contact:

Re: True FOC: definition and examples

Post by ProgramThyself » Jun 07 2020 9:13pm

Prof. Kirtley gives a definition in his MIT course notes (Chapter 7, Section 3.3)
https://ocw.mit.edu/courses/electrical- ... rse-notes/
For high performance drives, we will generally assume that the power supply, generally an inverter, can supply currents in the correct spatial relationship to the rotor to produce torque in some reasonably effective fashion. We will show in this section how to determine, given a required torque (or if the torque is limited by either voltage or current which we will discuss anon), what the values of Id and Iq must be. Then the power supply, given some means of determining where the rotor is (the instantaneous value of θ), will use the inverse Park’s transformation to determine the instantaneous valued required for phase currents. This is the essence of what is known as “field oriented control”, or putting stator currents in the correct location in space to produce the required torque.

john61ct   100 GW

100 GW
Posts: 7262
Joined: Dec 18 2018 2:06pm

Re: True FOC: definition and examples

Post by john61ct » Nov 08 2020 2:52pm

Clear statement from VasiliSk wrt the Nucular line

viewtopic.php?p=1596242#p1596242

Ianhill   10 MW

10 MW
Posts: 2189
Joined: Sep 25 2015 5:55pm

Re: True FOC: definition and examples

Post by Ianhill » Nov 08 2020 9:00pm

Your well above me on this but I can give some real world data from the same test mule with from 3 differing types of controller.

The motor is a cheap my1020 48v 1600w (didn't want to burn out anything fancy) and picked a complete scooter up £90 fee years ago it was a steal guy couldn't adjust the chain proper city guyich richer than me so each have they own uses but no to topic
Square wave 2.2kw would get it boiling hot climb 300m 20% incline tap out time

Same climb trapiz controller with a 125% over speed which I think is a set amount of field weakening by the controller non programable set to 4.4kw max on the stunts same climb it would take 2 runs to get the same heat yet i got to the top nearly half the time.so much less heat seemed to made.

Then a vesc 6.6 no field weakening in FOC 2.8kw and I can go up and down till the battery dies there's less heat for sure and the sound is much smoother the range went from 16 miles to 20 but my speed dropped 12 mph or so to dropping volts etc.

I'll be converting my bike to FOC in time it's a no brainer only difference being I won't have to take a power drop so that will be a win win.

Hope thats not to far of topic as I've not mentioned vector algorithms etc.

mxlemming   100 W

100 W
Posts: 147
Joined: Jul 17 2020 7:56am

Re: True FOC: definition and examples

Post by mxlemming » Nov 11 2020 11:47am

Lebowski wrote:
May 12 2020 10:00am
john61ct wrote:
May 12 2020 9:32am
Also, any clarification as to how "true FOC" can work in a sensorless setup would be greatly appreciated.
You can read the explanation of my stuff here :
viewtopic.php?f=30&t=104895#p1533225
Lebowski's controller and explanation is fantastic, and even more so when you realise he wrote the whole lot without knowing about Clark and park but perhaps doesn't answer your question concisely.

Any FOC algorithm requires knowledge of the rotor angle at any instant. FOC does not implicitly know this... Something else has to determine the angle.

In lebowskis code, the loop filters are essentially doing this. I'm not picking through his assembly to work it out exactly. In ST library there is a phase locked loop based on a luenburg observer (it makes a prediction of the next measured current given it's current knowledge of speed, voltage, and position, then adjust itself given the error observed in the prediction when it next measures current) in vesc i think it is done by integrating the observed voltages and knowing that over a revolution the integral will equal zero (equal positive and negative).

Once the angle is known, the FOC proceeds as normal with no knowledge as to where the angle measurement came from.

Interestingly, sensor less algorithms can be more accurate than sensored since they are directly taken from the magnetic field not assumed from accurate encoder/Hall alignment.

Writing the code for my version of it now, I'm realising at the moment is a complete :bolt: :flame: :warn: :warn: ing nightmare. The principle is fairly easy, the reality when you do it is that minor errors make everything just go into random oscillation mode.

mxlemming   100 W

100 W
Posts: 147
Joined: Jul 17 2020 7:56am

Re: True FOC: definition and examples

Post by mxlemming » Nov 11 2020 11:53am

I'll add to the above that typically, observers of whatever type are done in the 2 phase alpha beta frame (after Clark transform) since 1) at high voltages one phase won't have good measurements of current and 2) why mess with 3 phases when you have two nice perpendicular ones that are much easier to deal with.

Starting the motor is tricky. Low speed gives high densities error so usually algorithms just feed max possible current into the stator and then switch to the observer once it's spun up to speed.

ProgramThyself   100 mW

100 mW
Posts: 35
Joined: May 20 2019 12:13pm
Location: Cambridge, MA
Contact:

Re: True FOC: definition and examples

Post by ProgramThyself » Nov 13 2020 10:43pm

mxlemming wrote:
Nov 11 2020 11:47am
in vesc i think it is done by integrating the observed voltages and knowing that over a revolution the integral will equal zero (equal positive and negative).
VESC cites this paper and uses only relatively few lines of code to update the phase:
http://cas.ensmp.fr/~praly/Telechargeme ... stolfi.pdf

Code: Select all

const float L_ia = L * i_alpha;
const float L_ib = L * i_beta;
const float R_ia = R * i_alpha;
const float R_ib = R * i_beta;
const float lambda_2 = SQ(conf_now->foc_motor_flux_linkage);
...
float err = lambda_2 - (SQ(*x1 - L_ia) + SQ(*x2 - L_ib));
float x1_dot = -R_ia + v_alpha + gamma_half * (*x1 - L_ia) * err;
float x2_dot = -R_ib + v_beta + gamma_half * (*x2 - L_ib) * err;
*x1 += x1_dot * dt;
*x2 += x2_dot * dt;
...
*phase = utils_fast_atan2(*x2 - L_ib, *x1 - L_ia);
v_alpha, v_beta and i_alpha, i_beta are the measured voltages and currents in the stator frame. I thought this reference was a little clearer:
https://doi.org/10.1109/TCST.2010.2047396
They do integrate the observed voltages (and include resistance and inductance effects). But I don't see where they integrate over a revolution. TBH, I'm still trying to understand the basics of this paper though.

mxlemming   100 W

100 W
Posts: 147
Joined: Jul 17 2020 7:56am

Re: True FOC: definition and examples

Post by mxlemming » Nov 14 2020 12:01pm

ProgramThyself wrote:
Nov 13 2020 10:43pm
v_alpha, v_beta and i_alpha, i_beta are the measured voltages and currents in the stator frame. I thought this reference was a little clearer:
https://doi.org/10.1109/TCST.2010.2047396
They do integrate the observed voltages (and include resistance and inductance effects). But I don't see where they integrate over a revolution. TBH, I'm still trying to understand the basics of this paper though.
The integration over a revolution is not done by the code, it's a property of the motor that means the above code works. If it were not a property, those integrals would fly off to infinity. Since it is a property of the motor, the x1 and x2 are oscillatory around zero with the frequency of rotation, and a phase difference (90 degrees) which allows angle calculation by arctangent.

ProgramThyself   100 mW

100 mW
Posts: 35
Joined: May 20 2019 12:13pm
Location: Cambridge, MA
Contact:

Re: True FOC: definition and examples

Post by ProgramThyself » Nov 14 2020 5:45pm

mxlemming wrote:
Nov 11 2020 11:47am
in vesc i think it is done by integrating the observed voltages and knowing that over a revolution the integral will equal zero (equal positive and negative).
mxlemming wrote:
Nov 14 2020 12:01pm
The integration over a revolution is not done by the code, it's a property of the motor that means the above code works. If it were not a property, those integrals would fly off to infinity. Since it is a property of the motor, the x1 and x2 are oscillatory around zero with the frequency of rotation, and a phase difference (90 degrees) which allows angle calculation by arctangent.
In a hypothetical situation the motor could always rotate faster during one part of the electrical cycle and slower during the other. Then v_alpha would not necessarily integrate to zero. But I think the observer would still work because of the additional terms in the update equation.

mxlemming   100 W

100 W
Posts: 147
Joined: Jul 17 2020 7:56am

Re: True FOC: definition and examples

Post by mxlemming » Nov 15 2020 2:15pm

ProgramThyself wrote:
Nov 14 2020 5:45pm
In a hypothetical situation the motor could always rotate faster during one part of the electrical cycle and slower during the other. Then v_alpha would not necessarily integrate to zero. But I think the observer would still work because of the additional terms in the update equation.
Not the case. The integral remains the same regardless of speed, since as speed increases, back emf also increases, while the integral time goes down.

This is a pretty much fundamental property of any motor, the integral of back emf over a revolution remains constant, and is determined by the magnetic field strength, the number of poles and the number of turns.

User avatar
Lebowski   1 GW

1 GW
Posts: 3399
Joined: Jun 28 2011 1:38am
Location: beautiful Zurich, Switzerland

Re: True FOC: definition and examples

Post by Lebowski » Nov 15 2020 2:21pm

mxlemming wrote:
Nov 15 2020 2:15pm
ProgramThyself wrote:
Nov 14 2020 5:45pm
In a hypothetical situation the motor could always rotate faster during one part of the electrical cycle and slower during the other. Then v_alpha would not necessarily integrate to zero. But I think the observer would still work because of the additional terms in the update equation.
Not the case. The integral remains the same regardless of speed, since as speed increases, back emf also increases, while the integral time goes down.

This is a pretty much fundamental property of any motor, the integral of back emf over a revolution remains constant, and is determined by the magnetic field strength, the number of poles and the number of turns.
The voltage is the derivative of magnetic flux. So integrating voltage gives magnetic flux, for a coil this equates to 0 after a north and a south poled have passed a coil.

mxlemming   100 W

100 W
Posts: 147
Joined: Jul 17 2020 7:56am

Re: True FOC: definition and examples

Post by mxlemming » Nov 15 2020 5:37pm

Lebowski wrote:
Nov 15 2020 2:21pm
mxlemming wrote:
Nov 15 2020 2:15pm
ProgramThyself wrote:
Nov 14 2020 5:45pm
In a hypothetical situation the motor could always rotate faster during one part of the electrical cycle and slower during the other. Then v_alpha would not necessarily integrate to zero. But I think the observer would still work because of the additional terms in the update equation.
Not the case. The integral remains the same regardless of speed, since as speed increases, back emf also increases, while the integral time goes down.

This is a pretty much fundamental property of any motor, the integral of back emf over a revolution remains constant, and is determined by the magnetic field strength, the number of poles and the number of turns.
The voltage is the derivative of magnetic flux. So integrating voltage gives magnetic flux, for a coil this equates to 0 after a north and a south poled have passed a coil.
I think I mangled my words a bit... I meant at any angle within a revolution the integral should remain constant... Or the integral between any two given angles... Like if you start integrating from 0 angle then at X degrees regardless of the speed your integral should be the same. And over the full 360 degrees it should be 0.

Lebowskis explanation is good. Nice and visual.

ProgramThyself   100 mW

100 mW
Posts: 35
Joined: May 20 2019 12:13pm
Location: Cambridge, MA
Contact:

Re: True FOC: definition and examples

Post by ProgramThyself » Nov 15 2020 7:47pm

mxlemming wrote:
Nov 15 2020 2:15pm
ProgramThyself wrote:
Nov 14 2020 5:45pm
In a hypothetical situation the motor could always rotate faster during one part of the electrical cycle and slower during the other. Then v_alpha would not necessarily integrate to zero. But I think the observer would still work because of the additional terms in the update equation.
Not the case. The integral remains the same regardless of speed, since as speed increases, back emf also increases, while the integral time goes down.

This is a pretty much fundamental property of any motor, the integral of back emf over a revolution remains constant, and is determined by the magnetic field strength, the number of poles and the number of turns.
Lebowski wrote:
Nov 15 2020 2:21pm
The voltage is the derivative of magnetic flux. So integrating voltage gives magnetic flux, for a coil this equates to 0 after a north and a south poled have passed a coil.
You're both right, my example was flawed. But I think current could still be adjusted during each revolution to make the time integral of v_alpha be non-zero for one revolution. After all, the effective magnetic flux can be modified by changing i_d, field-strengthening during one half and weakening during the other half revolution. That may seem contrived, but the observer will surely receive noise inputs with those components and shouldn't random-walk all over the place.

Edit: I'm trying to make two points here: 1. I don't believe this conservation law exists where the time integral of v_alpha is claimed to be zero over each revolution (but admittedly I could be wrong). 2. The observer does not rely on such a law, because the observer is still stable even if noise or commanded behavior make the integral deviate from zero.

Edit #2: I appreciate the explanations. Questioning things is how I learn. Thanks for the technical discussion.

mxlemming   100 W

100 W
Posts: 147
Joined: Jul 17 2020 7:56am

Re: True FOC: definition and examples

Post by mxlemming » Nov 19 2020 7:53am

ProgramThyself wrote:
Nov 15 2020 7:47pm

You're both right, my example was flawed. But I think current could still be adjusted during each revolution to make the time integral of v_alpha be non-zero for one revolution. After all, the effective magnetic flux can be modified by changing i_d, field-strengthening during one half and weakening during the other half revolution. That may seem contrived, but the observer will surely receive noise inputs with those components and shouldn't random-walk all over the place.

Edit: I'm trying to make two points here: 1. I don't believe this conservation law exists where the time integral of v_alpha is claimed to be zero over each revolution (but admittedly I could be wrong). 2. The observer does not rely on such a law, because the observer is still stable even if noise or commanded behavior make the integral deviate from zero.

Edit #2: I appreciate the explanations. Questioning things is how I learn. Thanks for the technical discussion.
Integrating v_alpha does not necessarily add up to zero, because of phase resistance and inductance. But that is not the same as integrating the observed voltages - note in the VESC code you posted, the v_alpha and v_beta are adapting to account for resistance and inductance and then integrating. You need to be specific about what is and is not another value...

The observer is stable because it contains correction- the float err = lambda2... etc... is rolled into it and drags the result back towards zero in the event of noise, error etc.

Code: Select all

const float L_ia = L * i_alpha;
const float L_ib = L * i_beta;
const float R_ia = R * i_alpha;
const float R_ib = R * i_beta;
const float lambda_2 = SQ(conf_now->foc_motor_flux_linkage);
...
float err = lambda_2 - (SQ(*x1 - L_ia) + SQ(*x2 - L_ib));
float x1_dot = -R_ia + v_alpha + gamma_half * (*x1 - L_ia) * err;
float x2_dot = -R_ib + v_beta + gamma_half * (*x2 - L_ib) * err;
*x1 += x1_dot * dt;
*x2 += x2_dot * dt;
...
*phase = utils_fast_atan2(*x2 - L_ib, *x1 - L_ia);

john61ct   100 GW

100 GW
Posts: 7262
Joined: Dec 18 2018 2:06pm

Re: True FOC: definition and examples

Post by john61ct » Dec 09 2020 3:00pm


axialflux   1 mW

1 mW
Posts: 16
Joined: Sep 07 2020 3:52pm

Re: True FOC: definition and examples

Post by axialflux » Dec 12 2020 10:48pm

Google released all the code for the Makani wind kite project on github.
The motor firmware (for the TMS570) runs the Yasa motors, and yes it is "true FOC":

https://github.com/google/makani/tree/m ... r/firmware

Very nice code with great comments, as one might expect from a Google X project .

john61ct   100 GW

100 GW
Posts: 7262
Joined: Dec 18 2018 2:06pm

from amberwolf in another thread

Post by john61ct » Jan 11 2021 11:48pm

From Amberwolf, elsewhere and closely paraphrased:

Per-phase current sensing is required for FOC

though it is not required for sinusoidal control

_____
but I thought true FOC was possible completely sensorless?

j bjork   10 kW

10 kW
Posts: 896
Joined: Aug 31 2018 3:01pm
Location: Linköping, Sweden

Re: True FOC: definition and examples

Post by j bjork » Jan 12 2021 1:03am

It may be possible sensorless in the motor, not in the controller..

User avatar
amberwolf   100 GW

100 GW
Posts: 31684
Joined: Aug 17 2009 6:43am
Location: Phoenix, AZ, USA, Earth, Sol, Local Bubble, Orion Arm, Milky Way, Local Group
Contact:

Re: from amberwolf in another thread

Post by amberwolf » Jan 12 2021 1:15am

john61ct wrote:
Jan 11 2021 11:48pm
From Amberwolf, elsewhere and closely paraphrased:

Per-phase current sensing is required for FOC

though it is not required for sinusoidal control

_____
but I thought true FOC was possible completely sensorless?
"sensorless" (no hall sensors in motor) has absolutely nothing to do with current sensing (in controller).

This was covered earlier in this thread, such as here:
viewtopic.php?f=30&t=105139#p1537712

Post Reply