generated from Frc5572/Java-Template
-
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.
Co-authored-by: Aidan Underwood <[email protected]> Co-authored-by: Alex Resnick <[email protected]>
- Loading branch information
1 parent
0089a79
commit f3eddf0
Showing
5 changed files
with
149 additions
and
3 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package frc.robot.subsystems.intake; | ||
|
||
import org.littletonrobotics.junction.Logger; | ||
import edu.wpi.first.wpilibj2.command.Command; | ||
import edu.wpi.first.wpilibj2.command.Commands; | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
|
||
/** | ||
* Intake Subsystem | ||
*/ | ||
public class Intake extends SubsystemBase { | ||
private IntakeIO io; | ||
private IntakeInputsAutoLogged intakeAutoLogged = new IntakeInputsAutoLogged(); | ||
|
||
public Intake(IntakeIO io) { | ||
this.io = io; | ||
io.updateInputs(intakeAutoLogged); | ||
} | ||
|
||
@Override | ||
public void periodic() { | ||
io.updateInputs(intakeAutoLogged); | ||
Logger.processInputs("Intake", intakeAutoLogged); | ||
} | ||
|
||
public void setIntakeMotor(double percentage) { | ||
Logger.recordOutput("/Intake/Intake Percentage", percentage); | ||
io.setIntakeMotorPercentage(percentage); | ||
} | ||
|
||
public void setIndexerMotor(double percentage) { | ||
Logger.recordOutput("/Intake/Indexer Percentage", percentage); | ||
io.setIndexerMotorPercentage(percentage); | ||
} | ||
|
||
public boolean getSensorStatus() { | ||
return intakeAutoLogged.sensorStatus; | ||
} | ||
|
||
/** | ||
* Command to run the intake motor and indexer until the sensor trips | ||
* | ||
* @return {@link Command} to run the intake and indexer motors | ||
*/ | ||
public Command runIntakeMotor() { | ||
return Commands.startEnd(() -> { | ||
setIntakeMotor(0.5); | ||
setIndexerMotor(0.5); | ||
}, () -> { | ||
setIntakeMotor(0); | ||
setIndexerMotor(0); | ||
}, this).until(() -> getSensorStatus()).unless(() -> getSensorStatus()); | ||
} | ||
} |
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,31 @@ | ||
package frc.robot.subsystems.intake; | ||
|
||
import org.littletonrobotics.junction.AutoLog; | ||
|
||
/** | ||
* Intake IO Interface | ||
*/ | ||
public interface IntakeIO { | ||
|
||
/** | ||
* Intake Inputs to Log | ||
*/ | ||
@AutoLog | ||
public static class IntakeInputs { | ||
public double intakeSupplyVoltage; | ||
public double indexerSupplyVoltage; | ||
public double intakeMotorVoltage; | ||
public double indexerMotorVoltage; | ||
public double intakeAmps; | ||
public double indexerAmps; | ||
public double intakeRPM; | ||
public double indexerRPM; | ||
public boolean sensorStatus; | ||
} | ||
|
||
public default void updateInputs(IntakeInputs inputs) {} | ||
|
||
public default void setIntakeMotorPercentage(double percent) {} | ||
|
||
public default void setIndexerMotorPercentage(double percent) {} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/frc/robot/subsystems/intake/IntakeIOFalcon.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,47 @@ | ||
package frc.robot.subsystems.intake; | ||
|
||
import com.ctre.phoenix6.controls.DutyCycleOut; | ||
import com.ctre.phoenix6.hardware.TalonFX; | ||
import frc.robot.Constants; | ||
|
||
/** | ||
* Intake IO Layer with real motors and sensors | ||
*/ | ||
public class IntakeIOFalcon implements IntakeIO { | ||
|
||
private final TalonFX intakeMotor = | ||
new TalonFX(Constants.Motors.Intake.INTAKE_MOTOR_ID, "canivore"); | ||
private final TalonFX indexerMotor = | ||
new TalonFX(Constants.Motors.Intake.INDEXER_MOTOR_ID, "canivore"); | ||
|
||
private final DutyCycleOut intakeDutyCycleOut = new DutyCycleOut(0); | ||
private final DutyCycleOut indexerDutyCycleOut = new DutyCycleOut(0); | ||
|
||
/** | ||
* Intake IO Layer with real motors and sensors | ||
*/ | ||
public IntakeIOFalcon() {} | ||
|
||
@Override | ||
public void updateInputs(IntakeInputs inputs) { | ||
inputs.intakeSupplyVoltage = intakeMotor.getSupplyVoltage().getValueAsDouble(); | ||
inputs.intakeMotorVoltage = intakeMotor.getMotorVoltage().getValueAsDouble(); | ||
inputs.intakeAmps = intakeMotor.getStatorCurrent().getValueAsDouble(); | ||
inputs.intakeRPM = intakeMotor.getVelocity().getValueAsDouble(); | ||
inputs.indexerSupplyVoltage = indexerMotor.getSupplyVoltage().getValueAsDouble(); | ||
inputs.indexerMotorVoltage = indexerMotor.getMotorVoltage().getValueAsDouble(); | ||
inputs.indexerAmps = indexerMotor.getStatorCurrent().getValueAsDouble(); | ||
inputs.indexerRPM = indexerMotor.getVelocity().getValueAsDouble(); | ||
inputs.sensorStatus = false; | ||
} | ||
|
||
@Override | ||
public void setIntakeMotorPercentage(double percent) { | ||
intakeMotor.setControl(intakeDutyCycleOut.withOutput(percent)); | ||
} | ||
|
||
@Override | ||
public void setIndexerMotorPercentage(double percent) { | ||
indexerMotor.setControl(indexerDutyCycleOut.withOutput(percent)); | ||
} | ||
} |