add testing changes

This commit is contained in:
mimigamin
2026-03-19 18:32:02 -06:00
parent 917aaa7746
commit 4ffbe3f595
7 changed files with 90 additions and 74 deletions
@@ -32,7 +32,7 @@ public class Shooter extends SubsystemBase {
// Supplier<Pose2d> m_swervePoseSupplier;
public boolean badShooterVelocity;
public double distanceToHub = 5;
public double chassisXSpeed = 0;
public Shooter(
ShooterIO io,
@@ -66,7 +66,8 @@ public class Shooter extends SubsystemBase {
private ShooterMode mode = ShooterMode.Idle;
private boolean shooterButtonReady = false;
public void spinUpShooting() {
public void spinUpShooting(double chassisXSpeed) {
this.chassisXSpeed = chassisXSpeed;
this.mode = ShooterMode.Shooting;
}
@@ -35,7 +35,7 @@ public class ShooterConstants {
public static final ConfigurableDouble MODEL_TRIM = new ConfigurableDouble("TRIM SHOOTER SPEED", 0);
public static final ConfigurableDouble AIM_LEAD_TIME = new ConfigurableDouble("Aim lead time", 0);
public static final ConfigurableDouble AIM_LEAD_TIME = new ConfigurableDouble("Aim lead time", -1);
// Shoot mode tolerances
public static final ConfigurableDouble ROBOT_MIN_HUB = new ConfigurableDouble("Shoot min dist M", 1.8);
@@ -82,8 +82,8 @@ public class ShooterConstants {
// Motor Configuration
public static Slot0Configs SHOOTER_PID = new Slot0Configs()
.withKV(0.0)
.withKP(0.05)
.withKI(0.20)
.withKP(0.02)
.withKI(0.15)
.withKD(0.0);
@@ -91,7 +91,7 @@ public class ShooterConstants {
public static ConfigurableDouble shooter_kP = new ConfigurableDouble("Shooter KP", 0.08);
public static ConfigurableDouble shooter_kP = new ConfigurableDouble("Shooter KP", 0.02);
public static ConfigurableDouble shooter_kI = new ConfigurableDouble("Shooter KI", 0.15);
public static ConfigurableDouble shooter_kD = new ConfigurableDouble("Shooter KD", 0);
@@ -21,7 +21,7 @@ public interface ShooterIO {
// Angle shooterTargetPitch = Rotations.of(0);
// Current pitchMotorCurrent = Amps.of(0);
AngularVelocity motor1TargetVelocity = RotationsPerSecond.of(40); // For modeling purposes
AngularVelocity motor1TargetVelocity = RotationsPerSecond.of(0);
AngularVelocity motor2TargetVelocity = RotationsPerSecond.of(0);
double indexerTargetOutput = 0;
@@ -3,6 +3,7 @@ package frc4388.robot.subsystems.shooter;
import static edu.wpi.first.units.Units.Amps;
import static edu.wpi.first.units.Units.RotationsPerSecond;
import org.littletonrobotics.junction.Logger;
import com.ctre.phoenix6.controls.VelocityDutyCycle;
import com.ctre.phoenix6.hardware.TalonFX;
@@ -29,6 +30,8 @@ public class ShooterReal implements ShooterIO {
private boolean m_shooterStalling = false;
private boolean m_indexerStalling = false;
private boolean m_rollerStalling = false;
public String motorStall = "";
public ShooterReal(
TalonFX shooter1Motor,
@@ -52,46 +55,52 @@ public class ShooterReal implements ShooterIO {
}
@Override
public void motorStalled(ShooterState state, Intake m_Intake, LED m_robotLED) {
// if (Math.abs(state.motor1TargetVelocity.in(RotationsPerSecond)) - Math.abs(state.motor1Velocity.in(RotationsPerSecond)) > 20) {
// if (!m_shooterStalling) {
// m_shooterStalling = true;
// m_stallTimerShooter.restart();
// }
// if (m_stallTimerShooter.hasElapsed(5.0)) {
// m_robotLED.setMode(Constants.LEDConstants.MOTOR_STALLED);
// }
// } else {
// m_shooterStalling = false;
// m_stallTimerShooter.stop();
// }
public void motorStalled(ShooterState state, Intake m_Intake, LED m_robotLED) {
if (Math.abs(state.motor1TargetVelocity.in(RotationsPerSecond)) - Math.abs(state.motor1Velocity.in(RotationsPerSecond)) > 40) {
if (!m_shooterStalling) {
m_shooterStalling = true;
m_stallTimerShooter.restart();
}
if (m_stallTimerShooter.hasElapsed(5.0)) {
m_robotLED.setMode(Constants.LEDConstants.MOTOR_STALLED);
motorStall = "Shooter Stalled";
System.out.println(Math.abs(state.motor1TargetVelocity.in(RotationsPerSecond)) - Math.abs(state.motor1Velocity.in(RotationsPerSecond)));
}
} else {
m_shooterStalling = false;
m_stallTimerShooter.reset();
}
// if (Math.abs(state.indexerTargetOutput) - Math.abs(state.indexerOutput) > 0.2) {
// if (!m_indexerStalling) {
// m_indexerStalling = true;
// m_stallTimerIndexer.restart();
// }
// if (m_stallTimerIndexer.hasElapsed(5.0)) {
// m_robotLED.setMode(Constants.LEDConstants.MOTOR_STALLED);
// }
// } else {
// m_indexerStalling = false;
// m_stallTimerIndexer.stop();
// }
if (Math.abs(state.indexerTargetOutput) - Math.abs(state.indexerOutput) > 0.3) {
if (!m_indexerStalling) {
m_indexerStalling = true;
m_stallTimerIndexer.restart();
}
if (m_stallTimerIndexer.hasElapsed(5.0)) {
m_robotLED.setMode(Constants.LEDConstants.MOTOR_STALLED);
motorStall = "Indexer Stalled";
System.out.println(Math.abs(state.indexerTargetOutput) - Math.abs(state.indexerOutput));
}
} else {
m_indexerStalling = false;
m_stallTimerIndexer.reset();
}
// if (Math.abs(m_Intake.getRollerTarget()) - Math.abs(m_Intake.getRollerSpeed()) > 0.2) {
// if (!m_rollerStalling) {
// m_rollerStalling = true;
// m_stallTimerRoller.restart();
// }
// if (m_stallTimerRoller.hasElapsed(5.0)) {
// m_robotLED.setMode(Constants.LEDConstants.MOTOR_STALLED);
// }
// } else {
// m_rollerStalling = false;
// m_stallTimerRoller.stop();
// }
if (Math.abs(m_Intake.getRollerTarget()) - Math.abs(m_Intake.getRollerSpeed()) > 0.4) {
if (!m_rollerStalling) {
m_rollerStalling = true;
m_stallTimerRoller.restart();
}
if (m_stallTimerRoller.hasElapsed(5.0)) {
m_robotLED.setMode(Constants.LEDConstants.MOTOR_STALLED);
motorStall = "Roller Stalled";
System.out.println(Math.abs(m_Intake.getRollerTarget()) - Math.abs(m_Intake.getRollerSpeed()));
}
} else {
m_rollerStalling = false;
m_stallTimerRoller.reset();
}
Logger.recordOutput("Stalled Motor: ", motorStall);
}
@@ -166,6 +166,14 @@ public class SwerveDrive extends SubsystemBase implements Queryable {
// module.setDesiredState(state);
// }
public double chassisXSpeeds(){
if (TimesNegativeOne.isRed) {
return chassisSpeeds.vxMetersPerSecond;
} else {
return -chassisSpeeds.vxMetersPerSecond;
}
}
public void driveWithInput(Translation2d leftStick, Translation2d rightStick, boolean fieldRelative) {
if (rightStick.getNorm() < 0.05 && leftStick.getNorm() < 0.05 && stopped == false) // if no imput and the swerve drive is still going:
stopModules(); // stop the swerve
@@ -412,7 +420,7 @@ public class SwerveDrive extends SubsystemBase implements Queryable {
if (ballVelocity > 1E-3 && Math.abs(chassisSpeeds.vyMetersPerSecond) > 1E-3){
double aimOffset = chassisSpeeds.vyMetersPerSecond*(distanceToHub + SwerveDriveConstants.distanceTolerence.get())/(Math.abs(ballVelocity));
fieldPos = new Translation2d(fieldPos.getX(), fieldPos.getY() - aimOffset);
Logger.recordOutput("Offset Simple", aimOffset);
Logger.recordOutput("Offset Value", aimOffset);
}