Skip to content

Commit

Permalink
refactor: 🚧 Remove deadband from curve
Browse files Browse the repository at this point in the history
  • Loading branch information
ion098 committed Jun 25, 2024
1 parent 846ba1a commit 734183b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
4 changes: 1 addition & 3 deletions include/gamepad/drive_curve.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class ExpoDriveCurve : public DriveCurve {
* see https://www.desmos.com/calculator/umicbymbnl for an interactive graph
* see https://www.vexforum.com/t/expo-drive-lemlibs-implementation for a detailed explanation
*
* @param deadband range where input is considered to be input
* @param minOutput the minimum output that can be returned
* @param curve how "curved" the graph is
*
Expand All @@ -48,7 +47,7 @@ class ExpoDriveCurve : public DriveCurve {
* lemlib::ExpoDriveCurve driveCurve(5, 12, 1.132);
* @endcode
*/
ExpoDriveCurve(float deadband, float minOutput, float curve);
ExpoDriveCurve(float minOutput, float curve);
/**
* @brief curve an input
*
Expand All @@ -70,7 +69,6 @@ class ExpoDriveCurve : public DriveCurve {
*/
float curve(float input);
private:
const float deadband = 0;
const float minOutput = 0;
const float curveGain = 1;
};
Expand Down
13 changes: 3 additions & 10 deletions src/gamepad/drive_curve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,15 @@
#include <cmath>

namespace Gamepad {
ExpoDriveCurve::ExpoDriveCurve(float deadband, float minOutput, float curve)
: deadband(deadband),
ExpoDriveCurve::ExpoDriveCurve(float minOutput, float curve) :
minOutput(minOutput),
curveGain(curve) {}

float ExpoDriveCurve::curve(float input) {
// return 0 if input is within deadzone
if (std::abs(input) <= deadband) return 0;
// g is the output of g(x) as defined in the Desmos graph
const float g = std::abs(input) - deadband;
// g127 is the output of g(127) as defined in the Desmos graph
const float g127 = 127 - deadband;
const float g = std::abs(input);
// i is the output of i(x) as defined in the Desmos graph
const float i = std::copysign(std::pow(curveGain, g - 127) * g, input);
// i127 is the output of i(127) as defined in the Desmos graph
const float i127 = std::pow(curveGain, g127 - 127) * g127;
return (127.0 - minOutput) / (127) * i * 127 / i127 + std::copysign(minOutput, input);
return (127.0 - minOutput) / (127) * i + std::copysign(minOutput, input);
}
} // namespace Gamepad

0 comments on commit 734183b

Please sign in to comment.