Package frc.rebuilt

Class FuelPhysicsSim

java.lang.Object
frc.rebuilt.FuelPhysicsSim

public class FuelPhysicsSim extends Object
Simulates fuel on the 2026 REBUILT field. Depends only on WPILib, so it drops into any sim harness.

Symplectic Euler integration, sequential impulse contacts with warm starting and Baumgarte stabilization, spatial hash broadphase, and ball sleeping. Sleeping keeps 350 or more resting balls under 2 ms per tick.

  • Constructor Details

    • FuelPhysicsSim

      public FuelPhysicsSim(String tableKey)
      Parameters:
      tableKey - where to publish in NetworkTables, for example "Sim/Fuel"
    • FuelPhysicsSim

      public FuelPhysicsSim(String tableKey, FuelPhysicsSim.PhysicsConfig config)
    • FuelPhysicsSim

      public FuelPhysicsSim()
      Publishes to "Sim/FuelPositions".
  • Method Details

    • enable

      public void enable()
      Turns the sim on. tick() must still be called every cycle.
    • disable

      public void disable()
    • isRunning

      public boolean isRunning()
    • configureRobot

      public void configureRobot(double width, double length, double bumperHeight, int hopperSize, Supplier<Pose2d> poseSupplier, Supplier<ChassisSpeeds> speedsSupplier)
      Parameters:
      width - robot width along the Y axis (m)
      length - robot length along the X axis (m)
      bumperHeight - bumper height (m); balls above it ignore the robot
      hopperSize - capacity; intake stops once the robot holds this many
      poseSupplier - field-relative pose supplier
      speedsSupplier - field-relative chassis speeds supplier
    • configureRobot

      public void configureRobot(double width, double length, double bumperHeight, Supplier<Pose2d> poseSupplier, Supplier<ChassisSpeeds> speedsSupplier)
    • addIntakeZone

      public void addIntakeZone(double xMin, double xMax, double yMin, double yMax, BooleanSupplier active, Runnable callback)
      Parameters:
      xMin - front edge in the robot frame (m)
      xMax - back edge in the robot frame (m)
      yMin - left edge in the robot frame (m)
      yMax - right edge in the robot frame (m)
    • addIntakeZone

      public void addIntakeZone(double xMin, double xMax, double yMin, double yMax, BooleanSupplier active)
    • launchBall

      public void launchBall(Translation3d pos, Translation3d vel, double spinRPM)
      Parameters:
      pos - where the ball leaves the launcher, field frame (m)
      vel - launch velocity, field frame (m/s)
      spinRPM - positive is backspin, which lifts the ball through the Magnus effect
    • launchBall

      public void launchBall(Translation3d pos, Translation3d vel, Translation3d omega)
      Parameters:
      pos - where the ball leaves the launcher, field frame (m)
      vel - launch velocity, field frame (m/s)
      omega - 3D angular velocity (rad/s); negative Y is backspin
    • spawnBall

      public void spawnBall(Translation3d pos)
    • spawnBall

      public void spawnBall(Translation3d pos, Translation3d vel)
    • clearBalls

      public void clearBalls()
    • placeFieldBalls

      public void placeFieldBalls()
      Spawns the neutral zone and both depot grids at their starting positions.
    • tick

      public void tick()
      Advances one period and publishes ball positions. No-op while disabled.
    • advancePhysics

      public void advancePhysics(double dt)
      Parameters:
      dt - seconds to advance
    • publishPositions

      public void publishPositions()
    • getBallCount

      public int getBallCount()
    • getBallsInFlight

      public int getBallsInFlight()
    • getBallsOnGround

      public int getBallsOnGround()
    • getBallPositions

      public List<Translation3d> getBallPositions()
    • getBallVelocities

      public List<Translation3d> getBallVelocities()
    • getBallOmegas

      public List<Translation3d> getBallOmegas()
    • getConfig

      public FuelPhysicsSim.PhysicsConfig getConfig()
    • setConfig

      public void setConfig(FuelPhysicsSim.PhysicsConfig config)
    • setDeterministic

      public void setDeterministic(long seed)
      Lock the RNG seed so tests are repeatable.
    • getTotalKineticEnergy

      public double getTotalKineticEnergy()
      Translational and rotational kinetic energy, in joules.
    • getTotalPotentialEnergy

      public double getTotalPotentialEnergy()
    • getTotalMomentum

      public Translation3d getTotalMomentum()
    • getTotalLaunched

      public int getTotalLaunched()
    • getTotalScored

      public int getTotalScored()
    • getTotalIntaked

      public int getTotalIntaked()
    • getLastLaunchSpeed

      public double getLastLaunchSpeed()
    • getBlueScore

      public int getBlueScore()
    • getRedScore

      public int getRedScore()
    • getBlueHub

      public FuelPhysicsSim.ScoringTarget getBlueHub()
    • getRedHub

      public FuelPhysicsSim.ScoringTarget getRedHub()
    • getSleepingBallCount

      public int getSleepingBallCount()
    • getFieldLength

      public static double getFieldLength()
    • getFieldWidth

      public static double getFieldWidth()
    • getBallRadius

      public static double getBallRadius()
    • getBallMass

      public static double getBallMass()
    • getMomentOfInertia

      public static double getMomentOfInertia()
    • getDragAccelFactor

      public static double getDragAccelFactor()
    • getMagnusAccelFactor

      public static double getMagnusAccelFactor()
    • getFieldCOR

      public static double getFieldCOR()
    • getBallBallCOR

      public static double getBallBallCOR()
    • resetCounters

      public void resetCounters()