Hi everyone,
I was thinking about the library modifications which will be necessary in order to provide a true torque controller mode to the SimpleFOC library.
The torque controller mode already included in SimpleFOC is a basic one because it can’t take care of the back EFM generated when the motor is spinning. In some application this is a huge drawback because the torque can’t be controlled precisely over the full speed range.
I propose to detail here some research i did concerning torque control of PMSM. Feel free to comment, correct my words and help us to make a better piece of software, help will be appreciated
So before trying to improve the library let’s have a look at what we already have! The diagram below is a representation of the torque controller available in the current version of simpleFOC :
Concerning the color scheme:
-
Red box are hardware parts
-
Yellow box are code which have to be specific for each MCU or MCU Family
-
Blue box are small piece of software functionality which can be common to all target
-
White box are SimpleFOC function name supporting the blue box functionality.
In my opinion we shall discuss only about the white and the blue box here. Because as we saw with the Advice On Current Sensing thread, sometime, practical implementation can be a huge topic by itself. That’s why I propose to just imagine here that’s we are able to get current, position and speed in a perfect manner on each MCU which will run SimpleFOC, and discus only what can we do with this values.
What i propose to implement is an improved torque controller based on the current flowing through the motor coil, the user can choose according to is board capabilities if it will use the already implemented voltage controller or the new one based on current measurement:
// Motion control type
enum ControlType{
torque,// Torque control
velocity,// Velocity motion control
angle// Position/angle motion control
};
// Current
enum TorqueControlMode{
voltage,// Torque control using voltage (Openloop)
current,// Torque control using current (Closedloop)
};
Below is the diagram of considered the solution :
In case of TorqueControlMode set to voltage then the already implemented controller will be used. The input of the control is a voltage provided by the user or by a higher level loop.
In case of TorqueControlMode set to current. The input of the torquePI function will be a torque in N.m provided by the user or a higher level loop like a speed controller.
In the two configurations the torque setpoint can be set by the move() function as usual.
This approach will require a little rework of the setPhaseVoltage() function because the setphase voltage assume a voltage_d equal to 0.
We can now focus on the implementation of the torquePI() function in current mode :
This torque_sp variable will be used as an input for a new torquePI() function. This function will need all current flowing through the motor, the electrical angle and the torque setpoint in order to compute voltage_q and voltage_d required by the modified setPhaseVoltage function.
Hereafter the detail for each torquePI block:
Clark & Park all in one function
float C2d3 = 0.66666666666666666666666666666667;
float C1d3 = 0.33333333333333333333333333333333;
float C1dsqrt3 = 0.57735026918962576450914878050196;
float a,b,cosine,sine;
a = C2d3*(*ia) - C1d3*((*ib)+(*ic));
b = C1dsqrt3*((*ib)-(*ic));
cosine = cos((*theta_e));
sine = sin((*theta_e));
*d = a*cosine + b*sine;
*q = b*cosine - a*sine;
PI Controller
PI Controller already implemented in the library can be used here.
Torque To Iq
The Electric Torque of a PMSM is depending of this architecture, for a surface mounted magnet the torque equation is as simple as:
Te = (3/2)npmagnet_flux*iq
And magnet flux is equal to: (2kt/(3np)) with Kt the motor constant torque and np the pole pair number of the motor.
So
Te = Kt * iq
For an internal mounted magnet motor this equation is not valid, but for all gimbal brushell motor it dosen’t matter because they use always surface mounted magnets.
That’s it for the moment, don’t hesitate to give your opinion about this approche
Best regards,