Shooting is working

This commit is contained in:
Tyler Wilcox 2026-03-29 14:30:48 -04:00
parent 65e25ee9e3
commit a06b44edf7
4 changed files with 32 additions and 7 deletions

View File

@ -117,7 +117,7 @@ public final class Constants {
public static class HopperConstants { public static class HopperConstants {
public static final int KICKER_MOTOR_ID = 9; public static final int KICKER_MOTOR_ID = 9;
public static final InvertedValue KICKER_MOTOR_DIRECTION = InvertedValue.CounterClockwise_Positive; public static final InvertedValue KICKER_MOTOR_DIRECTION = InvertedValue.Clockwise_Positive;
public static final int SPINDEXER_MOTOR_ID = 8; public static final int SPINDEXER_MOTOR_ID = 8;
public static final InvertedValue SPINDEXER_MOTOR_DIRECTION = InvertedValue.CounterClockwise_Positive; public static final InvertedValue SPINDEXER_MOTOR_DIRECTION = InvertedValue.CounterClockwise_Positive;

View File

@ -70,6 +70,11 @@ public class RobotContainer {
// m_driverController.x().onTrue(intakeSubsystem.killSpeedCommand()); // m_driverController.x().onTrue(intakeSubsystem.killSpeedCommand());
// m_driverController.a().onTrue(intakeSubsystem.startSpeedCommand()); // m_driverController.a().onTrue(intakeSubsystem.startSpeedCommand());
m_driverController.b().whileTrue(turretSubsystem.setShooter(1500));
m_driverController.x().whileTrue(turretSubsystem.setShooter(2000));
m_driverController.y().whileTrue(turretSubsystem.setShooter(3000));
m_driverController.a().whileTrue(new AutoShootCommandChassisTurret(driveSubsystem, hopperSubsystem, turretSubsystem)); m_driverController.a().whileTrue(new AutoShootCommandChassisTurret(driveSubsystem, hopperSubsystem, turretSubsystem));
} }

View File

@ -74,7 +74,7 @@ public class AutoShootCommandChassisTurret extends Command{
} }
}); });
turretSubsystem.setLauncher(2500); turretSubsystem.setLauncher(5500);
hopperSubsystem.spindexerOn(); hopperSubsystem.spindexerOn();
cameraAutoCenterController.calculate(-100); cameraAutoCenterController.calculate(-100);

View File

@ -20,6 +20,7 @@ import com.ctre.phoenix6.signals.InvertedValue;
import com.revrobotics.PersistMode; import com.revrobotics.PersistMode;
import com.revrobotics.ResetMode; import com.revrobotics.ResetMode;
import com.revrobotics.spark.ClosedLoopSlot; import com.revrobotics.spark.ClosedLoopSlot;
import com.revrobotics.spark.FeedbackSensor;
import com.revrobotics.spark.SparkClosedLoopController; import com.revrobotics.spark.SparkClosedLoopController;
import com.revrobotics.spark.SparkMax; import com.revrobotics.spark.SparkMax;
import com.revrobotics.spark.SparkBase.ControlType; import com.revrobotics.spark.SparkBase.ControlType;
@ -33,6 +34,7 @@ import edu.wpi.first.units.measure.Angle;
import edu.wpi.first.wpilibj.DigitalInput; import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.Servo; import edu.wpi.first.wpilibj.Servo;
import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Commands;
public class TurretSubsystem extends TestableSubsystem { public class TurretSubsystem extends TestableSubsystem {
public enum TurretState { public enum TurretState {
@ -81,8 +83,14 @@ public class TurretSubsystem extends TestableSubsystem {
SparkMaxConfig config = new SparkMaxConfig() SparkMaxConfig config = new SparkMaxConfig()
.apply((SparkMaxConfig) SparkMaxConfig.Presets.REV_NEO); .apply((SparkMaxConfig) SparkMaxConfig.Presets.REV_NEO);
config.inverted(Constants.ShooterConstants.LAUNCHER_MOTOR_INVERTED); config.inverted(Constants.ShooterConstants.LAUNCHER_MOTOR_INVERTED);
config.closedLoop.p(1).i(0).d(0.1); config.voltageCompensation(10);
config.closedLoop.allowedClosedLoopError(10, ClosedLoopSlot.kSlot0); config.closedLoop.p(0.0001).i(0).d(0.0); // I = 0.0000001
config.closedLoop.feedForward.kS(0.2).kV(0.002).kA(0.00);
// config.closedLoop.allowedClosedLoopError(10, ClosedLoopSlot.kSlot0);
config.closedLoop.feedbackSensor(FeedbackSensor.kPrimaryEncoder);
config.closedLoop.positionWrappingEnabled(false);
// config.closedLoopRampRate(0.5);
// config.smartCurrentLimit(5, 50);
launcherMotor.configure(config, ResetMode.kResetSafeParameters, PersistMode.kPersistParameters); launcherMotor.configure(config, ResetMode.kResetSafeParameters, PersistMode.kPersistParameters);
launcherControler = launcherMotor.getClosedLoopController(); launcherControler = launcherMotor.getClosedLoopController();
@ -94,10 +102,13 @@ public class TurretSubsystem extends TestableSubsystem {
turretGoingPos = false; turretGoingPos = false;
} }
public void setLauncher(double speed) {launcherControler.setSetpoint(speed, ControlType.kVelocity);} public void setLauncher(double speed) {
launcherControler.setSetpoint(speed, ControlType.kVelocity, ClosedLoopSlot.kSlot0);
// launcherMotor.set(speed/1000);
}
public boolean isLauncherUpToSpeed() { public boolean isLauncherUpToSpeed() {
return launcherControler.isAtSetpoint(); return true;
} }
public void turretControl(double position) public void turretControl(double position)
@ -117,6 +128,14 @@ public class TurretSubsystem extends TestableSubsystem {
return this.runOnce(() -> setLauncher(-.5)); return this.runOnce(() -> setLauncher(-.5));
} }
public Command setShooter(int speedRPM){
return Commands.runEnd(() -> {
setLauncher(speedRPM);
}, () -> {
launcherMotor.stopMotor();
}, this);
}
public void startHoming() public void startHoming()
{ {
//turretMotor.set(Constants.ShooterConstants.HOMING_SPEED); //turretMotor.set(Constants.ShooterConstants.HOMING_SPEED);
@ -164,7 +183,8 @@ public class TurretSubsystem extends TestableSubsystem {
if(LOGGING) if(LOGGING)
{ {
Logger.recordOutput("Launcher Speed (RPM)", launcherMotor.getEncoder().getVelocity()); Logger.recordOutput("TurretSubsystem-Launcher Speed (RPM)", launcherMotor.getEncoder().getVelocity());
Logger.recordOutput("TurretSubsystem-Launcher Volatge", launcherMotor.getOutputCurrent());
} }
} }