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: left / 2, setLeft: true),
      DriveCommand(right: right / 2, setRight: true),
      DriveCommand(throttle: throttle, setThrottle: true),
    ];
  }
  final direction = state.normalLeftX * 20;  // [-1, 1] --> [-45, 45]
  final (double left, double right) = getWheelSpeeds(speed, direction);
  return [
    DriveCommand(left: speed * left, setLeft: true),
    DriveCommand(right: speed * right, setRight: true),
    DriveCommand(throttle: throttle, setThrottle: true),
  ];
}