Class ShooterCalculator

java.lang.Object
com.flarerobotics.lib.control.shooter.ShooterCalculator

public class ShooterCalculator extends Object
Calculates the optimal shooter parameters (angle, wheel speed, yaw) for hitting a target.
  • Field Details

    • kDynamicMoveSolveIterations

      public static double kDynamicMoveSolveIterations
      The number of maximum iterations for dynamic motion move solve.
    • kDynamicMoveSolveRPMThreshold

      public static double kDynamicMoveSolveRPMThreshold
      The RPM threshold for convergence in dynamic motion solve.
    • kDynamicMoveSolveTimeThreshold

      public static double kDynamicMoveSolveTimeThreshold
      The time threshold for convergence in dynamic motion solve.
    • kMaxRollNoiseRad

      public static double kMaxRollNoiseRad
      The 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

      public static List<ProjectileTarget> kProjectileTargets
      The list of projectile targets to use for trajectory visualization.
    • kDefaultProjectileTolerance

      public static double kDefaultProjectileTolerance
      The default tolerance for the projectile target in meters.
    • kTrajectoryMaxTime

      public static double kTrajectoryMaxTime
      The maximum time-of-flight to simulate for a given object.
    • kVelocityEpsilon

      public static double kVelocityEpsilon
      A constant velocity to apply when the velocity is too low to avoid the projectile getting stuck.
    • kVelocityEpsilonThreshold

      public static double kVelocityEpsilonThreshold
      The threshold to apply the velocity compensation.
  • Constructor Details

    • ShooterCalculator

      public ShooterCalculator(LibShooterDescriptor descriptor)
      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.