2026-01-10 16:52:43 -07:00
|
|
|
package frc4388.robot.subsystems.shooter;
|
|
|
|
|
|
2026-02-24 13:50:30 -07:00
|
|
|
import static edu.wpi.first.units.Units.Amps;
|
|
|
|
|
import static edu.wpi.first.units.Units.RotationsPerSecond;
|
|
|
|
|
|
2026-01-10 16:52:43 -07:00
|
|
|
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-02-24 13:50:30 -07:00
|
|
|
import edu.wpi.first.units.measure.Current;
|
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);
|
2026-02-17 18:53:26 -08:00
|
|
|
// 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);
|
|
|
|
|
|
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;
|
2026-02-17 18:53:26 -08:00
|
|
|
// 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
|
|
|
}
|
|
|
|
|
|
2026-02-24 13:50:30 -07:00
|
|
|
@Override
|
|
|
|
|
public void setShooterCurrentLimitSpeed(
|
|
|
|
|
ShooterState state,
|
|
|
|
|
double percentOutput,
|
|
|
|
|
Current currentLimit,
|
|
|
|
|
AngularVelocity targetVelocity
|
|
|
|
|
) {
|
|
|
|
|
state.motor1TargetVelocity = targetVelocity;
|
|
|
|
|
state.motor2TargetVelocity = targetVelocity;
|
|
|
|
|
|
|
|
|
|
double current = Math.abs(state.motor1Current.in(Amps)) + Math.abs(state.motor2Current.in(Amps));
|
|
|
|
|
double velocity = (Math.abs(state.motor1Velocity.in(RotationsPerSecond)) + Math.abs(state.motor2Velocity.in(RotationsPerSecond))) / 2;
|
|
|
|
|
|
|
|
|
|
if(
|
|
|
|
|
Math.abs(currentLimit.in(Amps)) > current &&
|
|
|
|
|
Math.abs(targetVelocity.in(RotationsPerSecond)) > velocity
|
|
|
|
|
) {
|
|
|
|
|
m_shooter1Motor.set(percentOutput);
|
|
|
|
|
m_shooter2Motor.set(percentOutput);
|
|
|
|
|
} else {
|
|
|
|
|
m_shooter1Motor.set(0);
|
|
|
|
|
m_shooter2Motor.set(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-10 16:52:43 -07:00
|
|
|
@Override
|
2026-02-16 18:21:53 -07:00
|
|
|
public void setIndexerOutput(ShooterState state, double percentOutput) {
|
|
|
|
|
state.indexerTargetOutput = percentOutput;
|
2026-02-10 17:33:39 -08:00
|
|
|
|
2026-02-16 18:21:53 -07:00
|
|
|
if(percentOutput == 0) {
|
2026-02-10 17:33:39 -08:00
|
|
|
m_indexerMotor.set(0);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-16 18:21:53 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// AngularVelocity motorRps = target.times(ShooterConstants.INDEXER_GEAR_RATIO);
|
|
|
|
|
m_indexerMotor.set(percentOutput);
|
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-16 18:21:53 -07:00
|
|
|
state.indexerOutput = m_indexerMotor.get();
|
|
|
|
|
// state.indexerOutput = 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-01-10 16:52:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|