Package frc.robot.sim
Class FuelSim
java.lang.Object
frc.robot.sim.FuelSim
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classOne fuel in the simulation.static classPhysics feature toggles.static classA hub that can be scored in. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadvancePhysics(double dt) Advance physics by dt seconds.voidRemove every fuel from the sim.intstatic doublestatic doublestatic doublestatic doubleintReturns the number of fuels in the simulation.static doublestatic doubleReturns a list of all fuel angular velocities.Returns a list of all fuel positions.static doubleintReturns the number of fuels currently in flight.intReturns the number of fuels on the ground.Returns a list of all fuel velocities.static FuelSimReturns a singleton instance of FuelSimdoublestatic doublestatic doubleintintReturns the number of sleeping fuels.intdoubleintdoubleintbooleanIs the sim running?voidlaunchFuel(Translation3d pos, Translation3d vel, double spinRPM) Shoot a fuel into the sim.voidlaunchFuel(Translation3d pos, Translation3d vel, Translation3d omega) Shoot a fuel with full 3D spin control.voidPush fuel positions and sim stats to NetworkTables for visualization.voidregisterIntake(double xMin, double xMax, double yMin, double yMax, BooleanSupplier active) Add an intake zone without a callback.voidregisterIntake(double xMin, double xMax, double yMin, double yMax, BooleanSupplier active, Runnable callback) Add an intake zone.voidregisterRobot(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.voidResets all counters to their initial values.voidsetConfig(FuelSim.PhysicsConfig config) Update physics config (e.g.voidsetDeterministic(long seed) Lock the RNG seed so tests are repeatable.voidspawnFuel(Translation3d pos) Drop a fuel at this position, sitting on the ground.voidspawnFuel(Translation3d pos, Translation3d vel) Drop a fuel with some initial velocity.voidSpawn all game pieces in their starting positions (neutral zone + depots).voidstart()Start the simulation.voidstop()Pause the simulation.voidtick()Step the sim forward one period (20ms) and publish fuel positions to NT.
-
Constructor Details
-
FuelSim
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
New sim with custom physics config.- Parameters:
tableKey- where to publish in NetworkTablesconfig- physics feature toggles and tuning
-
FuelSim
public FuelSim()Default constructor, publishes to "Sim/FuelPositions".
-
-
Method Details
-
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 supplierspeedsSupplier- 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 framexMax- back edge in robot frameyMin- left edge in robot frameyMax- right edge in robot frameactive- returns true when the intake is actually runningcallback- 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
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
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
Drop a fuel at this position, sitting on the ground. -
spawnFuel
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
Returns a list of all fuel positions. -
getFuelVelocities
Returns a list of all fuel velocities. -
getFuelOmegas
Returns a list of all fuel angular velocities. -
getConfig
-
setConfig
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
-
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
-
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.
-