mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[wpilib] Check for signedness in ArcadeDriveIK() (#4028)
If xSpeed == -0.0 and zRotation > 0, the algorithm assumes it's in the third quadrant instead of the first since +0.0 == -0.0. Also added tests for inverse kinematic functions, fixed some MecanumDrive test bugs, and added Java MecanumDrive.driveCartesianIK() and KilloughDrive.driveCartesianIK() overloads with defaulted gyro angle that C++ already had. Fixes #4022.
This commit is contained in:
@@ -112,9 +112,10 @@ DifferentialDrive::WheelSpeeds DifferentialDrive::ArcadeDriveIK(
|
||||
double maxInput =
|
||||
std::copysign(std::max(std::abs(xSpeed), std::abs(zRotation)), xSpeed);
|
||||
|
||||
if (xSpeed >= 0.0) {
|
||||
// Sign is used because `xSpeed >= 0.0` succeeds for -0.0
|
||||
if (!std::signbit(xSpeed)) {
|
||||
// First quadrant, else second quadrant
|
||||
if (zRotation >= 0.0) {
|
||||
if (!std::signbit(zRotation)) {
|
||||
leftSpeed = maxInput;
|
||||
rightSpeed = xSpeed - zRotation;
|
||||
} else {
|
||||
@@ -123,7 +124,7 @@ DifferentialDrive::WheelSpeeds DifferentialDrive::ArcadeDriveIK(
|
||||
}
|
||||
} else {
|
||||
// Third quadrant, else fourth quadrant
|
||||
if (zRotation >= 0.0) {
|
||||
if (!std::signbit(zRotation)) {
|
||||
leftSpeed = xSpeed + zRotation;
|
||||
rightSpeed = maxInput;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user