Skip to content

Commit c3feef0

Browse files
committed
Bemf Threshold
1 parent eb77697 commit c3feef0

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/encoders/flux_observer/FluxObserverSensor.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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{

src/encoders/flux_observer/FluxObserverSensor.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ class FluxObserverSensor : public Sensor
3535
float i_alpha_prev = 0; // Previous Alpha current
3636
float i_beta_prev = 0; // Previous Beta current
3737
float electrical_angle_prev = 0; // Previous electrical angle
38-
float angle_track = 0;
39-
int8_t first = 1;
38+
float angle_track = 0; // Total Electrical angle
39+
float bemf_threshold = 0.5; // Bemf voltage amplitude when the flux observer should start tracking
40+
int8_t first = 1; // To skip angle difference calculation the first time
4041

4142
protected:
4243
const FOCMotor& _motor;

0 commit comments

Comments
 (0)