-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Intake & Indexer IO and subsystem
- Loading branch information
Showing
6 changed files
with
142 additions
and
43 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
30 changes: 30 additions & 0 deletions
30
src/main/java/org/team1540/robot2024/commands/indexer/IntakeCommand.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,30 @@ | ||
package org.team1540.robot2024.commands.indexer; | ||
|
||
import edu.wpi.first.wpilibj2.command.Command; | ||
import org.team1540.robot2024.subsystems.indexer.Indexer; | ||
|
||
public class IntakeCommand extends Command { | ||
|
||
private final Indexer indexer; | ||
|
||
public IntakeCommand(Indexer indexer) { | ||
this.indexer = indexer; | ||
addRequirements(indexer); | ||
} | ||
|
||
@Override | ||
public void initialize() { | ||
indexer.setIntakePercent(0.4); | ||
} | ||
|
||
|
||
@Override | ||
public boolean isFinished() { | ||
return indexer.noteInIndexer(); | ||
} | ||
|
||
@Override | ||
public void end(boolean interrupted) { | ||
indexer.setIntakePercent(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
34 changes: 0 additions & 34 deletions
34
src/main/java/org/team1540/robot2024/subsystems/indexer/IndexerIOReal.java
This file was deleted.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
src/main/java/org/team1540/robot2024/subsystems/indexer/IndexerIOSparkMax.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,74 @@ | ||
package org.team1540.robot2024.subsystems.indexer; | ||
|
||
import com.revrobotics.*; | ||
import edu.wpi.first.math.controller.SimpleMotorFeedforward; | ||
import edu.wpi.first.math.util.Units; | ||
import edu.wpi.first.wpilibj.DigitalInput; | ||
|
||
import static org.team1540.robot2024.Constants.Indexer.*; | ||
|
||
|
||
public class IndexerIOSparkMax implements IndexerIO { | ||
private final CANSparkMax intakeMotor = new CANSparkMax(INTAKE_ID, CANSparkLowLevel.MotorType.kBrushless); | ||
private final CANSparkMax feederMotor = new CANSparkMax(FEEDER_ID, CANSparkLowLevel.MotorType.kBrushless); | ||
DigitalInput indexerBeamBreak = new DigitalInput(0); | ||
private final SparkPIDController feederPID; | ||
private final SimpleMotorFeedforward feederFF = new SimpleMotorFeedforward(FEEDER_KS, FEEDER_KV); | ||
|
||
|
||
public IndexerIOSparkMax() { | ||
intakeMotor.setIdleMode(CANSparkBase.IdleMode.kBrake); | ||
intakeMotor.enableVoltageCompensation(12.0); | ||
intakeMotor.setSmartCurrentLimit(30); | ||
|
||
feederMotor.setIdleMode(CANSparkBase.IdleMode.kBrake); | ||
feederMotor.enableVoltageCompensation(12.0); | ||
feederMotor.setSmartCurrentLimit(30); | ||
|
||
feederPID = feederMotor.getPIDController(); | ||
feederPID.setP(FEEDER_KP, 0); | ||
feederPID.setI(FEEDER_KI, 0); | ||
feederPID.setD(FEEDER_KD, 0); | ||
|
||
|
||
|
||
} | ||
// 2 jobs, | ||
// 1. be able to route to tramp | ||
// 2. feeding the shooter (by default, be still, spin up fast 4 for shooter. | ||
// make cmd factory spin | ||
// slower in other direction for tramp | ||
|
||
@Override | ||
public void updateInputs(IndexerIOInputs inputs) { | ||
inputs.intakeCurrent = intakeMotor.getOutputCurrent(); | ||
inputs.intakeVoltage = intakeMotor.getBusVoltage() * intakeMotor.getAppliedOutput(); | ||
inputs.intakeVelocityRPM = intakeMotor.getEncoder().getVelocity(); | ||
inputs.feederVoltage = feederMotor.getOutputCurrent(); | ||
inputs.feederCurrentAmps = feederMotor.getBusVoltage() * feederMotor.getAppliedOutput(); | ||
inputs.feederVelocityRPM = feederMotor.getEncoder().getVelocity(); | ||
inputs.noteInIntake = indexerBeamBreak.get(); | ||
} | ||
|
||
@Override | ||
public void setIntakeVoltage(double volts) { | ||
intakeMotor.setVoltage(volts); | ||
} | ||
|
||
@Override | ||
public void setFeederVoltage(double volts) { | ||
feederMotor.setVoltage(volts); | ||
} | ||
|
||
@Override | ||
public void setFeederVelocity(double velocity) { | ||
feederPID.setReference( | ||
Units.radiansPerSecondToRotationsPerMinute(velocity) * GEAR_RATIO, | ||
CANSparkBase.ControlType.kVelocity, | ||
0, | ||
feederFF.calculate(velocity), | ||
SparkPIDController.ArbFFUnits.kVoltage | ||
); | ||
} | ||
} | ||
// for elevator sim, app. voltage |