-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tank drivetrain emulation with swerve modules
- Loading branch information
1 parent
b24457c
commit 2496d15
Showing
2 changed files
with
49 additions
and
2 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
37 changes: 37 additions & 0 deletions
37
src/main/java/frc/robot/subsystems/drivetrain/TankEmulatorSwerveSubsystem.java
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,37 @@ | ||
package frc.robot.subsystems.drivetrain; | ||
|
||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import edu.wpi.first.math.kinematics.SwerveModuleState; | ||
import frc.robot.subsystems.leds.LEDSubsystem; | ||
import frc.robot.vision.PhotonWrapper; | ||
|
||
|
||
|
||
public class TankEmulatorSwerveSubsystem extends SwerveSubsystem{ | ||
|
||
private static final double SPEED_SCALE = .8 / 2; | ||
|
||
public TankEmulatorSwerveSubsystem(PhotonWrapper photonWrapper, LEDSubsystem ledSubsystem){ | ||
super(photonWrapper, ledSubsystem); | ||
} | ||
|
||
/** | ||
* Makes the swerve modules act as a tank drive | ||
* @param forwardPower The forward power of the robot [-1,1] | ||
* @param rotatePower The rotational power of the robot, clockwise positive [-1,1] | ||
*/ | ||
public void setDrivePowers(double forwardPower, double rotatePower){ | ||
|
||
double leftPower = SPEED_SCALE * (forwardPower + rotatePower); | ||
double rightPower = SPEED_SCALE * (forwardPower - rotatePower); | ||
|
||
SwerveModuleState[] states = { | ||
new SwerveModuleState(MAX_VEL * leftPower, new Rotation2d(0)), //TL | ||
new SwerveModuleState(MAX_VEL * rightPower, new Rotation2d(0)), //TR | ||
new SwerveModuleState(MAX_VEL * leftPower, new Rotation2d(0)), //BL | ||
new SwerveModuleState(MAX_VEL * rightPower, new Rotation2d(0)) //BR | ||
}; | ||
|
||
setSwerveModuleStates(states); | ||
} | ||
} |