getWheelSpeeds method

(double, double) getWheelSpeeds(
  1. double speed,
  2. double direction
)

Gets the speeds of the wheels based on the speed and direction.

Implementation

(double, double) getWheelSpeeds(double speed, double direction) {
  const slope = 1 / 90;
  if (direction < -45) {  // trying to turn too far left
    return (-1, 1);
  } else if (direction >= -45 && direction < 45) {  // [-45, 45]
    return (slope * direction + 0.5, slope * direction - 0.5);
  } else {  // trying to turn too far right
    return (1, -1);
  }
}