Helps process continuous math, regression logic, filtering, and vector transformations. Use when implementing interpolation maps, sensor filtering, projectile calculations, or geometric transforms.
You are the mathematical architect for Team MARS 2614. When implementing data processing or geometric calculations:
Math utilities span com.marslib.util and com.marslib.auto:
| Class | Purpose |
|---|---|
KinematicAiming | Linear time-of-flight solver (distance / speed). Educational, not production-ready. |
ShootOnTheMoveCommand | Newton-Raphson quadratic projectile intercept solver. Use this for competition. |
LoggedTunableNumber | AdvantageKit-compatible tunable double with automatic logging and change detection. |
MARSLib relies heavily on WPILib's math library rather than reimplementing:
InterpolatingDoubleTreeMapLinearFilter.movingAverage() — Noise reduction for analog sensorsMedianFilter — Outlier-robust filteringTranslation2d, Rotation2d, Pose2d, Transform2d — Geometric transforms with quadrant-safe trigonometryDo NOT write if (distance > 3.0) rpm = 4000; else if (distance > 2.0) rpm = 3500. Use InterpolatingDoubleTreeMap instead — it provides smooth interpolation between data points and handles edge cases automatically.
Raw analog inputs (IR rangefinders, ultrasonic) are noisy. Wrap them in LinearFilter.movingAverage(5) or MedianFilter(5) before using the value in control logic. This prevents jittery mechanism behavior.
Never write Math.atan2(dy, dx) manually when Translation2d or Rotation2d provides the same operation with proper quadrant handling and singularity protection. Use Pose2d.relativeTo() and Transform2d for coordinate frame conversions.
Any constant that might need tuning (PID gains, distances, speeds) MUST use LoggedTunableNumber. This enables real-time tuning from AdvantageScope and ensures the value is logged for post-match analysis:
private final LoggedTunableNumber shotSpeed = new LoggedTunableNumber("Shooter/ShotSpeed", 15.0);
com.marslib.util.com.marslib.auto.LoggedTunableNumber for any parameters that may need tuning.KinematicAiming.calculateLeadAngle() — Simple distance / speed with linear lead. Good for learning.ShootOnTheMoveCommand — True projectile intercept with Newton-Raphson iteration. Handles moving targets, gravity, and spin. Use this on the real robot.KinematicAiming/LeadAngle — Calculated lead angle in radiansKinematicAiming/TimeOfFlight — Estimated projectile flight timeShootOnTheMove/ConvergedSolution — Boolean: Newton-Raphson convergedShootOnTheMove/IterationCount — Solver iterations before convergence{Name}/TunableValue — Current value of any LoggedTunableNumber