Skip to content

Commit f9f1d3c

Browse files
committed
hall sensor fix simplefoc#192
1 parent b1a5e4e commit f9f1d3c

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/sensors/HallSensor.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ float HallSensor::getVelocity(){
116116
if (pulse_diff == 0 || ((long)(_micros() - pulse_timestamp) > pulse_diff) ) { // last velocity isn't accurate if too old
117117
return 0;
118118
} else {
119-
return direction * (_2PI / (float)cpr) / (pulse_diff / 1000000.0f);
119+
float vel = direction * (_2PI / (float)cpr) / (pulse_diff / 1000000.0f);
120+
// quick fix https://github.com/simplefoc/Arduino-FOC/issues/192
121+
if(vel < -velocity_max || vel > velocity_max) vel = 0f; //if velocity is out of range then make it zero
122+
return vel;
120123
}
121124

122125
}

src/sensors/HallSensor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ class HallSensor: public Sensor{
7676
// this is sometimes useful to identify interrupt issues (e.g. weak or no pullup resulting in 1000s of interrupts)
7777
volatile long total_interrupts;
7878

79+
// variable used to filter outliers - rad/s
80+
float velocity_max = 1000.0f
81+
7982
private:
8083

8184
Direction decodeDirection(int oldState, int newState);

0 commit comments

Comments
 (0)