Skip to content

Commit

Permalink
Fixed opposites error caused by .optimize()
Browse files Browse the repository at this point in the history
  • Loading branch information
MrTinker64 committed Sep 18, 2023
1 parent e788747 commit 894323a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ public SwerveModulePosition getPosition() {

@Override
public void setDesiredState(SwerveModuleState state) {
m_driveMotor.set(state.speedMetersPerSecond / DriveConstants.kPhysicalMaxSpeedMetersPerSecond);
state = SwerveModuleState.optimize(state, getState().angle);
double desiredTurnSpeed = turningPidController.calculate(getTurningPosition(), state.angle.getRadians());
m_turningMotor.set(desiredTurnSpeed);
m_driveMotor.set(state.speedMetersPerSecond / DriveConstants.kPhysicalMaxSpeedMetersPerSecond);

desiredState = state;
SmartDashboard.putString("Swerve[" + m_absoluteEncoder.getChannel() + "] state", state.toString());
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/RealSwerveModuleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ void setDesiredStateTemplate(double speed, double angle) {
SwerveModuleState expectedState = new SwerveModuleState(speed, new Rotation2d(angleInRadians));
// Act
subsystem.setDesiredState(expectedState);
// Assert Sets the drive speed to be proportional to the max speed
verify(mockDriveMotor).set(expectedState.speedMetersPerSecond / DriveConstants.kPhysicalMaxSpeedMetersPerSecond);
// Assert
expectedState = SwerveModuleState.optimize(expectedState, subsystem.getState().angle);
verify(mockDriveMotor).set(expectedState.speedMetersPerSecond / DriveConstants.kPhysicalMaxSpeedMetersPerSecond); // Sets the drive speed to be proportional to the max speed
// Verifies that the speed of the turning motor is appropriate given optimization
ArgumentCaptor<Double> argumentCaptor = ArgumentCaptor.forClass(Double.class);
verify(mockTurningMotor).set(argumentCaptor.capture());
Expand Down

0 comments on commit 894323a

Please sign in to comment.