Skip to content

Elevating FRC Java Robot Simulations to the Next Level with Physics Engines

License

Notifications You must be signed in to change notification settings

BroncBotz3481/maple-sim

 
 

Repository files navigation

team logo project logo

Elevating FRC Java Robot Simulations to the Next Level with Physics Engines

Why a Physics Engine?

A simulation engine is a powerful tool that provides realistic approximations of physical systems. With maple-sim, we integrate the open-source Java rigid-body dynamics engine, dyn4j, capable of simulating 2D forces and collisions between rigid shapes. This integration transforms the scope of robot simulations by enabling realistic interactions between robots, field elements, and game pieces.

physics engine illustration

Before maple-sim, most FRC robot simulations focused solely on the robot itself—its sensors, movements, and internal operations. Now, through the power of physics simulation, maple-sim allows your robot to engage directly with its environment. Imagine testing robot interactions with obstacles, field elements, and game pieces, all within the simulated world. A simulation that is realistic enough to feel like a video game.

Demo Video 1

With this advanced level of simulation, the possibilities are endless. You can:

  • Test autonomous modes with pinpoint accuracy.
  • Fine-tune advanced TeleOp enhancement features like pathfinding-auto-alignment.
  • Optimize shooters and other subsystems, all while gathering meaningful data from simulated physics.

And the best part? You can achieve all of this without needing a real robot on hand.

Simulation Details

Swerve-Drive Simulation Dynamics with Interactive Field

The standout feature of this project is the integration of the dyn4j physics engine, which enables a highly realistic and interactive simulation environment.

In traditional swerve drive simulations, the drivetrain is typically modeled using several DCMotorSim instances to simulate motor behavior.

In maple-sim, the drivetrain simulation goes a step further by calculating the frictional and propelling forces on each swerve module. These forces are used to model the drivetrain as a rigid body, allowing for more accurate interaction with the field environment.

swerve drive dynamics.gif

The realistic simulation dynamics allow you to test and refine auto paths as they would perform in real-world conditions.

path following simulation.gif

Odometry + Vision Simulation

By modeling the interaction between the wheels and the floor, our simulation can replicate odometry measurement errors caused by skidding.

Additionally, the IMU simulation includes drift, where hard impacts on the virtual robot will cause the IMU to behave similarly to how it would in real-world scenarios.

Odometry Sim

Beyond odometry, you can integrate photonlib to simulate how vision-based odometry can correct your robot’s position.

vision simulation.gif

Game Pieces and Intake Simulation

In maple-sim, game pieces on the field have collision boundaries and can interact with the robot. The simulator also supports a fixed intake module, allowing the robot to automatically collect game pieces upon contact.

game pieces simulation.gif

intakesim.gif

Projectile Simulation

In FRC, game pieces are often launched into the air. maple-sim offers a straightforward physics simulation to model the behavior of these projectiles.

projectile simulation.gif

Opponent Robots Simulation

Simulated opponent robots can be manually controlled with a gamepad for defensive play or set to follow pre-programmed cycle paths. Just like real robots, these opponents have collision boundaries, enabling drivers to practice both defensive and offensive strategies effectively. opponentrobotsim.gif

Quick Start

Please see the following guides:

  1. Hardware Abstractions
  2. Installing maple-sim
  3. Using the Simulated Arena
  4. Simulating Swerve Drivetrain
  5. Simulating Intake
  6. Simulating Projectiles
  7. Simulating Opponent Robots

Examples and Templates

  1. Advanced Swerve Drive Project: 6328's swerve drive project utilizing AdvantageKit, modified to have advanced drivetrain simulations. The changelog from the original project is here.
  2. Maple-Swerve-Skeleton: Our custom swerve drive project based on Advanced Swerve Drive Project with drivetrain simulation, vision simulation and some convenient controlling features.
  3. 5516-2024-OffSeason-RobotCode: Our 2024 off-season robot code that implements a variety of advanced simulations. It can run on real robot and be played like a video game. Videos

❌ YAGSL is not yet supported since simulation is running inside the library instead of the user code.

About

Elevating FRC Java Robot Simulations to the Next Level with Physics Engines

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%