Class StickShaping

java.lang.Object
com.crossbotics.ftchelper.gamepad.StickShaping

public final class StickShaping extends Object
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 Type
    Method
    Description
    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.
    static double
    shape(double value, double deadband, double exponent)
    Deadband (with a smooth start) and then a curve.
    static double
    slowScale(double trigger, double slowest)
    Turns a trigger into a speed multiplier: not pressed = full speed, fully pressed = slowest.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 1
      exponent - 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 1
      deadband - dead zone, e.g. 0.05
      exponent - 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 1
      slowest - the multiplier at full press, 0 to 1
      Returns:
      the speed multiplier, from slowest to 1