updateInputs();
TalonFXConfiguration config = new TalonFXConfiguration();
- config.Slot0.kP = 0.1; //tune p value
+ config.Slot0.kP = 0.15; //tune p value
config.Slot0.kI = 0;
- config.Slot0.kD = 0;
- config.Slot0.kV = 0.12; //Maximum rps = 100 --> 12V/100rps
+ config.Slot0.kD = 0.0;
+ config.Slot0.kV = 0.125; //Maximum rps = 100 --> 12V/100rps
shooterMotorLeft.getConfigurator().apply(config);
shooterMotorRight.getConfigurator().apply(config);
new MotorOutputConfigs().withNeutralMode(NeutralModeValue.Coast)
);
- SmartDashboard.putData("Turn on shooter", new InstantCommand(()-> setShooter(20.0)));
+ SmartDashboard.putData("Turn on shooter", new InstantCommand(()-> setShooter(12.0)));
}
@Override
powerModifier = SmartDashboard.getNumber("shooter power modifier", powerModifier);
SmartDashboard.putNumber("shooter power modifier", powerModifier);
- shooterMotorLeft.setControl(voltageRequest.withVelocity(shooterTargetSpeed * powerModifier));
- shooterMotorRight.setControl(voltageRequest.withVelocity(shooterTargetSpeed * powerModifier));
+ shooterMotorLeft.setControl(voltageRequest.withVelocity(Units.radiansToRotations(shooterTargetSpeed / (ShooterConstants.SHOOTER_LAUNCH_DIAMETER/2))));
+ shooterMotorRight.setControl(voltageRequest.withVelocity(Units.radiansToRotations(shooterTargetSpeed / (ShooterConstants.SHOOTER_LAUNCH_DIAMETER/2))));
+
+ Logger.recordOutput("Shooter/targetVelocity", shooterTargetSpeed);
}
public void setShooter(double linearVelocityMps) {
@Override
public void updateInputs(){
- inputs.shooterSpeedLeft = Units.rotationsToRadians(shooterMotorLeft.getVelocity().getValueAsDouble());
- inputs.shooterSpeedRight = Units.rotationsToRadians(shooterMotorRight.getVelocity().getValueAsDouble());
+ inputs.shooterSpeedLeft = Units.rotationsToRadians(shooterMotorLeft.getVelocity().getValueAsDouble()) * ShooterConstants.SHOOTER_LAUNCH_DIAMETER/2;
+ inputs.shooterSpeedRight = Units.rotationsToRadians(shooterMotorRight.getVelocity().getValueAsDouble())* ShooterConstants.SHOOTER_LAUNCH_DIAMETER/2;
Logger.processInputs("Shooter", inputs);
}
public static final InterpolatingDoubleTreeMap timeOfFlightMap = new InterpolatingDoubleTreeMap();
public static final InterpolatingDoubleTreeMap shooterPowerMap = new InterpolatingDoubleTreeMap();
public static final InterpolatingDoubleTreeMap hoodAngleMap = new InterpolatingDoubleTreeMap();
+
+ public static final InterpolatingDoubleTreeMap exitVelocityMap = new InterpolatingDoubleTreeMap();
static{
timeOfFlightMap.put(0.0, 0.67);
hoodAngleMap.put(0.0, Units.degreesToRadians(90));
hoodAngleMap.put(1.0, Units.degreesToRadians(90));
+
+ exitVelocityMap.put(1.0, 2.0);
+ exitVelocityMap.put(2.0, 4.0);
}
}
private static final double MAX_VEL_RAD_PER_SEC = 15;
//private static final double MAX_VEL_RAD_PER_SEC = 3.0; // Starting super duper slow for now
// private static final double MAX_ACCEL_RAD_PER_SEC2 = 160.0;
- private static final double MAX_ACCEL_RAD_PER_SEC2 = 60.0;
+ private static final double MAX_ACCEL_RAD_PER_SEC2 = 160.0;
private static final double GEAR_RATIO = TurretConstants.TURRET_GEAR_RATIO;
- private static final PIDController positionPID = new PIDController(15, 0, 0.25);
- private static final PIDController velocityPID = new PIDController(0.0, 0.0, 0.0);
+ private static final PIDController positionPID = new PIDController(15.0, 0, 0.0);
+ // private static final PIDController positionPID = new PIDController(15, 0, 0.25);
+ private static final PIDController velocityPID = new PIDController(0.2, 0.0, 0.0);
private final CANcoder encoderLeft = new CANcoder(0, Constants.SUBSYSTEM_CANIVORE_CAN);
private final CANcoder encoderRight = new CANcoder(1, Constants.SUBSYSTEM_CANIVORE_CAN);
private final MechanismLigament2d ligament = root.append(new MechanismLigament2d("barrel", 30, 0));
// private final SimpleMotorFeedforward feedForward = new SimpleMotorFeedforward(.1, 1. / DCMotor.getKrakenX60(1).KvRadPerSecPerVolt, 0.010);
- private final SimpleMotorFeedforward feedForward = new SimpleMotorFeedforward(0.1, 1. / DCMotor.getKrakenX60(1).KvRadPerSecPerVolt, 0);
+ private final SimpleMotorFeedforward feedForward = new SimpleMotorFeedforward(0.1, (1. / DCMotor.getKrakenX60(1).KvRadPerSecPerVolt) * 0.8, 0);
private final MotionMagicVoltage mmVoltageRequest = new MotionMagicVoltage(0);
/* ---------------- Constructor ---------------- */
public Turret() {
motor.setNeutralMode(NeutralModeValue.Coast);
- motor.getConfigurator().apply(
- new Slot0Configs()
- .withKP(kP)
- .withKD(kD));
+ // motor.getConfigurator().apply(
+ // new Slot0Configs()
+ // .withKP(kP)
+ // .withKD(kD));
TalonFXConfiguration config = new TalonFXConfiguration();
var motionMagicConfigs = config.MotionMagic;
double motorSetpointPosition = (setpoint.position) * GEAR_RATIO;
- targetVelocity = positionPID.calculate(
+ targetVelocity =
+ positionPID.calculate(
motor.getPosition().getValue().in(edu.wpi.first.units.Units.Radians),
motorSetpointPosition);
- //targetVelocity += Units.rotationsToRadians(motorVelRotPerSec); // TODO: Change this back after full rotation
- targetVelocity += Math.abs(setpoint.position) != Math.PI/2 ? Units.rotationsToRadians(motorVelRotPerSec) : 0;
+ targetVelocity += Units.rotationsToRadians(motorVelRotPerSec) * 1.0;
double voltage = feedForward.calculate(targetVelocity);
- double velocityCorrectionVoltage = velocityPID.calculate(Units.rotationsToRadians(motor.getVelocity().getValueAsDouble()), targetVelocity);
- voltage += velocityCorrectionVoltage;
+ // double velocityCorrectionVoltage = velocityPID.calculate(Units.rotationsToRadians(motor.getVelocity().getValueAsDouble()), targetVelocity);
+ // voltage += velocityCorrectionVoltage;
motor.setVoltage(voltage);
inputs.motorCurrent = motor.getStatorCurrent().getValueAsDouble();
inputs.encoderLeftRot = encoderLeft.getAbsolutePosition().getValueAsDouble();
inputs.encoderRightRot = encoderRight.getAbsolutePosition().getValueAsDouble();
+ inputs.motorVoltage = motor.getMotorVoltage().getValueAsDouble();
}
private double wrapUnit(double value) {