mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[wpimath] Add optimize() to SwerveModuleState (#3065)
Co-authored-by: Tyler Veness <calcmogul@gmail.com>
This commit is contained in:
@@ -79,9 +79,13 @@ public class SwerveModule {
|
||||
/**
|
||||
* Sets the desired state for the module.
|
||||
*
|
||||
* @param state Desired state with speed and angle.
|
||||
* @param desiredState Desired state with speed and angle.
|
||||
*/
|
||||
public void setDesiredState(SwerveModuleState state) {
|
||||
public void setDesiredState(SwerveModuleState desiredState) {
|
||||
// Optimize the reference state to avoid spinning further than 90 degrees
|
||||
SwerveModuleState state =
|
||||
SwerveModuleState.optimize(desiredState, new Rotation2d(m_turningEncoder.get()));
|
||||
|
||||
// Calculate the drive output from the drive PID controller.
|
||||
final double driveOutput =
|
||||
m_drivePIDController.calculate(m_driveEncoder.getRate(), state.speedMetersPerSecond);
|
||||
|
||||
@@ -87,11 +87,15 @@ public class SwerveModule {
|
||||
/**
|
||||
* Sets the desired state for the module.
|
||||
*
|
||||
* @param state Desired state with speed and angle.
|
||||
* @param desiredState Desired state with speed and angle.
|
||||
*/
|
||||
public void setDesiredState(SwerveModuleState state) {
|
||||
public void setDesiredState(SwerveModuleState desiredState) {
|
||||
// Optimize the reference state to avoid spinning further than 90 degrees
|
||||
SwerveModuleState state =
|
||||
SwerveModuleState.optimize(desiredState, new Rotation2d(m_turningEncoder.get()));
|
||||
|
||||
// Calculate the drive output from the drive PID controller.
|
||||
final var driveOutput =
|
||||
final double driveOutput =
|
||||
m_drivePIDController.calculate(m_driveEncoder.getRate(), state.speedMetersPerSecond);
|
||||
|
||||
// Calculate the turning motor output from the turning PID controller.
|
||||
|
||||
@@ -79,9 +79,13 @@ public class SwerveModule {
|
||||
/**
|
||||
* Sets the desired state for the module.
|
||||
*
|
||||
* @param state Desired state with speed and angle.
|
||||
* @param desiredState Desired state with speed and angle.
|
||||
*/
|
||||
public void setDesiredState(SwerveModuleState state) {
|
||||
public void setDesiredState(SwerveModuleState desiredState) {
|
||||
// Optimize the reference state to avoid spinning further than 90 degrees
|
||||
SwerveModuleState state =
|
||||
SwerveModuleState.optimize(desiredState, new Rotation2d(m_turningEncoder.get()));
|
||||
|
||||
// Calculate the drive output from the drive PID controller.
|
||||
final double driveOutput =
|
||||
m_drivePIDController.calculate(m_driveEncoder.getRate(), state.speedMetersPerSecond);
|
||||
|
||||
Reference in New Issue
Block a user