Foc algorithm help

Hello community, i’m new around here, i’m new to arduino, although plenty experience with AVR 8bit uC in AVRSutio and 32bit uC’s STM32 in STMCubeIDE, and high power hardware .
So i request you to please point me thru SimpleFOC repository file names where i can find the code responsible for transformations from A B C currents → clark → park → angle , d q PID → inverse park → inverse clark → SVPWM, i need to find the entire algorithm head to tail, i need to undestand a few things regarding angle and type of transformations, because on the web (MATLAB) i found two types of transformations, d aligned to alpha and q aligned to alpha

The thing is, i’m trying to make my own FOC on STM32, i took inspiration from several sources, including simple foc, and i found this FOC Algorithm | Arduino-FOC
but i’m missing some information and i can not find it on github (new to that also).
I also read and watched lost of tutorials, but i’m still missing something.
So far i managed to get it (code) working to some degree, i used the sensorless method with flux observer from MESC (David Molony), but something is not wright regarding angle phase shift and D and Q parametrization.
Problem is that:
1 if i do D aligned to alpha clark and park i get small amount iD, and iQ positive/ negative depending on rotation direction controls speed but has almost no toque (o can stop the motor just by touching the rotor) , with angle provided by the flux observer witch is 90 phase shifted(by the integral).
2 if i do Q aligned to alpha clark and park i get small amount iD positive/ negative depending on rotation direction randomly, and iQ only negative controls torque and speed (i can load the motor heavily) , with angle provided by the flux observer witch is 90 phase shifted(by the integral).
Neither way does not work wright, 1 can control spin direction but does not have torque, 2 can not controll the spin direction (starts randomly CW/CCW) but has torque.
So i’m verry confused by the two versions of transformation.
A look on simple FOC code to see the workflow head to tail of all transformations i believe will clear some things out.
Any points and hints and pointing will be greatly appreciated,
thank you,
Mihai.

1 Like

Hi @mihai_forna :wave:,

I am new here too, but I can help point you in the right direction.

For the transformations in SimpleFOC:

Clark and Park Transforms: Check the foc_utils.cpp file for clarkeTransform() and parkTransform().

Inverse Transforms: Also in foc_utils.cpp, look for invParkTransform() and invClarkeTransform().
SVPWM: Find this in hardware_api.cpp under writeDutyCycle6PWM().

If you’re facing issues with phase alignment or torque, make sure the D axis is correctly aligned with the alpha axis, as SimpleFOC defaults to this setup.

Let me know if you need more help…

Thank you @gwennadf for your reply, and help.
Now if any of you has some experience playing with different motors (like 1 → 5kw or more) with simpleFOC, how would you call a well working motor & FOC ESC, sensored or sensorless, toque, duty or speed mode, how should Id and Iq be like (constant smooth or wiggly ). I have have no ideea when it should be working ok. How do you tune the PI for Vd and Vq?, An oscilating Id and Iq confuses the PI control in my code, and motor goes berserk…