-
Notifications
You must be signed in to change notification settings - Fork 3
shotBlocker in code #258
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
Draft
cwkpete7383
wants to merge
3
commits into
Issue250
Choose a base branch
from
drumBlock
base: Issue250
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
shotBlocker in code #258
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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,114 @@ | ||
| package frc.robot.subsystems; | ||
|
|
||
| import com.ctre.phoenix6.CANBus; | ||
| import com.ctre.phoenix6.configs.TalonFXConfiguration; | ||
| import com.ctre.phoenix6.controls.MotionMagicVoltage; | ||
| import com.ctre.phoenix6.hardware.TalonFX; | ||
| import com.ctre.phoenix6.signals.InvertedValue; | ||
| import com.ctre.phoenix6.signals.NeutralModeValue; | ||
| import edu.wpi.first.math.util.Units; | ||
| import edu.wpi.first.wpilibj2.command.Command; | ||
| import edu.wpi.first.wpilibj2.command.Commands; | ||
| import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
| import frc.robot.Hardware; | ||
|
|
||
| public class Blocker extends SubsystemBase { | ||
| private final TalonFX blockerMotor; | ||
| private final MotionMagicVoltage request = new MotionMagicVoltage(0); | ||
|
|
||
| // Positions | ||
| private double targetPos; | ||
| public static final double DEPLOYED_POS = 0; | ||
| public static final double RETRACTED_POS = 0; | ||
|
Fatblabs marked this conversation as resolved.
|
||
| private static final double degreeTolerance = 5; | ||
|
|
||
| // PID variables | ||
| private static final double kP = 40; | ||
| private static final double kI = 0; | ||
| private static final double kD = 1; | ||
| private static final double kG = 0.4; | ||
| private static final double kS = 0.2; | ||
| private static final double kV = 0; | ||
| private static final double kA = 0; | ||
|
|
||
| // Current limits | ||
| private static final int STATOR_CURRENT_LIMIT = 60; // amps | ||
| private static final int SUPPLY_CURRENT_LIMIT = 30; // amps | ||
|
|
||
| // Motion Magic Config | ||
| private static final double CRUISE_VELOCITY = 100; | ||
| private static final double ACCELERATION = 400; | ||
| private static final double JERK = 0; | ||
|
|
||
| // Gear Ratio | ||
| private static final double GEAR_RATIO = 35; | ||
|
|
||
| // Soft Limits | ||
| public static final double PIVOT_MIN = -0.45; // rotations | ||
| public static final double PIVOT_MAX = 0.0; | ||
|
|
||
| public Blocker() { | ||
| blockerMotor = new TalonFX(Hardware.BLOCKER_MOTOR_ID, CANBus.roboRIO()); | ||
| blockerConfig(); | ||
| blockerMotor.clearStickyFaults(); | ||
| } | ||
|
|
||
| public void blockerConfig() { | ||
| TalonFXConfiguration config = new TalonFXConfiguration(); | ||
|
|
||
| config.MotorOutput.Inverted = InvertedValue.Clockwise_Positive; | ||
| config.MotorOutput.NeutralMode = NeutralModeValue.Brake; | ||
| config.Feedback.SensorToMechanismRatio = GEAR_RATIO; | ||
|
|
||
| config.CurrentLimits.StatorCurrentLimit = STATOR_CURRENT_LIMIT; | ||
| config.CurrentLimits.StatorCurrentLimitEnable = true; | ||
| config.CurrentLimits.SupplyCurrentLimit = SUPPLY_CURRENT_LIMIT; | ||
| config.CurrentLimits.SupplyCurrentLimitEnable = true; | ||
|
|
||
| config.SoftwareLimitSwitch.ForwardSoftLimitThreshold = PIVOT_MAX; | ||
| config.SoftwareLimitSwitch.ForwardSoftLimitEnable = true; | ||
| config.SoftwareLimitSwitch.ReverseSoftLimitThreshold = PIVOT_MIN; | ||
| config.SoftwareLimitSwitch.ReverseSoftLimitEnable = true; | ||
|
|
||
| config.MotionMagic.MotionMagicCruiseVelocity = CRUISE_VELOCITY; | ||
| config.MotionMagic.MotionMagicAcceleration = ACCELERATION; | ||
| config.MotionMagic.MotionMagicJerk = JERK; | ||
|
|
||
| config.Slot0.kP = kP; | ||
| config.Slot0.kI = kI; | ||
| config.Slot0.kD = kD; | ||
| config.Slot0.kG = kG; | ||
| config.Slot0.kS = kS; | ||
| config.Slot0.kV = kV; | ||
| config.Slot0.kA = kA; | ||
|
|
||
| blockerMotor.getConfigurator().apply(config); | ||
| } | ||
|
|
||
| public void setPivotPosition(double pos) { | ||
| targetPos = pos; | ||
| blockerMotor.setControl(request.withPosition(pos)); | ||
| } | ||
|
|
||
| public Command blockerInCommand() { | ||
| return Commands.runOnce(() -> setPivotPosition(RETRACTED_POS)); | ||
| } | ||
|
|
||
| public Command blockerOutCommand() { | ||
| return Commands.runOnce(() -> setPivotPosition(DEPLOYED_POS)); | ||
| } | ||
|
Fatblabs marked this conversation as resolved.
|
||
|
|
||
| public Command zeroBlocker() { | ||
| return runOnce( | ||
| () -> { | ||
| blockerMotor.setPosition(RETRACTED_POS); | ||
| targetPos = RETRACTED_POS; | ||
| }) | ||
| .withName("Zero Blocker"); | ||
| } | ||
|
|
||
| public boolean isAtTarget(double pose) { | ||
| return Math.abs(blockerMotor.getPosition().getValueAsDouble() - pose) | ||
| < Units.degreesToRotations(degreeTolerance); | ||
| } | ||
| } | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This trigger binding should be guarded with a null check for s.blocker. If the blocker subsystem is disabled in Subsystems.java, s.blocker will be null, leading to a NullPointerException when blockerOutCommand() or blockerInCommand() is called.