-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from aaditsangvikar/main
Updating GradleRIO version and adding NoteVisionRotation
- Loading branch information
Showing
11 changed files
with
123 additions
and
49 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
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
69 changes: 69 additions & 0 deletions
69
src/main/java/frc/robot/commands/RotateToNoteAndDriveCommand.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,69 @@ | ||
package frc.robot.commands; | ||
|
||
import edu.wpi.first.math.controller.ProfiledPIDController; | ||
import edu.wpi.first.wpilibj.GenericHID; | ||
import edu.wpi.first.wpilibj.XboxController; | ||
import edu.wpi.first.wpilibj2.command.Command; | ||
import frc.robot.constants.VisionConstants; | ||
import frc.robot.subsystems.SwerveSubsystem; | ||
import frc.robot.utils.VisionUtils; | ||
import java.util.function.DoubleSupplier; | ||
|
||
public class RotateToNoteAndDriveCommand extends Command { | ||
private SwerveSubsystem swerveSubsystem; | ||
private final DoubleSupplier forward; | ||
private final DoubleSupplier sideways; | ||
private final DoubleSupplier radians; | ||
private final double visionRotation; | ||
|
||
private final ProfiledPIDController rotationPID = new ProfiledPIDController( | ||
VisionConstants.rotateToNoteP, | ||
VisionConstants.rotateToNoteI, | ||
VisionConstants.rotateToNoteD, | ||
VisionConstants.rotateToNoteConstraints | ||
); | ||
|
||
private final XboxController controller; | ||
|
||
public RotateToNoteAndDriveCommand(SwerveSubsystem swerveSubsystem, XboxController controller, DoubleSupplier forward, DoubleSupplier sideways, DoubleSupplier radians) { | ||
this.swerveSubsystem = swerveSubsystem; | ||
this.forward = forward; | ||
this.sideways = sideways; | ||
this.radians = radians; | ||
this.controller = controller; | ||
|
||
rotationPID.setTolerance(0.05); | ||
|
||
this.visionRotation = rotationPID.calculate(VisionUtils.getNoteTX(), 0.0); | ||
|
||
addRequirements(swerveSubsystem); | ||
} | ||
|
||
|
||
@Override | ||
public void execute() { | ||
if (VisionUtils.getNoteTV() == 1.0) { | ||
swerveSubsystem.drive( | ||
forward.getAsDouble(), | ||
sideways.getAsDouble(), | ||
visionRotation, | ||
true, | ||
true | ||
); | ||
} else { | ||
swerveSubsystem.drive( | ||
forward.getAsDouble(), | ||
sideways.getAsDouble(), | ||
radians.getAsDouble(), | ||
true, | ||
true | ||
); | ||
controller.setRumble(GenericHID.RumbleType.kBothRumble, 1.0); | ||
} | ||
} | ||
|
||
@Override | ||
public void end(boolean interrupted) { | ||
controller.setRumble(GenericHID.RumbleType.kBothRumble, 0.0); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.