-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/main/java/org/littletonrobotics/frc2024/subsystems/superstructure/feeder/Feeder.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,27 @@ | ||
package org.littletonrobotics.frc2024.subsystems.superstructure.feeder; | ||
|
||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import org.littletonrobotics.junction.Logger; | ||
|
||
public class Feeder extends SubsystemBase { | ||
private final FeederIO io; | ||
private FeederIOInputsAutoLogged inputs = new FeederIOInputsAutoLogged(); | ||
|
||
public Feeder(FeederIO io) { | ||
this.io = io; | ||
} | ||
|
||
@Override | ||
public void periodic() { | ||
io.updateInputs(inputs); | ||
Logger.processInputs("Feeder", inputs); | ||
} | ||
|
||
public void runVolts(double volts) { | ||
io.runVolts(volts); | ||
} | ||
|
||
public void stop() { | ||
io.stop(); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...ava/org/littletonrobotics/frc2024/subsystems/superstructure/feeder/FeederIOSparkFlex.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,41 @@ | ||
package org.littletonrobotics.frc2024.subsystems.superstructure.feeder; | ||
|
||
import static org.littletonrobotics.frc2024.subsystems.superstructure.SuperstructureConstants.FeederConstants.*; | ||
|
||
import com.revrobotics.CANSparkBase; | ||
import com.revrobotics.CANSparkFlex; | ||
import com.revrobotics.RelativeEncoder; | ||
import edu.wpi.first.math.util.Units; | ||
|
||
public class FeederIOSparkFlex implements FeederIO { | ||
private final CANSparkFlex motor; | ||
private final RelativeEncoder encoder; | ||
|
||
public FeederIOSparkFlex() { | ||
motor = new CANSparkFlex(id, CANSparkBase.MotorType.kBrushless); | ||
|
||
motor.setInverted(inverted); | ||
motor.setIdleMode(CANSparkBase.IdleMode.kBrake); | ||
|
||
encoder = motor.getEncoder(); | ||
} | ||
|
||
@Override | ||
public void updateInputs(FeederIOInputs inputs) { | ||
inputs.positionRads = Units.rotationsToRadians(encoder.getPosition()) / reduction; | ||
inputs.velocityRadsPerSec = | ||
Units.rotationsPerMinuteToRadiansPerSecond(encoder.getVelocity()) / reduction; | ||
inputs.appliedVoltage = motor.getAppliedOutput() * motor.getBusVoltage(); | ||
inputs.outputCurrent = motor.getOutputCurrent(); | ||
} | ||
|
||
@Override | ||
public void runVolts(double volts) { | ||
motor.setVoltage(volts); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
motor.stopMotor(); | ||
} | ||
} |