Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/sensors/HallSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,11 @@ float HallSensor::getMechanicalAngle() {
function using mixed time and frequency measurement technique
*/
float HallSensor::getVelocity(){
if (pulse_diff == 0 || ((long)(_micros() - pulse_timestamp) > pulse_diff) ) { // last velocity isn't accurate if too old
long last_pulse_diff = pulse_diff;
if (last_pulse_diff == 0 || ((long)(_micros() - pulse_timestamp) > last_pulse_diff) ) { // last velocity isn't accurate if too old
return 0;
} else {
float vel = direction * (_2PI / (float)cpr) / (pulse_diff / 1000000.0f);
float vel = direction * (_2PI / (float)cpr) / (last_pulse_diff / 1000000.0f);
// quick fix https://github.com/simplefoc/Arduino-FOC/issues/192
if(vel < -velocity_max || vel > velocity_max) vel = 0.0f; //if velocity is out of range then make it zero
return vel;
Expand Down