Skip to content

Commit bb0ed89

Browse files
committed
Remove sqrt2 for kv and use getABcurrents function
1 parent 1a27345 commit bb0ed89

File tree

1 file changed

+8
-30
lines changed

1 file changed

+8
-30
lines changed

src/encoders/flux_observer/FluxObserverSensor.cpp

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ FluxObserverSensor::FluxObserverSensor(const FOCMotor& m) : _motor(m)
77
{
88
// Derive Flux linkage from KV_rating and pole_pairs
99
if (_isset(_motor.pole_pairs) && _isset(_motor.KV_rating)){
10-
flux_linkage = 60 / ( _sqrt(3) * _PI * (_motor.KV_rating/_SQRT2) * (_motor.pole_pairs * 2));
10+
flux_linkage = 60 / ( _SQRT3 * _PI * _motor.KV_rating * _motor.pole_pairs * 2);
1111
}
1212
}
1313

@@ -35,29 +35,7 @@ void FluxObserverSensor::update() {
3535
PhaseCurrent_s current = _motor.current_sense->getPhaseCurrents();
3636

3737
// calculate clarke transform
38-
float i_alpha, i_beta;
39-
if(!current.c){
40-
// if only two measured currents
41-
i_alpha = current.a;
42-
i_beta = _1_SQRT3 * current.a + _2_SQRT3 * current.b;
43-
}else if(!current.a){
44-
// if only two measured currents
45-
float a = -current.c - current.b;
46-
i_alpha = a;
47-
i_beta = _1_SQRT3 * a + _2_SQRT3 * current.b;
48-
}else if(!current.b){
49-
// if only two measured currents
50-
float b = -current.a - current.c;
51-
i_alpha = current.a;
52-
i_beta = _1_SQRT3 * current.a + _2_SQRT3 * b;
53-
} else {
54-
// signal filtering using identity a + b + c = 0. Assumes measurement error is normally distributed.
55-
float mid = (1.f/3) * (current.a + current.b + current.c);
56-
float a = current.a - mid;
57-
float b = current.b - mid;
58-
i_alpha = a;
59-
i_beta = _1_SQRT3 * a + _2_SQRT3 * b;
60-
}
38+
ABCurrent_s ABcurrent = _motor.current_sense->getABCurrents(current);
6139

6240
// This work deviates slightly from the BSD 3 clause licence.
6341
// The work here is entirely original to the MESC FOC project, and not based
@@ -71,10 +49,10 @@ void FluxObserverSensor::update() {
7149
// Flux linkage observer
7250
float now = _micros();
7351
float Ts = ( now - angle_prev_ts) * 1e-6f;
74-
flux_alpha = _constrain( flux_alpha + (_motor.Ualpha - _motor.phase_resistance * i_alpha) * Ts -
75-
_motor.phase_inductance * (i_alpha - i_alpha_prev),-flux_linkage, flux_linkage);
76-
flux_beta = _constrain( flux_beta + (_motor.Ubeta - _motor.phase_resistance * i_beta) * Ts -
77-
_motor.phase_inductance * (i_beta - i_beta_prev) ,-flux_linkage, flux_linkage);
52+
flux_alpha = _constrain( flux_alpha + (_motor.Ualpha - _motor.phase_resistance * ABcurrent.alpha) * Ts -
53+
_motor.phase_inductance * (ABcurrent.alpha - i_alpha_prev),-flux_linkage, flux_linkage);
54+
flux_beta = _constrain( flux_beta + (_motor.Ubeta - _motor.phase_resistance * ABcurrent.beta) * Ts -
55+
_motor.phase_inductance * (ABcurrent.beta - i_beta_prev) ,-flux_linkage, flux_linkage);
7856

7957
// Calculate angle
8058
float electrical_angle = _normalizeAngle(_atan2(flux_beta,flux_alpha));
@@ -110,8 +88,8 @@ void FluxObserverSensor::update() {
11088
angle_prev = angle_track /_motor.pole_pairs;
11189

11290
// Store Previous values
113-
i_alpha_prev = i_alpha;
114-
i_beta_prev = i_beta;
91+
i_alpha_prev = ABcurrent.alpha;
92+
i_beta_prev = ABcurrent.beta;
11593
angle_prev_ts = now;
11694
electrical_angle_prev = electrical_angle;
11795

0 commit comments

Comments
 (0)