Skip to content

Commit

Permalink
Merge pull request mavlink#4695 from nanthony21/improve_deadband
Browse files Browse the repository at this point in the history
Improve deadband
  • Loading branch information
DonLakeFlyer authored Mar 29, 2017
2 parents f0c7608 + 279d560 commit 5c7f03a
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/Joystick/Joystick.cc
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,20 @@ float Joystick::_adjustRange(int value, Calibration_t calibration, bool withDead
axisLength = calibration.center - calibration.min;
}

float axisPercent;

if (withDeadbands) {
if (valueNormalized>calibration.deadband) valueNormalized-=calibration.deadband;
else if (valueNormalized<-calibration.deadband) valueNormalized+=calibration.deadband;
else valueNormalized = 0.f;
if (valueNormalized>calibration.deadband) {
axisPercent = (valueNormalized - calibration.deadband) / (axisLength - calibration.deadband);
} else if (valueNormalized<-calibration.deadband) {
axisPercent = (valueNormalized + calibration.deadband) / (axisLength - calibration.deadband);
} else {
axisPercent = 0.f;
}
}
else {
axisPercent = valueNormalized / axisLength;
}

float axisPercent = valueNormalized / axisLength;

float correctedValue = axisBasis * axisPercent;

Expand Down

0 comments on commit 5c7f03a

Please sign in to comment.