Repository navigation
Flywheels #4
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
Flywheels #4
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5367673
subsystem code done, need to do controls
Jetblackdragon 67b3dc6
controls complete
cwkpete7383 c336350
Merge branch 'main' of https://github.com/robototes/Everybot2026 into…
cwkpete7383 34da4bc
forgot to commit earlier
cwkpete7383 9fd7f64
fix issues 1
cwkpete7383 e4aa1d3
Merge branch 'flywheels' of https://github.com/robototes/Everybot2026…
cwkpete7383 8ce4ee1
a
cwkpete7383 ac002ce
fix issues 2
cwkpete7383 1bac873
Merge branch 'main' of https://github.com/robototes/Everybot2026 into…
cwkpete7383 9e7a02e
spotless applied
cwkpete7383 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| package frc.robot; | ||
|
|
||
| import com.ctre.phoenix6.configs.TalonFXConfiguration; | ||
| import com.ctre.phoenix6.controls.Follower; | ||
| import com.ctre.phoenix6.controls.MotionMagicVelocityVoltage; | ||
| import com.ctre.phoenix6.hardware.TalonFX; | ||
| import com.ctre.phoenix6.signals.InvertedValue; | ||
| import com.ctre.phoenix6.signals.MotorAlignmentValue; | ||
| import com.ctre.phoenix6.signals.NeutralModeValue; | ||
| import edu.wpi.first.wpilibj2.command.Command; | ||
| import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
| import java.util.function.DoubleSupplier; | ||
|
|
||
| public class Flywheels extends SubsystemBase { | ||
| private final TalonFX flywheelOne; | ||
| private final TalonFX flywheelTwo; | ||
|
|
||
| public static double speed = 1; // placeholder | ||
|
|
||
| // Configs: PIDS and limits | ||
| double kP = 0.0; | ||
| double kI = 0.0; | ||
| double kD = 0.0; | ||
| double kA = 0.0; | ||
| double kV = 0.0; | ||
| double kS = 0.0; | ||
| double kG = 0.0; | ||
|
|
||
| private static final int supplyCurrentLimit = 20; | ||
| private static final int statorCurrentLimit = 40; | ||
| private static final boolean supplyCurrentLimitEnable = true; | ||
| private static final boolean statorCurrentLimitEnable = true; | ||
| private static final int motionMagicAcceleration = 40; | ||
| private final MotionMagicVelocityVoltage request = new MotionMagicVelocityVoltage(0); | ||
| private final Follower follow = | ||
| new Follower(Hardware.FLYWHEEL_ONE_ID, MotorAlignmentValue.Opposed); | ||
| public final double FLYWHEEL_TOLERANCE = 5; // TODO: Tune tolerance as well | ||
|
cwkpete7383 marked this conversation as resolved.
Resolved
|
||
|
|
||
| public Flywheels() { | ||
| flywheelOne = new TalonFX(Hardware.FLYWHEEL_ONE_ID); | ||
| flywheelTwo = new TalonFX(Hardware.FLYWHEEL_TWO_ID); | ||
|
|
||
| configureMotors(); | ||
| } | ||
|
|
||
| private void configureMotors() { | ||
| TalonFXConfiguration config = new TalonFXConfiguration(); | ||
|
|
||
| // TODO: tune configs and PIDS, currently placeholder | ||
| config.CurrentLimits.SupplyCurrentLimit = supplyCurrentLimit; | ||
| config.CurrentLimits.StatorCurrentLimit = statorCurrentLimit; | ||
| config.CurrentLimits.SupplyCurrentLimitEnable = supplyCurrentLimitEnable; | ||
| config.CurrentLimits.StatorCurrentLimitEnable = statorCurrentLimitEnable; | ||
|
|
||
| config.MotorOutput.NeutralMode = NeutralModeValue.Coast; | ||
| config.MotorOutput.Inverted = InvertedValue.Clockwise_Positive; | ||
|
|
||
| config.Slot0.kP = kP; | ||
| config.Slot0.kI = kI; | ||
| config.Slot0.kD = kD; | ||
| config.Slot0.kA = kA; | ||
| config.Slot0.kV = kV; | ||
| config.Slot0.kS = kS; | ||
| config.Slot0.kG = kG; | ||
|
|
||
| config.MotionMagic.MotionMagicAcceleration = motionMagicAcceleration; // RPS^2 | ||
|
|
||
| flywheelOne.getConfigurator().apply(config); | ||
| flywheelTwo.getConfigurator().apply(config); | ||
| } | ||
|
|
||
| public Command runFlywheels() { | ||
|
markpete marked this conversation as resolved.
Resolved
|
||
| return startEnd( | ||
| () -> { | ||
| setFlywheelVelocity(speed); | ||
| }, | ||
| () -> { | ||
| stopCommand(); | ||
| }) | ||
| .withName("Run flywheels"); | ||
| } | ||
|
|
||
| private void setFlywheelVelocity(double rps) { | ||
| request.Velocity = rps; | ||
| flywheelOne.setControl(request); | ||
| flywheelTwo.setControl(follow); | ||
| } | ||
|
|
||
| public Command suppliedSetVelocity(DoubleSupplier rps) { | ||
| return startEnd( | ||
| () -> { | ||
| request.Velocity = rps.getAsDouble(); | ||
| flywheelOne.setControl(request); | ||
| flywheelTwo.setControl(follow); | ||
| }, | ||
| () -> { | ||
| stopCommand(); | ||
| }) | ||
| .withName("Supplied velocity command"); | ||
| } | ||
|
|
||
| public boolean isAtSpeed() { | ||
| return Math.abs(flywheelOne.getVelocity().getValueAsDouble() - request.Velocity) | ||
| <= FLYWHEEL_TOLERANCE; | ||
| } | ||
|
|
||
| private void stopCommand() { | ||
| flywheelOne.stopMotor(); | ||
| } | ||
| } | ||
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.
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.