Get IDK to work

This commit is contained in:
Michael Mikovsky
2026-02-09 18:38:55 -08:00
parent 51d2b80ea0
commit 6ce6d0eb0b
5 changed files with 48 additions and 40 deletions
@@ -1,18 +1,11 @@
package frc4388.robot.subsystems.shooter;
import static edu.wpi.first.units.Units.Rotation;
import static edu.wpi.first.units.Units.Rotations;
import static edu.wpi.first.units.Units.RotationsPerSecond;
import java.util.function.Supplier;
import org.littletonrobotics.junction.Logger;
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.units.measure.Angle;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc4388.robot.subsystems.intake.IntakeConstants;
import frc4388.robot.subsystems.shooter.ShooterIO.ShooterState;
public class Shooter extends SubsystemBase {
public ShooterIO io;
@@ -47,6 +40,7 @@ public class Shooter extends SubsystemBase {
Inactive,
}
public void setMode(ShooterMode mode) {
switch (mode) {
case Active:
@@ -57,12 +51,12 @@ public class Shooter extends SubsystemBase {
case Resting:
io.setShooterVelocity(state, RotationsPerSecond.of(ShooterConstants.SHOOTER_RESTING_VELOCITY.get()));
// io.setMotor2Velocity(state, ShooterConstants.SHOOTER_RESTING_VELOCITY);
io.setIndexerVelocity(state, RotationsPerSecond.of(ShooterConstants.INDEXER_INACTIVE_VELOCITY.get()));
io.setIndexerVelocity(state, RotationsPerSecond.of(0));
break;
case Inactive:
io.setShooterVelocity(state, RotationsPerSecond.of(ShooterConstants.SHOOTER_RESTING_VELOCITY.get()));
// io.setMotor2Velocity(state, ShooterConstants.SHOOTER_RESTING_VELOCITY);
io.setIndexerVelocity(state, RotationsPerSecond.of(ShooterConstants.INDEXER_INACTIVE_VELOCITY.get()));
io.setIndexerVelocity(state, RotationsPerSecond.of(0));
break;
}
}
@@ -31,10 +31,10 @@ public class ShooterConstants {
public static final ConfigurableDouble SHOOTER_ACTIVE_VELOCITY = new ConfigurableDouble("Shooter Active Velocity", 30);
public static final ConfigurableDouble SHOOTER_RESTING_VELOCITY = new ConfigurableDouble("Shooter Resting Velocity", 15);
public static final ConfigurableDouble SHOOTER_INACTIVE_VELOCITY = new ConfigurableDouble("Shooter Inactive Velocity", 0);
// public static final ConfigurableDouble SHOOTER_INACTIVE_VELOCITY = new ConfigurableDouble("Shooter Inactive Velocity", 0);
public static final ConfigurableDouble INDEXER_ACTIVE_VELOCITY = new ConfigurableDouble("Shooter Active Velocity", 10);
public static final ConfigurableDouble INDEXER_INACTIVE_VELOCITY = new ConfigurableDouble("Shooter Inactive Velocity", 0);
// public static final ConfigurableDouble INDEXER_INACTIVE_VELOCITY = new ConfigurableDouble("Shooter Inactive Velocity", 0);
public static Slot0Configs SHOOTER_PID = new Slot0Configs()
.withKV(0.0)
@@ -47,6 +47,15 @@ public class ShooterConstants {
.withKP(0.0)
.withKI(0.0)
.withKD(0.0);
public static ConfigurableDouble indexer_kP = new ConfigurableDouble("Indexer KP", 0.2);
public static ConfigurableDouble indexer_kI = new ConfigurableDouble("Indexer KP", 0);
public static ConfigurableDouble indexer_kD = new ConfigurableDouble("Indexer KP", 0);
public static ConfigurableDouble shooter_kP = new ConfigurableDouble("Shooter KP", 0.2);
public static ConfigurableDouble shooter_kI = new ConfigurableDouble("Shooter KI", 0);
public static ConfigurableDouble shooter_kD = new ConfigurableDouble("Shooter KD", 0);
// Limits
@@ -94,6 +94,12 @@ public class ShooterReal implements ShooterIO {
state.motor1TargetVelocity = target;
state.motor2TargetVelocity = target;
if(target.baseUnitMagnitude() == 0) {
m_shooter1Motor.set(0);
m_shooter2Motor.set(0);
return;
}
AngularVelocity motorRps = target.div(ShooterConstants.INDEXER_GEAR_RATIO);
m_shooter1Motor.setControl(shooter1Velocity.withVelocity(motorRps));
@@ -107,14 +113,6 @@ public class ShooterReal implements ShooterIO {
m_indexerMotor.setControl(m_indexerVelocity.withVelocity(motorRps));
}
ConfigurableDouble indexer_kP = new ConfigurableDouble("Indexer KP", 0.2);
ConfigurableDouble indexer_kI = new ConfigurableDouble("Indexer KP", 0);
ConfigurableDouble indexer_kD = new ConfigurableDouble("Indexer KP", 0);
ConfigurableDouble shooter_kP = new ConfigurableDouble("Shooter KP", 0.2);
ConfigurableDouble shooter_kI = new ConfigurableDouble("Shooter KI", 0);
ConfigurableDouble shooter_kD = new ConfigurableDouble("Shooter KD", 0);
@Override
public void updateInputs(ShooterState state) {
@@ -130,19 +128,19 @@ public class ShooterReal implements ShooterIO {
state.indexerCurrent = m_indexerMotor.getStatorCurrent().getValue();
}
@Override
public void updateGains() {
// TEMPORARY PIDs
ShooterConstants.SHOOTER_PID.kP = shooter_kP.get();
ShooterConstants.SHOOTER_PID.kI = shooter_kI.get();
ShooterConstants.SHOOTER_PID.kD = shooter_kD.get();
ShooterConstants.SHOOTER_PID.kP = ShooterConstants.shooter_kP.get();
ShooterConstants.SHOOTER_PID.kI = ShooterConstants.shooter_kI.get();
ShooterConstants.SHOOTER_PID.kD = ShooterConstants.shooter_kD.get();
m_shooter1Motor.getConfigurator().apply(ShooterConstants.SHOOTER_PID);
m_shooter2Motor.getConfigurator().apply(ShooterConstants.SHOOTER_PID);
ShooterConstants.INDEXER_PID.kP = indexer_kP.get();
ShooterConstants.INDEXER_PID.kI = indexer_kI.get();
ShooterConstants.INDEXER_PID.kD = indexer_kD.get();
ShooterConstants.INDEXER_PID.kP = ShooterConstants.indexer_kP.get();
ShooterConstants.INDEXER_PID.kI = ShooterConstants.indexer_kI.get();
ShooterConstants.INDEXER_PID.kD = ShooterConstants.indexer_kD.get();
m_indexerMotor.getConfigurator().apply(ShooterConstants.INDEXER_PID);
}