-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
122c9dd
commit 7f71826
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package frc.robot.commands; | ||
|
||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import edu.wpi.first.math.kinematics.SwerveModuleState; | ||
import edu.wpi.first.wpilibj2.command.CommandBase; | ||
import frc.robot.subsystems.SwerveSubsystem; | ||
|
||
public class DriveStraightCmd extends CommandBase { | ||
private final SwerveSubsystem m_swerveSubsystem; | ||
private final Double rotationDegrees, meters; | ||
private Double initialPosX, initialPosY; | ||
|
||
|
||
public DriveStraightCmd(Double rotationDegrees, Double meters, SwerveSubsystem swerveSubsystem) { | ||
m_swerveSubsystem = swerveSubsystem; | ||
this.rotationDegrees = rotationDegrees; | ||
this.meters = meters; | ||
addRequirements(swerveSubsystem); | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
initialPosX = m_swerveSubsystem.getPose().getX(); | ||
initialPosY = m_swerveSubsystem.getPose().getY(); | ||
SwerveModuleState[] module_states = { | ||
new SwerveModuleState(1.0, Rotation2d.fromDegrees(rotationDegrees)), | ||
new SwerveModuleState(1.0, Rotation2d.fromDegrees(rotationDegrees)), | ||
new SwerveModuleState(1.0, Rotation2d.fromDegrees(rotationDegrees)), | ||
new SwerveModuleState(1.0, Rotation2d.fromDegrees(rotationDegrees)) | ||
}; | ||
m_swerveSubsystem.setModuleStates(module_states); | ||
} | ||
|
||
@Override | ||
public void end(boolean interrupted) { | ||
m_swerveSubsystem.stopModules(); | ||
} | ||
|
||
@Override | ||
public boolean isFinished() { | ||
return Math.sqrt(Math.pow(m_swerveSubsystem.getPose().getX() - initialPosX, 2) + Math.pow(m_swerveSubsystem.getPose().getY() - initialPosY, 2)) >= meters; | ||
} | ||
} |