Hello @Antun_Skuric, @robin2906,
@Antun_Skuric Your last version 2.0 is great, it really is an improvement and more structured, well done. Otherwise, I had just a little bit precision about the formula of the current as I have shown above, as KE is in Vrms/Krpm (standard) and sensor.getVelocity() in rd/s, I propose you to put a constant factor equal to :
#define KE (x.xx) // Back emf in Vrms/KRPM
#define BEMFC ((_SQRT2 * _2PI / (1000 * 60)) * KE) // BEMFC is the Back emf in Vpeak/rd/s
and the formula becomes:
estimate.current = ( motor.voltage_q - BEMFC * sensor.getVelocity() ) / Z
Another stuff, the _sqrt from the formula of Z can be a classic fast sqrt implemented in the foc_utils.cpp:
Blockquote
// Fast sqrt
float _sqrt(float n) {
n = 1.0f / n;
long i;
float x, y;
x = n * 0.5f;
y = n;
i = *(long *)&y;
i = 0x5f3759df - (i >> 1);
y = *(float *)&i;
y = y * (1.5f - (x * y * y));
return y;
}
Therefore from formula here above, the limit torque could be controlled by :
motor.voltage_limit = target_current * Z + BEMFC * motor.target_velocity;
with target_current
in Amps, motor.target_velocity
in rd/s, motor.voltage_limit
in Volt.
@Antun_Skuric, @robin2906 In the second approach, we can deduce an estimate velocity from the current reading with:
estimate.speed = (motor.voltage_q - Z * motor.current) / BEMFC
with
motor.voltage_q
is the voltage applies to the phaseZ
is the impedance in ohmsmotor.current
the current reading in AmpsBEMFC
the backemf constant in Vpeak/rd/sestimate.speed
is in rd/s
Therefore, you could implement estimate functions in the both approach in the future, as shown above…
Your thoughts ?