Class ShooterCalculator
java.lang.Object
com.flarerobotics.lib.control.shooter.ShooterCalculator
Calculates the optimal shooter parameters (angle, wheel speed, yaw) for hitting a target.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic double
The default tolerance for the projectile target in meters.static double
The number of maximum iterations for dynamic motion move solve.static double
The RPM threshold for convergence in dynamic motion solve.static double
The time threshold for convergence in dynamic motion solve.static double
The maximum noise in the roll (X axis rotation) for projectile visualization.static List<ProjectileTarget>
The list of projectile targets to use for trajectory visualization.static double
The maximum time-of-flight to simulate for a given object.static double
A constant velocity to apply when the velocity is too low to avoid the projectile getting stuck.static double
The threshold to apply the velocity compensation. -
Constructor Summary
ConstructorsConstructorDescriptionShooterCalculator
(LibShooterDescriptor descriptor) Constructs a new ShooterCalculator with the given descriptor. -
Method Summary
Modifier and TypeMethodDescriptioncalculateDynamic
(edu.wpi.first.math.geometry.Pose3d robotPose, edu.wpi.first.math.geometry.Pose3d targetPose, double currentRPM, ShooterProjectileType projectile, edu.wpi.first.math.kinematics.ChassisSpeeds speeds, double aXMeters, double aYMeters, double aThetaRads) Calculates a shooter state based on the provided parameters, accounting for dynamic motion.static List<ShooterProjectile>
updateVisualizer
(String loggerKey, List<ShooterProjectile> list) Updates the projectile trajectory visualizer using AdvantageScope.
-
Field Details
-
kDynamicMoveSolveIterations
public static double kDynamicMoveSolveIterationsThe number of maximum iterations for dynamic motion move solve. -
kDynamicMoveSolveRPMThreshold
public static double kDynamicMoveSolveRPMThresholdThe RPM threshold for convergence in dynamic motion solve. -
kDynamicMoveSolveTimeThreshold
public static double kDynamicMoveSolveTimeThresholdThe time threshold for convergence in dynamic motion solve. -
kMaxRollNoiseRad
public static double kMaxRollNoiseRadThe maximum noise in the roll (X axis rotation) for projectile visualization. Do not increase too much due to it causing choppy rotation. Uses radians as the unit of angle. -
kProjectileTargets
The list of projectile targets to use for trajectory visualization. -
kDefaultProjectileTolerance
public static double kDefaultProjectileToleranceThe default tolerance for the projectile target in meters. -
kTrajectoryMaxTime
public static double kTrajectoryMaxTimeThe maximum time-of-flight to simulate for a given object. -
kVelocityEpsilon
public static double kVelocityEpsilonA constant velocity to apply when the velocity is too low to avoid the projectile getting stuck. -
kVelocityEpsilonThreshold
public static double kVelocityEpsilonThresholdThe threshold to apply the velocity compensation.
-
-
Constructor Details
-
ShooterCalculator
Constructs a new ShooterCalculator with the given descriptor.Note: The descriptors must be set via
LibShooterDescriptor.Builder
's dataSet methods. Otherwise throws an exception.- Parameters:
descriptor
- The shooter subsystem descriptor containing physical parameters and interpolators.- Throws:
IllegalArgumentException
- If the interpolators are not defined.
-
-
Method Details
-
calculateDynamic
public ShooterState calculateDynamic(edu.wpi.first.math.geometry.Pose3d robotPose, edu.wpi.first.math.geometry.Pose3d targetPose, double currentRPM, ShooterProjectileType projectile, edu.wpi.first.math.kinematics.ChassisSpeeds speeds, double aXMeters, double aYMeters, double aThetaRads) Calculates a shooter state based on the provided parameters, accounting for dynamic motion. Put zero for the kinematics parameters to calculate static state.Note: The method may be slightly performance intensive if called periodically.
Note: The turret yaw assumes left is positive, as per WPILib coordinate systems. Negate the angle if your turret uses right as positive.
- Parameters:
robotPose
- The field-relative current robot pose.targetPose
- The field-relative target pose.currentRPM
- The current angular velocity of the shooter in RPM.projectile
- The projectile instance being shot.speeds
- The field-relative chassis speeds of the robot.aXMeters
- The field-relative acceleration along the X axis (m/s^2).aYMeters
- The field-relative acceleration along the Y axis (m/s^2).aThetaRads
- The field-relative angular acceleration (rad/s^2).- Returns:
- The computed shooter state.
-
updateVisualizer
public static List<ShooterProjectile> updateVisualizer(String loggerKey, List<ShooterProjectile> list) Updates the projectile trajectory visualizer using AdvantageScope. Logs the values to the given logger key. If performance intensive, move to a Notifier thread.- Parameters:
loggerKey
- The key to put the projectiles' positions into.list
- The list of projectiles to simulate.- Returns:
- The updated list, removing all ended projectiles.
-