File tree Expand file tree Collapse file tree 2 files changed +7
-1
lines changed Expand file tree Collapse file tree 2 files changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -116,7 +116,10 @@ float HallSensor::getVelocity(){
116
116
if (pulse_diff == 0 || ((long )(_micros () - pulse_timestamp) > pulse_diff) ) { // last velocity isn't accurate if too old
117
117
return 0 ;
118
118
} 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;
120
123
}
121
124
122
125
}
Original file line number Diff line number Diff line change @@ -76,6 +76,9 @@ class HallSensor: public Sensor{
76
76
// this is sometimes useful to identify interrupt issues (e.g. weak or no pullup resulting in 1000s of interrupts)
77
77
volatile long total_interrupts;
78
78
79
+ // variable used to filter outliers - rad/s
80
+ float velocity_max = 1000 .0f
81
+
79
82
private:
80
83
81
84
Direction decodeDirection (int oldState, int newState);
You can’t perform that action at this time.
0 commit comments