Package frc.robot.sim

Class FuelSim

java.lang.Object
frc.robot.sim.FuelSim

public class FuelSim extends Object
Full-field fuel physics simulation for FRC 2026 REBUILT. Handles drag, Magnus lift, friction, fuel-fuel collisions, wall bounces, hub scoring, sleeping, CCD, and robot interaction. Single file, only depends on WPILib (wpimath + ntcore). Drop it into your sim and watch fuels fly.

Physics: symplectic Euler integration, 3D angular velocity for Magnus (omega x v cross product), Coulomb friction with spin transfer, sequential impulse collision solver with warm starting and Baumgarte stabilization. Spatial hashing for fuel-fuel broadphase. Fuel sleeping keeps 350+ resting fuels under 2ms/tick.

Usage:

 FuelSim fuelSim = new FuelSim("Sim/Fuel");
 fuelSim.enable();
 fuelSim.placeFieldFuels(); // spawns all the game pieces
 // in simulationPeriodic():
 fuelSim.configureRobot(width, length, bumperH, poseSupplier, speedsSupplier);
 fuelSim.tick(); // runs physics, publishes to NT
 
  • Constructor Details

    • FuelSim

      public FuelSim(String tableKey)
      New sim with default physics config. Publishes fuel positions to the given NT path.
      Parameters:
      tableKey - where to publish in NetworkTables (e.g. "Sim/Fuel")
    • FuelSim

      public FuelSim(String tableKey, FuelSim.PhysicsConfig config)
      New sim with custom physics config.
      Parameters:
      tableKey - where to publish in NetworkTables
      config - physics feature toggles and tuning
    • FuelSim

      public FuelSim()
      Default constructor, publishes to "Sim/FuelPositions".
  • Method Details

    • getInstance

      public static FuelSim getInstance()
      Returns a singleton instance of FuelSim
    • start

      public void start()
      Start the simulation. `tick` must still be called every loop
    • stop

      public void stop()
      Pause the simulation.
    • isRunning

      public boolean isRunning()
      Is the sim running?
    • registerRobot

      public void registerRobot(double width, double length, double bumperHeight, Supplier<Pose2d> poseSupplier, Supplier<ChassisSpeeds> speedsSupplier)
      Tell the sim about your robot so it can handle bumper collisions and intake pickup.
      Parameters:
      width - robot width along Y axis (m)
      length - robot length along X axis (m)
      bumperHeight - bumper height (m)
      poseSupplier - field-relative pose supplier
      speedsSupplier - field-relative chassis speeds supplier
    • registerIntake

      public void registerIntake(double xMin, double xMax, double yMin, double yMax, BooleanSupplier active, Runnable callback)
      Add an intake zone. Fuels that enter this box (in robot-relative coords) get picked up.
      Parameters:
      xMin - front edge in robot frame
      xMax - back edge in robot frame
      yMin - left edge in robot frame
      yMax - right edge in robot frame
      active - returns true when the intake is actually running
      callback - fires when a fuel gets picked up
    • registerIntake

      public void registerIntake(double xMin, double xMax, double yMin, double yMax, BooleanSupplier active)
      Add an intake zone without a callback.
    • launchFuel

      public void launchFuel(Translation3d pos, Translation3d vel, double spinRPM)
      Shoot a fuel into the sim.
      Parameters:
      pos - where the fuel leaves the launcher (field frame, meters)
      vel - launch velocity (field frame, m/s)
      spinRPM - backspin in RPM (positive = backspin = Magnus lift)
    • launchFuel

      public void launchFuel(Translation3d pos, Translation3d vel, Translation3d omega)
      Shoot a fuel with full 3D spin control.
      Parameters:
      pos - launch position (field frame, meters)
      vel - launch velocity (field frame, m/s)
      omega - 3D angular velocity (rad/s)
    • spawnFuel

      public void spawnFuel(Translation3d pos)
      Drop a fuel at this position, sitting on the ground.
    • spawnFuel

      public void spawnFuel(Translation3d pos, Translation3d vel)
      Drop a fuel with some initial velocity.
    • clearFuel

      public void clearFuel()
      Remove every fuel from the sim.
    • spawnStartingFuel

      public void spawnStartingFuel()
      Spawn all game pieces in their starting positions (neutral zone + depots).
    • tick

      public void tick()
      Step the sim forward one period (20ms) and publish fuel positions to NT. Does nothing if the sim isn't enabled.
    • advancePhysics

      public void advancePhysics(double dt)
      Advance physics by dt seconds. Splits into subticks for stability.
      Parameters:
      dt - time to advance (seconds)
    • publishPositions

      public void publishPositions()
      Push fuel positions and sim stats to NetworkTables for visualization.
    • getFuelCount

      public int getFuelCount()
      Returns the number of fuels in the simulation.
    • getFuelsInFlight

      public int getFuelsInFlight()
      Returns the number of fuels currently in flight.
    • getFuelsOnGround

      public int getFuelsOnGround()
      Returns the number of fuels on the ground.
    • getFuelPositions

      public List<Translation3d> getFuelPositions()
      Returns a list of all fuel positions.
    • getFuelVelocities

      public List<Translation3d> getFuelVelocities()
      Returns a list of all fuel velocities.
    • getFuelOmegas

      public List<Translation3d> getFuelOmegas()
      Returns a list of all fuel angular velocities.
    • getConfig

      public FuelSim.PhysicsConfig getConfig()
    • setConfig

      public void setConfig(FuelSim.PhysicsConfig config)
      Update physics config (e.g. to enable/disable features or change parameters).
    • setDeterministic

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

      public double getTotalKineticEnergy()
    • 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 FuelSim.ScoringTarget getBlueHub()
    • getRedHub

      public FuelSim.ScoringTarget getRedHub()
    • getSleepingFuelCount

      public int getSleepingFuelCount()
      Returns the number of sleeping fuels.
    • getFieldLength

      public static double getFieldLength()
    • getFieldWidth

      public static double getFieldWidth()
    • getFuelRadius

      public static double getFuelRadius()
    • getFuelMass

      public static double getFuelMass()
    • getMomentOfInertia

      public static double getMomentOfInertia()
    • getDragAccelFactor

      public static double getDragAccelFactor()
    • getMagnusAccelFactor

      public static double getMagnusAccelFactor()
    • getFieldCOR

      public static double getFieldCOR()
    • getFuelFuelCOR

      public static double getFuelFuelCOR()
    • resetCounters

      public void resetCounters()
      Resets all counters to their initial values.