2026-01-10 16:52:43 -07:00
|
|
|
package frc4388.robot.subsystems.shooter;
|
|
|
|
|
|
|
|
|
|
import com.ctre.phoenix6.controls.VelocityDutyCycle;
|
|
|
|
|
import com.ctre.phoenix6.hardware.TalonFX;
|
|
|
|
|
|
2026-01-27 18:13:51 -07:00
|
|
|
import edu.wpi.first.units.measure.AngularVelocity;
|
2026-01-10 16:52:43 -07:00
|
|
|
|
2026-01-27 19:15:37 -07:00
|
|
|
public class ShooterReal implements ShooterIO {
|
2026-01-27 18:13:51 -07:00
|
|
|
|
|
|
|
|
TalonFX m_shooter1Motor;
|
|
|
|
|
TalonFX m_shooter2Motor;
|
|
|
|
|
TalonFX m_indexerMotor;
|
2026-02-09 17:18:54 -08:00
|
|
|
|
2026-01-27 18:13:51 -07:00
|
|
|
VelocityDutyCycle shooter1Velocity = new VelocityDutyCycle(0);
|
|
|
|
|
VelocityDutyCycle shooter2Velocity = new VelocityDutyCycle(0);
|
|
|
|
|
VelocityDutyCycle m_indexerVelocity = new VelocityDutyCycle(0);
|
2026-01-10 16:52:43 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
public ShooterReal(
|
2026-01-27 18:13:51 -07:00
|
|
|
TalonFX shooter1Motor,
|
|
|
|
|
TalonFX shooter2Motor,
|
|
|
|
|
TalonFX indexerMotor
|
2026-01-10 16:52:43 -07:00
|
|
|
) {
|
2026-02-09 16:03:48 -08:00
|
|
|
m_shooter1Motor = shooter1Motor;
|
|
|
|
|
m_shooter2Motor = shooter2Motor;
|
|
|
|
|
m_indexerMotor = indexerMotor;
|
2026-02-09 17:18:54 -08:00
|
|
|
|
2026-01-27 19:15:37 -07:00
|
|
|
m_shooter1Motor.getConfigurator().apply(ShooterConstants.SHOOTER_PID);
|
|
|
|
|
m_shooter2Motor.getConfigurator().apply(ShooterConstants.SHOOTER_PID);
|
|
|
|
|
m_indexerMotor.getConfigurator().apply(ShooterConstants.SHOOTER_PID);
|
|
|
|
|
|
2026-01-27 18:13:51 -07:00
|
|
|
m_shooter1Motor.getConfigurator().apply(ShooterConstants.SHOOTER1_MOTOR_CONFIG);
|
|
|
|
|
m_shooter2Motor.getConfigurator().apply(ShooterConstants.SHOOTER2_MOTOR_CONFIG);
|
|
|
|
|
m_indexerMotor.getConfigurator().apply(ShooterConstants.INDEXER_MOTOR_CONFIG);
|
2026-02-09 17:18:54 -08:00
|
|
|
|
|
|
|
|
shooter1Velocity.Slot = 0;
|
|
|
|
|
shooter2Velocity.Slot = 0;
|
|
|
|
|
m_indexerVelocity.Slot = 0;
|
2026-01-10 16:52:43 -07:00
|
|
|
}
|
|
|
|
|
|
2026-01-27 18:13:51 -07:00
|
|
|
@Override
|
2026-02-09 17:18:54 -08:00
|
|
|
public void setShooterVelocity(ShooterState state, AngularVelocity target) {
|
2026-01-27 19:15:37 -07:00
|
|
|
state.motor1TargetVelocity = target;
|
2026-01-27 18:13:51 -07:00
|
|
|
state.motor2TargetVelocity = target;
|
2026-01-27 19:15:37 -07:00
|
|
|
|
2026-02-09 18:38:55 -08:00
|
|
|
if(target.baseUnitMagnitude() == 0) {
|
|
|
|
|
m_shooter1Motor.set(0);
|
|
|
|
|
m_shooter2Motor.set(0);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-14 14:03:32 -08:00
|
|
|
AngularVelocity motorRps = target.times(ShooterConstants.SHOOTERMOTOR_GEAR_RATIO);
|
2026-02-09 17:18:54 -08:00
|
|
|
|
|
|
|
|
m_shooter1Motor.setControl(shooter1Velocity.withVelocity(motorRps));
|
|
|
|
|
m_shooter2Motor.setControl(shooter2Velocity.withVelocity(motorRps));
|
2026-01-10 16:52:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2026-01-27 18:13:51 -07:00
|
|
|
public void setIndexerVelocity(ShooterState state, AngularVelocity target) {
|
|
|
|
|
state.indexerTargetVelocity = target;
|
2026-02-10 17:33:39 -08:00
|
|
|
|
|
|
|
|
if(target.baseUnitMagnitude() == 0) {
|
|
|
|
|
m_indexerMotor.set(0);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AngularVelocity motorRps = target.times(ShooterConstants.INDEXER_GEAR_RATIO);
|
2026-02-09 17:18:54 -08:00
|
|
|
m_indexerMotor.setControl(m_indexerVelocity.withVelocity(motorRps));
|
2026-01-10 16:52:43 -07:00
|
|
|
}
|
|
|
|
|
|
2026-02-09 17:18:54 -08:00
|
|
|
|
2026-01-10 16:52:43 -07:00
|
|
|
@Override
|
|
|
|
|
public void updateInputs(ShooterState state) {
|
|
|
|
|
|
2026-02-14 14:03:32 -08:00
|
|
|
state.motor1Velocity = m_shooter1Motor.getVelocity().getValue().div(ShooterConstants.SHOOTERMOTOR_GEAR_RATIO);
|
|
|
|
|
state.motor2Velocity = m_shooter2Motor.getVelocity().getValue().div(ShooterConstants.SHOOTERMOTOR_GEAR_RATIO);
|
2026-02-10 17:33:39 -08:00
|
|
|
state.indexerVelocity = m_indexerMotor.getVelocity().getValue().div(ShooterConstants.INDEXER_GEAR_RATIO);
|
2026-01-10 16:52:43 -07:00
|
|
|
|
2026-02-09 17:18:54 -08:00
|
|
|
// state.motorLinearVelocity = InchesPerSecond.of(m_shooter1Motor.getVelocity().getValue().in(RotationsPerSecond) * ShooterConstants.FEEDER_INCHES_PER_ROT);
|
2026-01-27 19:15:37 -07:00
|
|
|
|
2026-01-27 18:13:51 -07:00
|
|
|
state.motor1Current = m_shooter1Motor.getStatorCurrent().getValue();
|
2026-01-27 19:15:37 -07:00
|
|
|
state.motor2Current = m_shooter2Motor.getStatorCurrent().getValue();
|
|
|
|
|
state.indexerCurrent = m_indexerMotor.getStatorCurrent().getValue();
|
2026-02-09 17:18:54 -08:00
|
|
|
|
|
|
|
|
}
|
2026-02-09 18:38:55 -08:00
|
|
|
|
2026-02-09 17:18:54 -08:00
|
|
|
@Override
|
|
|
|
|
public void updateGains() {
|
|
|
|
|
// TEMPORARY PIDs
|
2026-02-09 18:38:55 -08:00
|
|
|
ShooterConstants.SHOOTER_PID.kP = ShooterConstants.shooter_kP.get();
|
|
|
|
|
ShooterConstants.SHOOTER_PID.kI = ShooterConstants.shooter_kI.get();
|
|
|
|
|
ShooterConstants.SHOOTER_PID.kD = ShooterConstants.shooter_kD.get();
|
2026-02-09 17:18:54 -08:00
|
|
|
m_shooter1Motor.getConfigurator().apply(ShooterConstants.SHOOTER_PID);
|
|
|
|
|
m_shooter2Motor.getConfigurator().apply(ShooterConstants.SHOOTER_PID);
|
|
|
|
|
|
2026-02-09 18:38:55 -08:00
|
|
|
ShooterConstants.INDEXER_PID.kP = ShooterConstants.indexer_kP.get();
|
|
|
|
|
ShooterConstants.INDEXER_PID.kI = ShooterConstants.indexer_kI.get();
|
|
|
|
|
ShooterConstants.INDEXER_PID.kD = ShooterConstants.indexer_kD.get();
|
2026-02-09 17:18:54 -08:00
|
|
|
m_indexerMotor.getConfigurator().apply(ShooterConstants.INDEXER_PID);
|
2026-01-10 16:52:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|