mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
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:
committed by
Peter Johnson
parent
5ca00dddbe
commit
64a7e57fe0
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user