Added output normalization to DifferentialDrive::CurvatureDrive() (#924)

This normalizes within -1..1 to avoid clipping and maintain the ratio between
wheel speeds, since that ratio determines the center of rotation.

Fixes #923.
This commit is contained in:
Tyler Veness
2018-02-01 21:17:04 -08:00
committed by Peter Johnson
parent 5ca00dddbe
commit 64a7e57fe0
2 changed files with 16 additions and 0 deletions

View File

@@ -261,6 +261,13 @@ public class DifferentialDrive extends RobotDriveBase {
}
}
// Normalize the wheel speeds
double maxMagnitude = Math.max(Math.abs(leftMotorOutput), Math.abs(rightMotorOutput));
if (maxMagnitude > 1.0) {
leftMotorOutput /= maxMagnitude;
rightMotorOutput /= maxMagnitude;
}
m_leftMotor.set(leftMotorOutput * m_maxOutput);
m_rightMotor.set(-rightMotorOutput * m_maxOutput);