-
Notifications
You must be signed in to change notification settings - Fork 8
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
Showing
8 changed files
with
124 additions
and
36 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
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,67 @@ | ||
package frc.robot.commands.drive; | ||
|
||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import edu.wpi.first.math.geometry.Translation2d; | ||
import edu.wpi.first.math.kinematics.ChassisSpeeds; | ||
import edu.wpi.first.wpilibj2.command.Command; | ||
import frc.robot.Robot; | ||
import frc.robot.subsystems.drive.HolonomicDriveSubsystem; | ||
import frc.robot.utils.ChassisHeadingController; | ||
import frc.robot.utils.MapleJoystickDriveInput; | ||
import java.util.function.DoubleSupplier; | ||
import org.ironmaple.utils.FieldMirroringUtils; | ||
|
||
public class ClockDrive extends Command { | ||
public static final double ROTATION_AXIS_THRESHOLD = 0.5; | ||
|
||
private final HolonomicDriveSubsystem driveSubsystem; | ||
private final MapleJoystickDriveInput input; | ||
private final DoubleSupplier rotationXSupplier, rotationYSupplier; | ||
|
||
private ChassisSpeeds currentPilotInputSpeeds; | ||
private Rotation2d currentDesiredFacing; | ||
|
||
public ClockDrive( | ||
HolonomicDriveSubsystem driveSubsystem, | ||
MapleJoystickDriveInput input, | ||
DoubleSupplier rotationXSupplier, | ||
DoubleSupplier rotationYSupplier) { | ||
this.driveSubsystem = driveSubsystem; | ||
this.input = input; | ||
this.rotationXSupplier = rotationXSupplier; | ||
this.rotationYSupplier = rotationYSupplier; | ||
|
||
super.addRequirements(driveSubsystem); | ||
} | ||
|
||
@Override | ||
public void initialize() { | ||
currentPilotInputSpeeds = new ChassisSpeeds(); | ||
currentDesiredFacing = driveSubsystem.getFacing(); | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
final ChassisSpeeds newestPilotInputSpeed = input.getJoystickChassisSpeeds( | ||
driveSubsystem.getChassisMaxLinearVelocityMetersPerSec(), | ||
driveSubsystem.getChassisMaxAngularVelocity()); | ||
currentPilotInputSpeeds = driveSubsystem.constrainAcceleration( | ||
currentPilotInputSpeeds, newestPilotInputSpeed, Robot.defaultPeriodSecs); | ||
|
||
Translation2d headingVector = | ||
new Translation2d(rotationXSupplier.getAsDouble(), rotationYSupplier.getAsDouble()); | ||
if (headingVector.getNorm() > ROTATION_AXIS_THRESHOLD) | ||
this.currentDesiredFacing = | ||
headingVector.getAngle().plus(FieldMirroringUtils.getCurrentAllianceDriverStationFacing()); | ||
|
||
ChassisHeadingController.getInstance() | ||
.setHeadingRequest(new ChassisHeadingController.FaceToRotationRequest(this.currentDesiredFacing)); | ||
|
||
driveSubsystem.runDriverStationCentricChassisSpeeds(currentPilotInputSpeeds, true); | ||
} | ||
|
||
@Override | ||
public void end(boolean interrupted) { | ||
ChassisHeadingController.getInstance().setHeadingRequest(new ChassisHeadingController.NullRequest()); | ||
} | ||
} |
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
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
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
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
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
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