|
| 1 | +package frc.robot.intake; |
| 2 | + |
| 3 | +import edu.wpi.first.math.controller.SimpleMotorFeedforward; |
| 4 | +import com.ctre.phoenix6.configs.TalonFXConfiguration; |
| 5 | +import com.ctre.phoenix6.hardware.TalonFX; |
| 6 | +import com.ctre.phoenix6.signals.NeutralModeValue; |
| 7 | +import frc.lib.Configurator; |
| 8 | + |
| 9 | +/** Roller motor using a TalonFX. */ |
| 10 | +public class RollerMotorIOTalonFX implements RollerMotorIO { |
| 11 | + |
| 12 | + private final TalonFX topTalonFX, bottomTalonFX; |
| 13 | + |
| 14 | + private final SimpleMotorFeedforward topFeedforward, bottomFeedforward; |
| 15 | + |
| 16 | + public RollerMotorIOTalonFX() { |
| 17 | + topTalonFX = new TalonFX(0); // TODO |
| 18 | + bottomTalonFX = new TalonFX(0); // TODO |
| 19 | + |
| 20 | + topFeedforward = new SimpleMotorFeedforward(0, 0); // TODO |
| 21 | + bottomFeedforward = new SimpleMotorFeedforward(0, 0); // TODO |
| 22 | + } |
| 23 | + |
| 24 | + @Override |
| 25 | + public void configure() { |
| 26 | + final TalonFXConfiguration config = new TalonFXConfiguration(); |
| 27 | + |
| 28 | + config.Feedback.SensorToMechanismRatio = 1.0; // TODO |
| 29 | + |
| 30 | + config.MotorOutput.NeutralMode = NeutralModeValue.Coast; |
| 31 | + |
| 32 | + Configurator.configureTalonFX(topTalonFX.getConfigurator(), config); |
| 33 | + Configurator.configureTalonFX(bottomTalonFX.getConfigurator(), config); |
| 34 | + } |
| 35 | + |
| 36 | + @Override |
| 37 | + public void update(RollerMotorIOValues values) { |
| 38 | + values.velocityRotationsPerSecond = getVelocity(); |
| 39 | + values.currentAmps = topTalonFX.getStatorCurrent().refresh().getValue(); |
| 40 | + } |
| 41 | + |
| 42 | + @Override |
| 43 | + public void setSetpoint(double velocityRotationsPerSecond) { |
| 44 | + double topVolts = topFeedforward.calculate(velocityRotationsPerSecond); |
| 45 | + |
| 46 | + topTalonFX.setVoltage(topVolts); |
| 47 | + |
| 48 | + double bottomVolts = bottomFeedforward.calculate(velocityRotationsPerSecond); |
| 49 | + |
| 50 | + bottomTalonFX.setVoltage(bottomVolts); |
| 51 | + } |
| 52 | + |
| 53 | + public double getVelocity() { |
| 54 | + return topTalonFX.getVelocity().refresh().getValue(); |
| 55 | + } |
| 56 | +} |
0 commit comments