Skip to content

Commit d97a749

Browse files
authored
[wpimath] SwerveDrivePoseEstimator: Fix stationary module emitting error when calculating angle in ToSwerveModuleStates (#7175)
1 parent 2085ab3 commit d97a749

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

wpimath/src/main/java/edu/wpi/first/math/kinematics/SwerveDriveKinematics.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public SwerveModuleState[] toSwerveModuleStates(
167167
double y = moduleStatesMatrix.get(i * 2 + 1, 0);
168168

169169
double speed = Math.hypot(x, y);
170-
Rotation2d angle = new Rotation2d(x, y);
170+
Rotation2d angle = speed > 1e-6 ? new Rotation2d(x, y) : m_moduleHeadings[i];
171171

172172
moduleStates[i] = new SwerveModuleState(speed, angle);
173173
m_moduleHeadings[i] = angle;

wpimath/src/main/native/include/frc/kinematics/SwerveDriveKinematics.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ SwerveDriveKinematics<NumModules>::ToSwerveModuleStates(
6666
units::meters_per_second_t y{moduleStateMatrix(i * 2 + 1, 0)};
6767

6868
auto speed = units::math::hypot(x, y);
69-
Rotation2d rotation{x.value(), y.value()};
69+
auto rotation = speed > 1e-6_mps ? Rotation2d{x.value(), y.value()}
70+
: m_moduleHeadings[i];
7071

7172
moduleStates[i] = {speed, rotation};
7273
m_moduleHeadings[i] = rotation;

0 commit comments

Comments
 (0)