limitConfig.SupplyCurrentLowerLimit = SpindexerConstants.currentLimit;
limitConfig.SupplyCurrentLowerTime = 1.5;
motor.getConfigurator().apply(limitConfig);
-
- SmartDashboard.putData("Max speed spindexer", new InstantCommand(() -> maxSpindexer()));
- SmartDashboard.putData("Turn off spindexer", new InstantCommand(() -> stopSpindexer()));
- SmartDashboard.putData("Spindexer 50%", new InstantCommand(() -> setSpindexer(0.5)));
}
@Override
// scale threshold based on power
double velocityThreshold = SpindexerConstants.spindexerVelocityWithBall * power;
- SmartDashboard.putNumber("Spindexer Velocity Threshold", velocityThreshold);
SmartDashboard.putNumber("Spindexer Ball Count", ballCount);
boolean isSpindexerSlow = inputs.spindexerVelocity < velocityThreshold;
import org.littletonrobotics.junction.Logger;
+import com.ctre.phoenix6.configs.CurrentLimitsConfigs;
import com.ctre.phoenix6.configs.TalonFXConfiguration;
import com.ctre.phoenix6.controls.MotionMagicVoltage;
import com.ctre.phoenix6.hardware.CANcoder;
import edu.wpi.first.wpilibj.smartdashboard.MechanismLigament2d;
import edu.wpi.first.wpilibj.smartdashboard.MechanismRoot2d;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
+import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.constants.Constants;
import frc.robot.constants.IdConstants;
private final TurretIOInputsAutoLogged inputs = new TurretIOInputsAutoLogged();
+ private boolean calibrating;
+
/* ---------------- Hardware ---------------- */
private final TalonFX motor = new TalonFX(IdConstants.TURRET_MOTOR_ID, Constants.CANIVORE_SUB);
mm.MotionMagicJerk = 0; // Set to > 0 for "S-Curve" smoothing if needed
motor.getConfigurator().apply(config);
+ setCurrentLimits(TurretConstants.NORMAL_CURRENT_LIMIT);
+
lastGoalRad = 0.0;
if (RobotBase.isSimulation()) {
// Multiply goal velocity by kV
double robotTurnCompensation = goalVelocityRadPerSec * TurretConstants.FEEDFORWARD_KV;
- // Sets motor control with feedforward
- motor.setControl(mmVoltageRequest
+ if(calibrating){
+ motor.set(0.05);
+ if(Math.abs(motor.getStatorCurrent().getValueAsDouble()) >= TurretConstants.CALIBRATION_CURRENT_THRESHOLD){
+ stopCalibrating();
+ }
+ } else{
+ // Sets motor control with feedforward
+ motor.setControl(mmVoltageRequest
.withPosition(motorGoalRotations)
.withFeedForward(robotTurnCompensation));
+ }
Logger.recordOutput("Turret/Voltage", motor.getMotorVoltage().getValue());
Logger.recordOutput("Turret/setpointDeg", goalAngle.getDegrees());
SmartDashboard.putNumber("Encoder left position", encoderLeft.getAbsolutePosition().getValueAsDouble());
SmartDashboard.putNumber("Encoder right position", encoderRight.getAbsolutePosition().getValueAsDouble());
-
+ SmartDashboard.putData("Start turret calibration", new InstantCommand(()-> calibrate()));
+ SmartDashboard.putData("Stop turret calibration", new InstantCommand(()-> stopCalibrating()));
}
/* ---------------- Simulation ---------------- */
inputs.motorVoltage = motor.getMotorVoltage().getValueAsDouble();
}
+ /**
+ * sets supply and stator current limits
+ * @param limit the current limit for stator and supply current
+ */
+ public void setCurrentLimits(double limit) {
+ CurrentLimitsConfigs limits = new CurrentLimitsConfigs()
+ .withStatorCurrentLimitEnable(true)
+ .withStatorCurrentLimit(limit)
+ .withSupplyCurrentLimitEnable(true)
+ .withSupplyCurrentLimit(limit);
+
+ if(limit == TurretConstants.NORMAL_CURRENT_LIMIT){
+ limits.SupplyCurrentLowerLimit = TurretConstants.CALIBRATION_CURRENT_LIMIT;
+ limits.SupplyCurrentLowerTime = 1.0; // Set to lower limit if over 1 second
+ }
+
+ motor.getConfigurator().apply(limits);
+ }
+
// Also ignore this for now
private double wrapUnit(double value) {
value %= 1.0;
if (value < 0) value += 1.0;
return value;
}
+
+ private void calibrate(){
+ setCurrentLimits(TurretConstants.CALIBRATION_CURRENT_LIMIT);
+ calibrating = true;
+ }
+
+ private void stopCalibrating(){
+ motor.set(Units.degreesToRotations(TurretConstants.CALIBRATION_OFFSET) * TurretConstants.GEAR_RATIO);
+ setCurrentLimits(TurretConstants.NORMAL_CURRENT_LIMIT);
+ calibrating = false;
+ setFieldRelativeTarget(new Rotation2d(Units.degreesToRadians(TurretConstants.CALIBRATION_OFFSET)), 0.0);
+ }
}