-
Notifications
You must be signed in to change notification settings - Fork 0
Indexer #12
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
Open
Wow-Jr
wants to merge
12
commits into
main
Choose a base branch
from
indexer
base: main
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.
Open
Indexer #12
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
204c13c
dsljfs
Wow-Jr dc5934a
w rizz fixes
Wow-Jr 46bb9fd
L rizz fixes
Wow-Jr b1cee63
mid rizz fixes
Wow-Jr f38a11d
Merge remote-tracking branch 'origin/main' into indexer
Wow-Jr 6a1ec2c
Merging 2025 to 2026 wpi
Wow-Jr 4eff110
importing changes + updating laser
Wow-Jr 32778f3
arvindChanges™
Wow-Jr 7bc9d59
adding getInstance method, prototype for sensing
Wow-Jr 04116aa
Add controller to indexer (#16)
Quantalabs 25661e3
git
Wow-Jr 12740a1
Fixed indexer
github-0-0 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
179 changes: 179 additions & 0 deletions
179
src/main/java/frc/robot/subsystems/indexer/Indexer.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,179 @@ | ||
| package frc.robot.subsystems.indexer; | ||
|
|
||
| import static frc.robot.subsystems.indexer.IndexerConstants.*; | ||
| import com.ctre.phoenix6.controls.ControlRequest; | ||
| import com.ctre.phoenix6.controls.VelocityVoltage; | ||
| import com.ctre.phoenix6.hardware.TalonFX; | ||
| import com.ctre.phoenix6.sim.TalonFXSimState; | ||
|
|
||
| import edu.wpi.first.util.sendable.SendableBuilder; | ||
| import edu.wpi.first.wpilibj2.command.Command; | ||
| import edu.wpi.first.wpilibj2.command.Commands; | ||
| import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
| import frc.robot.subsystems.TelemetryManager; | ||
| import au.grapplerobotics.LaserCan; | ||
| import au.grapplerobotics.ConfigurationFailedException; | ||
|
|
||
| // TODO (ethan): only activate if shooter ready | ||
| // TODO (ethan): ask tommy setControl(request) | ||
| public class Indexer extends SubsystemBase { | ||
| /** getInstance of indexer */ | ||
| private static Indexer leftInstance; | ||
| public static Indexer getLeftInstance() { | ||
| if (leftInstance == null) { | ||
| leftInstance = new Indexer(true); | ||
| } | ||
| return leftInstance; | ||
| } | ||
| private static Indexer rightInstance; | ||
| public static Indexer getrightInstance() { | ||
| if (rightInstance == null) { | ||
| rightInstance = new Indexer(false); | ||
| } | ||
| return rightInstance; | ||
| } | ||
| private ControlRequest request; | ||
|
|
||
| private TalonFX motor; | ||
| private TalonFXSimState motorSim; | ||
| private LaserCan lc; | ||
|
|
||
| /** boolean that's modified by checkForBall() */ | ||
| private boolean hasBall; | ||
|
|
||
| // private boolean shooterReady = false; | ||
| // COMMENTED OUT /** boolean that's modified by checkForBallTwo() */ | ||
| // private boolean hasBallTwo; | ||
|
|
||
| /** boolean that's modified by shooter */ | ||
|
|
||
| /** setup, adding motor and laser */ | ||
| private Indexer(boolean isLeft) { | ||
| super(); | ||
| setName("Indexer " + (isLeft ? "Left" : "Right")); | ||
| motor = new TalonFX(isLeft ? L_MOTOR_ID : R_MOTOR_ID); | ||
| motor.getConfigurator().apply(getConfig()); | ||
| motorSim = motor.getSimState(); | ||
| lc = new LaserCan(isLeft ? L_LASER_ID : R_LASER_ID); | ||
| // lcTwo = new LaserCan(LASER_ID_2); | ||
|
|
||
| /* new laser configs */ | ||
| for (int i = 0; i < 20; i++) { | ||
| try { | ||
| lc.setRangingMode(LaserCan.RangingMode.SHORT); | ||
| lc.setRegionOfInterest(new LaserCan.RegionOfInterest(8, 8, 16, 16)); | ||
| lc.setTimingBudget(LaserCan.TimingBudget.TIMING_BUDGET_33MS); | ||
| break; | ||
| } catch (ConfigurationFailedException e) { | ||
| System.out.println("Configuration failed! " + e); | ||
| } | ||
| } | ||
| // try { | ||
| // lcTwo.setRangingMode(LaserCan.RangingMode.SHORT); | ||
| // lcTwo.setRegionOfInterest(new LaserCan.RegionOfInterest(8, 8, 16, 16)); | ||
| // lcTwo.setTimingBudget(LaserCan.TimingBudget.TIMING_BUDGET_33MS); | ||
| // } catch (ConfigurationFailedException e) { | ||
| // System.out.println("Configuration failed! " + e); | ||
| // } | ||
| setDefaultCommand(loadIndexer()); | ||
| } | ||
|
|
||
| @Override | ||
| /* check for balls and makes sure motor is constantly running at desired speed */ | ||
| public void periodic() { | ||
| motor.setControl(request); | ||
|
|
||
| checkForBall(); | ||
| // checkForBallTwo(); | ||
| // if (shooterReady == true) { | ||
| // activateIndexer(); | ||
| // } | ||
| } | ||
|
|
||
| @Override | ||
| public void simulationPeriodic() { | ||
|
|
||
| } | ||
|
|
||
| /** type conversion/abstraction */ | ||
| public void setRequest(ControlRequest request) { | ||
| this.request = request; | ||
| } | ||
|
|
||
| /** sets speed (duh) */ | ||
| public Command setSpeed(double speed) { | ||
| return runOnce(() -> setRequest(new VelocityVoltage(speed))); | ||
| } | ||
|
|
||
| /** moves motor to speed if sense ball */ | ||
| public Command loadIndexer() { | ||
| return Commands.either( | ||
| deactivateIndexer(), | ||
| activateIndexer(), | ||
| this::hasBall | ||
| ).repeatedly(); | ||
| } | ||
|
|
||
| public Command activateIndexer() { | ||
| return setSpeed(ROLLING_SPEED); | ||
| } | ||
|
|
||
| /** turn motor down to zero */ | ||
| public Command deactivateIndexer() { | ||
| return setSpeed(0); | ||
| } | ||
|
|
||
| /** command to sense distance from LaserCAN; used to sense if bol */ | ||
| private double getDistanceMm() { | ||
| LaserCan.Measurement measurement = lc.getMeasurement(); | ||
| if (measurement != null && measurement.status == LaserCan.LASERCAN_STATUS_VALID_MEASUREMENT) { | ||
| return measurement.distance_mm; | ||
| } else { | ||
| return Double.POSITIVE_INFINITY; | ||
| } | ||
| } | ||
|
|
||
| /** command that modifies hasBall, uses getDistanceMm() */ | ||
| private void checkForBall() { | ||
| double x = getDistanceMm(); | ||
| if (x <= MAXIMUM_LASER_DIST) { | ||
| hasBall = false; | ||
| } | ||
| } | ||
|
|
||
| /** setup formatting for boolean hasBall so it can be used in activateIndexer().either */ | ||
| private boolean hasBall() { | ||
| return hasBall; | ||
| } | ||
| // COMMENTED OUT /** setup formatting for boolean hasBall so that it can be used to tell if shooter ready */ | ||
| // private boolean hasBallTwo() { | ||
| // return hasBallTwo; | ||
| // } | ||
| // COMMENTED OUT /** command to sense if bol going into shooter */ | ||
| // private double getDistanceMmTwo() { | ||
| // LaserCan.Measurement measurement = lc.getMeasurement(); | ||
| // if (measurement != null && measurement.status == LaserCan.LASERCAN_STATUS_VALID_MEASUREMENT) { | ||
| // return measurement.distance_mm; | ||
| // } else { | ||
| // return -1; | ||
| // } | ||
| // } | ||
| // COMMENTED OUT //** command that checks if bol is boutta be shot */ | ||
| // private void checkForBallTwo() { | ||
| // double x = getDistanceMmTwo(); | ||
| // if (x >= LaserCan_DefaultMeasurement) { | ||
| // hasBallTwo = false; | ||
| // } else if (x != -1) { /* (x != -1) is checking that the camera isn't just returning an error as ball sensed */ | ||
| // hasBallTwo = true; | ||
| // } | ||
| // } | ||
|
|
||
| // TODO: AdvantageKit! | ||
| /** ????????? */ | ||
| @Override | ||
| public void initSendable(SendableBuilder builder) { | ||
| super.initSendable(builder); | ||
| builder.addBooleanProperty("Has Ball", () -> hasBall, null); | ||
| TelemetryManager.makeSendableTalonFX("Indexer Motor", motor, builder); | ||
| } | ||
| } | ||
38 changes: 38 additions & 0 deletions
38
src/main/java/frc/robot/subsystems/indexer/IndexerConstants.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,38 @@ | ||
| package frc.robot.subsystems.indexer; | ||
|
|
||
| import com.ctre.phoenix6.configs.CurrentLimitsConfigs; | ||
| import com.ctre.phoenix6.configs.Slot0Configs; | ||
| import com.ctre.phoenix6.configs.TalonFXConfiguration; | ||
| import com.ctre.phoenix6.configs.VoltageConfigs; | ||
|
|
||
| public class IndexerConstants { | ||
|
|
||
| // TODO: Set IDs | ||
| // TODO (Ethan): Set LaserCan_DefaultMeasurement | ||
| public static final int L_MOTOR_ID = 32; | ||
| public static final int L_LASER_ID = 36; | ||
| public static final int R_MOTOR_ID = 32; | ||
| public static final int R_LASER_ID = 36; | ||
| // public static final int LASER_ID_2 = 0; | ||
| public static final double ROLLING_SPEED = 10; // rps | ||
| public static final double MAXIMUM_LASER_DIST = 100; | ||
|
|
||
|
|
||
| public static TalonFXConfiguration getConfig() { | ||
| return new TalonFXConfiguration() | ||
| .withSlot0(new Slot0Configs() | ||
| .withKV(0.0) | ||
| .withKP(0.3) | ||
| .withKI(0.001) | ||
| .withKD(0.0) | ||
| .withKA(0.1) | ||
| .withKS(0.1) | ||
| .withKV(0.1)) // placeholder values | ||
| .withCurrentLimits(new CurrentLimitsConfigs() | ||
| .withStatorCurrentLimit(40) | ||
| .withSupplyCurrentLimit(40)) | ||
| .withVoltage(new VoltageConfigs() | ||
| .withPeakForwardVoltage(12.0) | ||
| .withPeakReverseVoltage(-12.0)); | ||
| } | ||
| } |
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.