Class StickShaping
java.lang.Object
com.crossbotics.ftchelper.gamepad.StickShaping
Helpers that make sticks and triggers feel good to drive with.
double forward = StickShaping.shape(-gamepad1.left_stick_y, 0.05, 2);
double speed = StickShaping.slowScale(gamepad1.left_trigger, 0.25);
drive.drive(forward, strafe, turn, speed);
The minus sign on left_stick_y is needed because the SDK gives a negative number
when you push the stick UP (away from you). See docs/conventions.md.
Docs: docs/modules/gamepad.md
-
Method Summary
Modifier and TypeMethodDescriptionstatic doublecurve(double value, double exponent) Bends the stick response so small moves give fine control and a full push still gives full power.static doubleshape(double value, double deadband, double exponent) Deadband (with a smooth start) and then a curve.static doubleslowScale(double trigger, double slowest) Turns a trigger into a speed multiplier: not pressed = full speed, fully pressed = slowest.
-
Method Details
-
curve
public static double curve(double value, double exponent) Bends the stick response so small moves give fine control and a full push still gives full power. The sign is kept.Exponent 1 = straight line (no change). Exponent 2 = "squared": half stick gives 1/4 power. Exponent 3 = even softer in the middle.
- Parameters:
value- stick value, -1 to 1exponent- 1 or more (values below 1 are treated as 1)- Returns:
- the curved value, -1 to 1
-
shape
public static double shape(double value, double deadband, double exponent) Deadband (with a smooth start) and then a curve. The usual one-line stick setup.A "deadband" (dead zone) ignores tiny stick values near the middle. Sticks rarely rest at exactly 0, and without a dead zone the robot would creep when nobody touches the stick. "Smooth start" means the power starts from 0 at the edge of the dead zone instead of jumping.
- Parameters:
value- stick value, -1 to 1deadband- dead zone, e.g. 0.05exponent- curve, e.g. 1 (none) or 2 (squared)- Returns:
- the shaped value, -1 to 1
-
slowScale
public static double slowScale(double trigger, double slowest) Turns a trigger into a speed multiplier: not pressed = full speed, fully pressed = slowest. This is last season's "trigger brake".Example with slowest 0.25: trigger 0 gives 1.0; trigger 1 gives 0.25; trigger 0.5 gives 0.625.
- Parameters:
trigger- the trigger value, 0 to 1slowest- the multiplier at full press, 0 to 1- Returns:
- the speed multiplier, from
slowestto 1
-