@@ -22,8 +22,13 @@ void FluxObserverSensor::update() {
2222 (flux_linkage == 0 )) return ;
2323
2424 // Update sensor, with optional downsampling of update rate
25- if (sensor_cnt++ < sensor_downsample) return ;
26-
25+ if (sensor_cnt++ < sensor_downsample) return ;
26+
27+ // Close to zero speed the flux observer can resonate
28+ // Estimate the BEMF and exit if it's below the threshold
29+ float bemf = _motor.voltage .q - _motor.phase_resistance * _motor.current .q ;
30+ if (abs (bemf < bemf_threshold)) return ;
31+
2732 sensor_cnt = 0 ;
2833
2934 // read current phase currents
@@ -54,7 +59,6 @@ void FluxObserverSensor::update() {
5459 i_beta = _1_SQRT3 * a + _2_SQRT3 * b;
5560 }
5661
57-
5862 // This work deviates slightly from the BSD 3 clause licence.
5963 // The work here is entirely original to the MESC FOC project, and not based
6064 // on any appnotes, or borrowed from another project. This work is free to
@@ -73,11 +77,12 @@ void FluxObserverSensor::update() {
7377 _motor.phase_inductance * (i_beta - i_beta_prev) ,-flux_linkage, flux_linkage);
7478
7579 // Calculate angle
76- float electrical_angle = _normalizeAngle (atan2 (flux_beta,flux_alpha));
80+ float electrical_angle = _normalizeAngle (_atan2 (flux_beta,flux_alpha));
7781
7882 // Electrical angle difference
7983 float d_electrical_angle = 0 ;
8084 if (first){
85+ // Skip angle difference calculation the first time
8186 first = 0 ;
8287 d_electrical_angle = electrical_angle;
8388 }else {
0 commit comments