getWheelCommands method

List<DriveCommand> getWheelCommands(
  1. GamepadState state
)

Gets all commands for the wheels based on the gamepad state.

Implementation

List<DriveCommand> getWheelCommands(GamepadState state) {
  final speed = state.normalTriggers; // sum of both triggers, [-1, 1]
  if (speed == 0) {
    final left = state.normalLeftX;
    final right = state.normalLeftX;
    return [
      DriveCommand(left: leftLimiter.calculate(left / 2), setLeft: true),
      DriveCommand(right: rightLimiter.calculate(right / 2), setRight: true),
      DriveCommand(throttle: throttleLimiter.calculate(throttle), setThrottle: true),
    ];
  }
  final direction = state.normalLeftX * 20; // [-1, 1] --> [-45, 45]
  final (double left, double right) = getWheelSpeeds(speed, direction);
  return [
    DriveCommand(left: leftLimiter.calculate(speed * left), setLeft: true),
    DriveCommand(right: rightLimiter.calculate(speed * right), setRight: true),
    DriveCommand(throttle: throttleLimiter.calculate(throttle), setThrottle: true),
  ];
}