Files
2026KPopRobotHunters/src/main/java/frc4388/robot/subsystems/shooter/ShooterConstants.java
T

143 lines
6.9 KiB
Java
Raw Normal View History

package frc4388.robot.subsystems.shooter;
2026-02-17 16:09:58 -07:00
import static edu.wpi.first.units.Units.RotationsPerSecond;
import com.ctre.phoenix6.configs.CurrentLimitsConfigs;
import com.ctre.phoenix6.configs.MotorOutputConfigs;
2026-01-27 19:15:37 -07:00
import com.ctre.phoenix6.configs.Slot0Configs;
import com.ctre.phoenix6.configs.TalonFXConfiguration;
import com.ctre.phoenix6.signals.NeutralModeValue;
2026-02-17 16:09:58 -07:00
import edu.wpi.first.units.measure.AngularVelocity;
2026-02-09 17:18:54 -08:00
import frc4388.utility.configurable.ConfigurableDouble;
import frc4388.utility.status.CanDevice;
2026-02-10 17:33:39 -08:00
public class ShooterConstants {
// Motor conversions
2026-01-27 19:15:37 -07:00
2026-03-19 14:21:46 -06:00
public static final double SHOOTERMOTOR_GEAR_RATIO = 1.286; // TODO: supposed to be 9 rotations in to 7 out -- 0.77 or 1.29
2026-04-02 18:27:51 -06:00
// public static final double INDEXER_GEAR_RATIO = 1.;
2026-03-07 20:08:15 -07:00
public static final double T_CONSTANT = 2;
2026-03-14 18:29:15 -06:00
public static final double SHOOTER_RADIUS = 2/39.37;
public static final double INDEXER_RADIUS = 0.625/39.37;
2026-02-20 20:59:06 -08:00
public static final ConfigurableDouble SHOOTER_MAX_VELOCITY = new ConfigurableDouble("Shooter MAX Velocity", 60);
2026-03-06 22:52:06 -07:00
public static final ConfigurableDouble SHOOTER_OVERRIDE_VELOCITY = new ConfigurableDouble("Shooter OVERRIDE Velocity", -42);
2026-03-06 10:57:47 -07:00
// public static final ConfigurableDouble SHOOTER_FEED_VELOCITY = new ConfigurableDouble("Shooter Feed Velocity", -35);
2026-02-24 13:50:30 -07:00
// public static final ConfigurableDouble SHOOTER_RESTING_VELOCITY = new ConfigurableDouble("Shooter Resting Velocity", 0.0);
2026-02-09 17:18:54 -08:00
2026-03-18 13:39:27 -06:00
2026-02-28 12:05:13 -07:00
public static final ConfigurableDouble SHOOTER_IDLE_PERCENT_OUTPUT = new ConfigurableDouble("Shooter idle % output", -0.15);
2026-02-25 17:34:24 -07:00
// public static final ConfigurableDouble SHOOTER_IDLE_TARGET_VEL = new ConfigurableDouble("Shooter idle target velocity", 20.);
// public static final ConfigurableDouble SHOOTER_IDLE_MAX_CURRENT = new ConfigurableDouble("Shooter Idle max current", 10);
2026-02-24 13:50:30 -07:00
2026-02-20 20:59:06 -08:00
public static final ConfigurableDouble INDEXER_FORWARD_OUTPUT = new ConfigurableDouble("Indexer FWD % Output", -0.4);
2026-03-20 15:40:07 -06:00
public static final ConfigurableDouble INDEXER_REVERSE_OUTPUT = new ConfigurableDouble("Indexer reverse % Output", 0.2);
2026-03-19 14:21:46 -06:00
public static final ConfigurableDouble MODEL_TRIM = new ConfigurableDouble("TRIM SHOOTER SPEED", 0);
2026-02-10 18:42:47 -08:00
2026-02-24 13:50:30 -07:00
2026-03-20 20:01:06 -06:00
public static final ConfigurableDouble NEG_OFFSET = new ConfigurableDouble("Negative offset", 8.);
public static final ConfigurableDouble POS_OFFSET = new ConfigurableDouble("Positive offset", 8.);
2026-03-20 15:40:07 -06:00
2026-03-21 13:38:34 -06:00
public static final ConfigurableDouble AIM_LEAD_TIME = new ConfigurableDouble("Aim lead time", -1.1);
2026-02-17 16:09:58 -07:00
// Shoot mode tolerances
2026-02-21 12:54:16 -08:00
public static final ConfigurableDouble ROBOT_MIN_HUB = new ConfigurableDouble("Shoot min dist M", 1.8);
public static final ConfigurableDouble ROBOT_MAX_HUB = new ConfigurableDouble("Shoot max dist M", 4.8);
2026-02-10 18:42:47 -08:00
2026-03-21 13:04:40 -06:00
public static final ConfigurableDouble AIM_ANGLE = new ConfigurableDouble("Aim angle tolerance", 15);
public static final ConfigurableDouble ROBOT_ANG_TOLERANCE = new ConfigurableDouble("Ang tolerance DEG", 360);
2026-02-10 18:42:47 -08:00
public static final ConfigurableDouble ROBOT_SPEED_TOLERANCE = new ConfigurableDouble("Speed tolerance MS", 1);
public static final ConfigurableDouble ROBOT_ANG_SPEED_TOLERANCE = new ConfigurableDouble("Shoot Ang speed tolerance DEG", 3);
2026-02-10 18:42:47 -08:00
2026-02-21 12:54:16 -08:00
public static final ConfigurableDouble SHOOTER_SPEED_TOLERANCE = new ConfigurableDouble("Shooter speed tolerance RPS", 3);
2026-02-10 18:42:47 -08:00
2026-02-17 16:09:58 -07:00
//
2026-03-20 15:40:07 -06:00
public static AngularVelocity getTargetShooterSpeed(double hubDistMeters, double chassisXSpeed) {
double speed = 0;
if (Math.abs(chassisXSpeed) < 0.1){
speed = 0.0593402*hubDistMeters*hubDistMeters +
2026-03-19 14:21:46 -06:00
4.90561*hubDistMeters +
30.35696 + MODEL_TRIM.get();
2026-03-20 15:40:07 -06:00
} else if (chassisXSpeed > 0){
speed = 0.0593402*hubDistMeters*hubDistMeters +
4.90561*hubDistMeters +
2026-03-20 20:01:06 -06:00
30.35696 + chassisXSpeed * POS_OFFSET.get() + MODEL_TRIM.get();
2026-03-20 15:40:07 -06:00
} else { // Negative is closer to hub
speed = 0.0593402*hubDistMeters*hubDistMeters +
4.90561*hubDistMeters +
2026-03-20 20:01:06 -06:00
30.35696 + chassisXSpeed * NEG_OFFSET.get() + MODEL_TRIM.get();
2026-03-20 15:40:07 -06:00
}
2026-02-20 20:59:06 -08:00
double max = SHOOTER_MAX_VELOCITY.get();
2026-02-17 16:09:58 -07:00
2026-02-20 20:59:06 -08:00
// Clamp speed to max
if(speed > max) {
speed = max;
} else if(speed < -max) {
speed = -max;
}
2026-02-21 12:54:16 -08:00
// double speed = SHOOTER_MAX_VELOCITY.get();
2026-02-20 20:59:06 -08:00
return RotationsPerSecond.of(-speed);
2026-02-17 16:09:58 -07:00
}
2026-01-29 18:07:19 -07:00
2026-02-17 16:09:58 -07:00
// Motor Configuration
2026-01-27 19:15:37 -07:00
public static Slot0Configs SHOOTER_PID = new Slot0Configs()
.withKV(0.0)
2026-03-19 18:32:02 -06:00
.withKP(0.02)
.withKI(0.15)
2026-02-20 20:59:06 -08:00
.withKD(0.0);
2026-01-27 19:15:37 -07:00
2026-02-09 18:38:55 -08:00
2026-02-17 18:53:26 -08:00
2026-02-09 18:38:55 -08:00
2026-03-19 18:32:02 -06:00
public static ConfigurableDouble shooter_kP = new ConfigurableDouble("Shooter KP", 0.02);
2026-02-21 12:54:16 -08:00
public static ConfigurableDouble shooter_kI = new ConfigurableDouble("Shooter KI", 0.15);
2026-02-09 18:38:55 -08:00
public static ConfigurableDouble shooter_kD = new ConfigurableDouble("Shooter KD", 0);
2026-02-09 17:18:54 -08:00
2026-02-07 14:51:05 -07:00
2026-02-09 17:18:54 -08:00
public static final CanDevice SHOOTER1_ID = new CanDevice("SHOOTER 1", 22);
public static final CanDevice SHOOTER2_ID = new CanDevice("SHOOTER 2", 23);
public static final CanDevice INDEXER_ID = new CanDevice("INDEXER",24);
2026-01-27 18:13:51 -07:00
public static final TalonFXConfiguration SHOOTER1_MOTOR_CONFIG = new TalonFXConfiguration()
.withCurrentLimits(
new CurrentLimitsConfigs()
.withStatorCurrentLimit(40) // TODO: tune???
.withStatorCurrentLimitEnable(true)
).withMotorOutput(
new MotorOutputConfigs()
2026-02-09 17:18:54 -08:00
.withNeutralMode(NeutralModeValue.Coast) // Must be coast because this is spinny spinny
2026-04-02 18:27:51 -06:00
.withDutyCycleNeutralDeadband(0.04) // This sets the minimum output of motor so if its less than 4% it wont move
);
2026-01-27 18:13:51 -07:00
public static final TalonFXConfiguration SHOOTER2_MOTOR_CONFIG = new TalonFXConfiguration()
.withCurrentLimits(
new CurrentLimitsConfigs()
.withStatorCurrentLimit(40) // TODO: tune???
.withStatorCurrentLimitEnable(true) // TODO: Figure out what this means
).withMotorOutput(
new MotorOutputConfigs()
.withNeutralMode(NeutralModeValue.Coast) // Must be coast because this is spinny spinny
2026-04-02 18:27:51 -06:00
.withDutyCycleNeutralDeadband(0.04) // This sets the minimum output of motor so if its less than 4% it wont move
);
2026-02-09 17:18:54 -08:00
2026-01-27 18:13:51 -07:00
public static final TalonFXConfiguration INDEXER_MOTOR_CONFIG = new TalonFXConfiguration()
.withCurrentLimits(
new CurrentLimitsConfigs()
.withStatorCurrentLimit(40) // TODO: tune???
.withStatorCurrentLimitEnable(true)
).withMotorOutput(
new MotorOutputConfigs()
.withNeutralMode(NeutralModeValue.Coast) // Must be coast because this is spinny spinny
2026-04-02 18:27:51 -06:00
.withDutyCycleNeutralDeadband(0.04) // This sets the minimum output of motor so if its less than 4% it wont move
);
}