Working robot in testing

This commit is contained in:
Michael Mikovsky
2026-02-10 17:33:39 -08:00
parent 6ce6d0eb0b
commit 539c1bd8eb
8 changed files with 74 additions and 61 deletions
@@ -40,25 +40,10 @@ public class Shooter extends SubsystemBase {
Inactive,
}
private ShooterMode mode = ShooterMode.Inactive;
public void setMode(ShooterMode mode) {
switch (mode) {
case Active:
io.setShooterVelocity(state, RotationsPerSecond.of(ShooterConstants.SHOOTER_ACTIVE_VELOCITY.get()));
// io.setMotor2Velocity(state, ShooterConstants.SHOOTER_ACTIVE_VELOCITY);
io.setIndexerVelocity(state, RotationsPerSecond.of(ShooterConstants.INDEXER_ACTIVE_VELOCITY.get()));
break;
case Resting:
io.setShooterVelocity(state, RotationsPerSecond.of(ShooterConstants.SHOOTER_RESTING_VELOCITY.get()));
// io.setMotor2Velocity(state, ShooterConstants.SHOOTER_RESTING_VELOCITY);
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(0));
break;
}
this.mode = mode;
}
// Calculate what should be done based off of the position of the robot
@@ -83,5 +68,23 @@ public class Shooter extends SubsystemBase {
io.updateInputs(state);
switch (mode) {
case Active:
io.setShooterVelocity(state, RotationsPerSecond.of(ShooterConstants.SHOOTER_ACTIVE_VELOCITY.get()));
// io.setMotor2Velocity(state, ShooterConstants.SHOOTER_ACTIVE_VELOCITY);
io.setIndexerVelocity(state, RotationsPerSecond.of(ShooterConstants.INDEXER_ACTIVE_VELOCITY.get()));
break;
case Resting:
io.setShooterVelocity(state, RotationsPerSecond.of(ShooterConstants.SHOOTER_RESTING_VELOCITY.get()));
// io.setMotor2Velocity(state, ShooterConstants.SHOOTER_RESTING_VELOCITY);
io.setIndexerVelocity(state, RotationsPerSecond.of(0));
break;
case Inactive:
io.setShooterVelocity(state, RotationsPerSecond.of(0));
// io.setMotor2Velocity(state, ShooterConstants.SHOOTER_RESTING_VELOCITY);
io.setIndexerVelocity(state, RotationsPerSecond.of(0));
break;
}
}
}
@@ -14,7 +14,7 @@ import edu.wpi.first.units.measure.AngularVelocity;
import frc4388.utility.configurable.ConfigurableDouble;
import frc4388.utility.status.CanDevice;
public class ShooterConstants {
public class ShooterConstants {
// Motor conversions
public static final double FEEDER_INCHES_PER_ROT = 1.;
@@ -33,25 +33,25 @@ public class ShooterConstants {
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 INDEXER_ACTIVE_VELOCITY = new ConfigurableDouble("Shooter Active Velocity", 10);
public static final ConfigurableDouble INDEXER_ACTIVE_VELOCITY = new ConfigurableDouble("Indexer Active Velocity", 10);
// public static final ConfigurableDouble INDEXER_INACTIVE_VELOCITY = new ConfigurableDouble("Shooter Inactive Velocity", 0);
public static Slot0Configs SHOOTER_PID = new Slot0Configs()
.withKV(0.0)
.withKP(0.0)
.withKI(0.0)
.withKD(0.0);
.withKD(0.2);
public static Slot0Configs INDEXER_PID = new Slot0Configs()
.withKV(0.0)
.withKP(0.0)
.withKI(0.0)
.withKD(0.0);
.withKD(0.2);
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 indexer_kI = new ConfigurableDouble("Indexer KI", 0);
public static ConfigurableDouble indexer_kD = new ConfigurableDouble("Indexer KD", 0);
public static ConfigurableDouble shooter_kP = new ConfigurableDouble("Shooter KP", 0.2);
public static ConfigurableDouble shooter_kI = new ConfigurableDouble("Shooter KI", 0);
@@ -100,7 +100,7 @@ public class ShooterReal implements ShooterIO {
return;
}
AngularVelocity motorRps = target.div(ShooterConstants.INDEXER_GEAR_RATIO);
AngularVelocity motorRps = target.times(ShooterConstants.INDEXER_GEAR_RATIO);
m_shooter1Motor.setControl(shooter1Velocity.withVelocity(motorRps));
m_shooter2Motor.setControl(shooter2Velocity.withVelocity(motorRps));
@@ -109,7 +109,13 @@ public class ShooterReal implements ShooterIO {
@Override
public void setIndexerVelocity(ShooterState state, AngularVelocity target) {
state.indexerTargetVelocity = target;
AngularVelocity motorRps = target.div(ShooterConstants.INDEXER_GEAR_RATIO);
if(target.baseUnitMagnitude() == 0) {
m_indexerMotor.set(0);
return;
}
AngularVelocity motorRps = target.times(ShooterConstants.INDEXER_GEAR_RATIO);
m_indexerMotor.setControl(m_indexerVelocity.withVelocity(motorRps));
}
@@ -117,9 +123,9 @@ public class ShooterReal implements ShooterIO {
@Override
public void updateInputs(ShooterState state) {
state.motor1Velocity = m_shooter1Motor.getVelocity().getValue().times(ShooterConstants.SHOOTERMOTOR1_GEAR_RATIO);
state.motor2Velocity = m_shooter2Motor.getVelocity().getValue().times(ShooterConstants.SHOOTERMOTOR2_GEAR_RATIO);
state.indexerVelocity = m_indexerMotor.getVelocity().getValue().times(ShooterConstants.INDEXER_GEAR_RATIO);
state.motor1Velocity = m_shooter1Motor.getVelocity().getValue().div(ShooterConstants.SHOOTERMOTOR1_GEAR_RATIO);
state.motor2Velocity = m_shooter2Motor.getVelocity().getValue().div(ShooterConstants.SHOOTERMOTOR2_GEAR_RATIO);
state.indexerVelocity = m_indexerMotor.getVelocity().getValue().div(ShooterConstants.INDEXER_GEAR_RATIO);
// state.motorLinearVelocity = InchesPerSecond.of(m_shooter1Motor.getVelocity().getValue().in(RotationsPerSecond) * ShooterConstants.FEEDER_INCHES_PER_ROT);