mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51: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
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "Drive/DifferentialDrive.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
#include <HAL/HAL.h>
|
||||
@@ -171,6 +172,14 @@ void DifferentialDrive::CurvatureDrive(double xSpeed, double zRotation,
|
||||
}
|
||||
}
|
||||
|
||||
// Normalize the wheel speeds
|
||||
double maxMagnitude =
|
||||
std::max(std::abs(leftMotorOutput), std::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