Package frc.rebuilt
Class FuelPhysicsSim
java.lang.Object
frc.rebuilt.FuelPhysicsSim
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classPhysics feature toggles, for isolating terms when debugging.static classstatic class -
Constructor Summary
ConstructorsConstructorDescriptionPublishes to"Sim/FuelPositions".FuelPhysicsSim(String tableKey) FuelPhysicsSim(String tableKey, FuelPhysicsSim.PhysicsConfig config) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddIntakeZone(double xMin, double xMax, double yMin, double yMax, BooleanSupplier active) voidaddIntakeZone(double xMin, double xMax, double yMin, double yMax, BooleanSupplier active, Runnable callback) voidadvancePhysics(double dt) voidvoidconfigureRobot(double width, double length, double bumperHeight, int hopperSize, Supplier<Pose2d> poseSupplier, Supplier<ChassisSpeeds> speedsSupplier) voidconfigureRobot(double width, double length, double bumperHeight, Supplier<Pose2d> poseSupplier, Supplier<ChassisSpeeds> speedsSupplier) voiddisable()voidenable()Turns the sim on.static doubleintstatic doublestatic doubleintintintstatic doublestatic doublestatic doublestatic doubledoublestatic doublestatic doubleintintintdoubleTranslational and rotational kinetic energy, in joules.intdoubleintbooleanvoidlaunchBall(Translation3d pos, Translation3d vel, double spinRPM) voidlaunchBall(Translation3d pos, Translation3d vel, Translation3d omega) voidSpawns the neutral zone and both depot grids at their starting positions.voidvoidvoidvoidsetDeterministic(long seed) Lock the RNG seed so tests are repeatable.voidspawnBall(Translation3d pos) voidspawnBall(Translation3d pos, Translation3d vel) voidtick()Advances one period and publishes ball positions.
-
Constructor Details
-
FuelPhysicsSim
- Parameters:
tableKey- where to publish in NetworkTables, for example"Sim/Fuel"
-
FuelPhysicsSim
-
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 robothopperSize- capacity; intake stops once the robot holds this manyposeSupplier- field-relative pose supplierspeedsSupplier- 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
- 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
- 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
-
spawnBall
-
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
-
getBallVelocities
-
getBallOmegas
-
getConfig
-
setConfig
-
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
-
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
-
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()
-