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(){
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}
Original file line number Diff line number Diff 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);
You can’t perform that action at this time.
0 commit comments