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

120 lines
5.2 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-02-14 14:03:32 -08:00
public static final double SHOOTERMOTOR_GEAR_RATIO = 1.5;
2026-01-27 18:13:51 -07:00
public static final double INDEXER_GEAR_RATIO = 1.;
2026-01-29 18:07:19 -07:00
2026-02-21 12:54:16 -08:00
// public static final ConfigurableDouble SHOOTER_ACTIVE_VELOCITY = new ConfigurableDouble("Shooter Active Velocity", -40);
2026-02-20 20:59:06 -08:00
public static final ConfigurableDouble SHOOTER_MAX_VELOCITY = new ConfigurableDouble("Shooter MAX Velocity", 60);
2026-02-19 18:55:00 -08:00
public static final ConfigurableDouble SHOOTER_RESTING_VELOCITY = new ConfigurableDouble("Shooter Resting Velocity", 0.0);
2026-02-09 17:18:54 -08:00
2026-02-20 20:59:06 -08:00
public static final ConfigurableDouble INDEXER_FORWARD_OUTPUT = new ConfigurableDouble("Indexer FWD % Output", -0.4);
2026-02-19 18:55:00 -08:00
public static final ConfigurableDouble INDEXER_REVERSE_OUTPUT = new ConfigurableDouble("Indexer reverse % Output", 0.0);
2026-02-10 18:42:47 -08:00
public static final ConfigurableDouble AIM_LEAD_TIME = new ConfigurableDouble("Aim lead time", 0);
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
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
//
public static AngularVelocity getTargetShooterSpeed(double hubDistMeters) {
2026-02-20 20:59:06 -08:00
// Model derived from points
2026-02-21 12:54:16 -08:00
// double speed =
// 1.11576*hubDistMeters*hubDistMeters +
// 0.318464*hubDistMeters +
// 30.6293;
2026-02-20 20:59:06 -08:00
double speed =
2026-02-21 12:54:16 -08:00
5.6939*hubDistMeters +
22.76545;
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-02-20 20:59:06 -08:00
.withKP(0.08)
2026-02-21 12:54:16 -08:00
.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-02-14 14:03:32 -08:00
public static ConfigurableDouble shooter_kP = new ConfigurableDouble("Shooter KP", 0.08);
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
.withDutyCycleNeutralDeadband(0.04) // TODO: Figure out what this means
);
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
.withDutyCycleNeutralDeadband(0.04) // TODO: Figure out what this means
);
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
.withDutyCycleNeutralDeadband(0.04) // TODO: Figure out what this means
);
}