generated from Programming-TRIGON/RobotTemplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Better Controls #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Better Controls #40
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
072677d
Implement double tap controls
Strflightmight09 dd6ce30
Double tap for operator toggle controls
Strflightmight09 4fdc575
Indicate no vision update
Strflightmight09 655f313
Merge branch 'main' into better-controls
Strflightmight09 3e119e4
Hald update bad climb logic
Strflightmight09 16ba74f
Fix climb logic + error + minor logic fix
Strflightmight09 5fd022d
Reorder
Strflightmight09 89fb34d
Made intake assist toggles ignore disable
Strflightmight09 cffe1ee
Finla
Strflightmight09 5706aac
Commit so that CodeRabbit can review 👍
Strflightmight09 b2206b7
Added indicate alliance shift
Strflightmight09 391db9d
Refactor and reset PID controllers
Strflightmight09 09ff687
Merge branch 'main' into better-controls
Strflightmight09 a831a93
Update auton commands with main update + fix logic
Strflightmight09 e8d27be
Update lib
Strflightmight09 7f0b775
Make it so don't go brrr during practice
Strflightmight09 7d114b6
Make last commit better
Strflightmight09 9c19cb4
Fix bug
Strflightmight09 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
108 changes: 108 additions & 0 deletions
108
src/main/java/frc/trigon/robot/commands/commandclasses/ShootingSafeDriveCommand.java
This file contains hidden or 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,108 @@ | ||
| package frc.trigon.robot.commands.commandclasses; | ||
|
|
||
| import edu.wpi.first.math.MathUtil; | ||
| import edu.wpi.first.math.filter.SlewRateLimiter; | ||
| import edu.wpi.first.math.geometry.Rotation2d; | ||
| import edu.wpi.first.math.geometry.Translation2d; | ||
| import edu.wpi.first.wpilibj2.command.Command; | ||
| import edu.wpi.first.wpilibj2.command.InstantCommand; | ||
| import edu.wpi.first.wpilibj2.command.SequentialCommandGroup; | ||
| import frc.trigon.robot.RobotContainer; | ||
| import frc.trigon.robot.constants.FieldConstants; | ||
| import frc.trigon.robot.constants.OperatorConstants; | ||
| import frc.trigon.robot.subsystems.swerve.SwerveCommands; | ||
| import frc.trigon.robot.subsystems.swerve.SwerveConstants; | ||
|
|
||
| /** | ||
| * A command class that limits the swerve powers to ease shooting to the hub and increase accuracy. | ||
| */ | ||
| public class ShootingSafeDriveCommand extends SequentialCommandGroup { | ||
| private static final double | ||
| TRANSLATION_SLEW_RATE = 2, | ||
| MAXIMUM_DRIVE_POWER_TOWARDS_HUB = 3 / SwerveConstants.MAXIMUM_SPEED_METERS_PER_SECOND; | ||
| private static final SlewRateLimiter | ||
| X_SLEW_RATE_LIMITER = new SlewRateLimiter(TRANSLATION_SLEW_RATE), | ||
| Y_SLEW_RATE_LIMITER = new SlewRateLimiter(TRANSLATION_SLEW_RATE), | ||
| ROTATION_SLEW_RATE_LIMITER = new SlewRateLimiter(1); | ||
|
|
||
| public ShootingSafeDriveCommand() { | ||
| addCommands( | ||
| getInitializeCommand(), | ||
| SwerveCommands.getClosedLoopFieldRelativeDriveCommand( | ||
| ShootingSafeDriveCommand::calculateSafeDriveTranslationPower, | ||
| ShootingSafeDriveCommand::calculateSafeDriveRotationPower | ||
| ).asProxy() | ||
| ); | ||
| } | ||
|
|
||
| private static Command getInitializeCommand() { | ||
| return new InstantCommand(() -> { | ||
| X_SLEW_RATE_LIMITER.reset(0); | ||
| Y_SLEW_RATE_LIMITER.reset(0); | ||
| ROTATION_SLEW_RATE_LIMITER.reset(0); | ||
| }); | ||
| } | ||
|
|
||
| private static Translation2d calculateSafeDriveTranslationPower() { | ||
| return limitTranslationPowerToEaseShooting(getSlewRateLimitedTranslationPower()); | ||
| } | ||
|
|
||
| private static double calculateSafeDriveRotationPower() { | ||
| final double rawPower = OperatorConstants.DRIVER_CONTROLLER.getRightX(); | ||
| return ROTATION_SLEW_RATE_LIMITER.calculate(rawPower); | ||
| } | ||
|
|
||
| private static Translation2d getSlewRateLimitedTranslationPower() { | ||
| final double | ||
| rawXPower = OperatorConstants.DRIVER_CONTROLLER.getLeftY(), | ||
| rawYPower = OperatorConstants.DRIVER_CONTROLLER.getLeftX(); | ||
|
|
||
| return new Translation2d( | ||
| X_SLEW_RATE_LIMITER.calculate(rawXPower), | ||
| Y_SLEW_RATE_LIMITER.calculate(rawYPower) | ||
| ); | ||
| } | ||
|
|
||
| private static Translation2d limitTranslationPowerToEaseShooting(Translation2d targetPower) { | ||
| final Rotation2d hubDirection = calculateFieldRelativeAngleToHub().plus(Rotation2d.k180deg); | ||
|
|
||
| final double radialVelocity = calculateRadialVelocityToHub(targetPower, hubDirection); | ||
| final double limitedRadialVelocity = limitRadialVelocity(radialVelocity); | ||
|
|
||
| final Translation2d tangentialComponent = calculateTangentialComponent(targetPower, radialVelocity, hubDirection); | ||
| final Translation2d limitedRadialComponent = calculateRadialComponent(limitedRadialVelocity, hubDirection); | ||
|
|
||
| return tangentialComponent.plus(limitedRadialComponent); | ||
| } | ||
Strflightmight09 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private static double calculateRadialVelocityToHub(Translation2d velocity, Rotation2d hubDirection) { | ||
| return velocity.getX() * hubDirection.getCos() + velocity.getY() * hubDirection.getSin(); | ||
| } | ||
|
|
||
| private static double limitRadialVelocity(double radialVelocity) { | ||
| return MathUtil.clamp( | ||
| radialVelocity, | ||
| -MAXIMUM_DRIVE_POWER_TOWARDS_HUB, | ||
| MAXIMUM_DRIVE_POWER_TOWARDS_HUB | ||
| ); | ||
| } | ||
|
|
||
| private static Translation2d calculateTangentialComponent(Translation2d velocity, double radialVelocity, Rotation2d hubDirection) { | ||
| final Translation2d radialComponent = calculateRadialComponent(radialVelocity, hubDirection); | ||
| return velocity.minus(radialComponent); | ||
| } | ||
|
|
||
| private static Translation2d calculateRadialComponent(double radialVelocity, Rotation2d hubDirection) { | ||
| return new Translation2d( | ||
| radialVelocity * hubDirection.getCos(), | ||
| radialVelocity * hubDirection.getSin() | ||
| ); | ||
| } | ||
|
|
||
| private static Rotation2d calculateFieldRelativeAngleToHub() { | ||
| final Translation2d | ||
| robotPosition = RobotContainer.ROBOT_POSE_ESTIMATOR.getEstimatedRobotPose().getTranslation(), | ||
| hubPosition = FieldConstants.HUB_POSITION.get(); | ||
| return hubPosition.minus(robotPosition).getAngle(); | ||
| } | ||
| } | ||
22 changes: 13 additions & 9 deletions
22
src/main/java/frc/trigon/robot/commands/commandfactories/ClimbCommands.java
This file contains hidden or 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 |
|---|---|---|
| @@ -1,33 +1,37 @@ | ||
| package frc.trigon.robot.commands.commandfactories; | ||
|
|
||
| import edu.wpi.first.wpilibj2.command.*; | ||
| import edu.wpi.first.wpilibj2.command.Command; | ||
| import edu.wpi.first.wpilibj2.command.ConditionalCommand; | ||
| import edu.wpi.first.wpilibj2.command.InstantCommand; | ||
| import edu.wpi.first.wpilibj2.command.SequentialCommandGroup; | ||
| import frc.trigon.robot.constants.OperatorConstants; | ||
| import frc.trigon.robot.subsystems.climber.ClimberCommands; | ||
| import frc.trigon.robot.subsystems.climber.ClimberConstants; | ||
| import org.littletonrobotics.junction.networktables.LoggedNetworkBoolean; | ||
|
|
||
| public class ClimbCommands { | ||
| public static boolean IS_CLIMBING = false; | ||
| public static final LoggedNetworkBoolean IS_CLIMBING = new LoggedNetworkBoolean("IsClimbing", false); | ||
|
|
||
| public static Command getClimbToL1Command() { | ||
| return new SequentialCommandGroup( | ||
| ClimberCommands.getSetTargetStateCommand(ClimberConstants.ClimberState.CLIMB_PREPARE).until(OperatorConstants.CONTINUE_CLIMB_TRIGGER), | ||
| new InstantCommand(() -> IS_CLIMBING = true), | ||
| new InstantCommand(() -> IS_CLIMBING.set(true)), | ||
| ClimberCommands.getSetTargetStateCommand(ClimberConstants.ClimberState.PREPARE_CLIMB).until(OperatorConstants.CONTINUE_CLIMB_TRIGGER), | ||
| ClimberCommands.getSetTargetStateCommand(ClimberConstants.ClimberState.CLIMB_L1) | ||
| ).until(OperatorConstants.CANCEL_CLIMB_TRIGGER); | ||
| } | ||
|
|
||
| public static Command getClimbDownFromL1Command() { | ||
| public static Command getReleaseL1Command() { | ||
| return new SequentialCommandGroup( | ||
| new WaitUntilCommand(OperatorConstants.CANCEL_CLIMB_TRIGGER.negate()), | ||
| ClimberCommands.getSetTargetStateCommand(ClimberConstants.ClimberState.CLIMB_DOWN).until(OperatorConstants.CANCEL_CLIMB_TRIGGER) | ||
| ClimberCommands.getSetTargetStateCommand(ClimberConstants.ClimberState.RELEASE_CLIMB).until(OperatorConstants.CANCEL_CLIMB_TRIGGER.negate()), | ||
| new InstantCommand(() -> IS_CLIMBING.set(false)) | ||
| ); | ||
| } | ||
|
|
||
| public static Command getClimberDefaultCommand() { | ||
| return new ConditionalCommand( | ||
| getClimbDownFromL1Command().andThen(() -> IS_CLIMBING = false), | ||
| getReleaseL1Command(), | ||
| ClimberCommands.getSetTargetStateCommand(ClimberConstants.ClimberState.REST), | ||
| () -> IS_CLIMBING | ||
| IS_CLIMBING::get | ||
| ); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.