Simulation-Driven Design with WPILib Physics Models
Validate a mechanism before cutting metal using WPILib's physics sim classes (DCMotor, ElevatorSim, SingleJointedArmSim, FlywheelSim) and CAD-derived inputs.
Sign in to track progress, earn XP, and save lessons.
Design it, then prove it, before you build it
Top teams validate mechanisms in CAD and simulation before committing material and time. WPILib ships physics simulation classes that model your mechanism from real inputs: motor type/count, gear ratio, mass or moment of inertia, and travel.
The building block: DCMotor
Everything starts with a DCMotor model that encodes a real motor's stall torque, free speed, and stall current. For example, DCMotor.getNEO(1) or DCMotor.getKrakenX60(2) describes the motor(s) driving your mechanism, the same published curves you used to size the reduction (NEO Vortex: 6784 RPM free, 3.6 Nm stall; Kraken X60: 6000 RPM free trapezoidal, 7.09 Nm stall).
Mechanism models
ElevatorSim(motor, gearing, carriageMassKg, drumRadiusM, minHeightM, maxHeightM, simulateGravity, startingHeight, ...)— predicts whether your motor count and ratio can actually lift the carriage and how fast.SingleJointedArmSim(motor, gearing, jKgMetersSquared, armLengthM, minAngle, maxAngle, simulateGravity, startingAngle, ...)— checks if your arm can hold and move under gravity.FlywheelSim— predicts spin-up time and recovery for a shooter.
Getting the inputs from CAD
The key advanced move: pull moment of inertia (MOI) and center of mass straight from your Onshape/CAD model's mass properties instead of estimating. FRC teams combine free-body diagrams with CAD mass data to compute net torque and validate a mechanism, exactly the workflow case-study teams document. Garbage MOI in = misleading sim out, so model the real materials and parts.
A validation loop
- Size reduction by hand (torque math).
- Build the CAD; read MOI/CoM from mass properties.
- Plug into the matching WPILib sim class.
- Command a profile and watch: does it hold? Does it reach the setpoint in time? Does current stay under your limit?
- If it fails in sim, change the ratio/motor count/mass before cutting metal.
Why this wins
Simulation catches under-geared mechanisms, over-current designs, and impossible motion-profile targets in minutes, not after a week of fabrication. It also lets programmers develop and tune control code against a realistic model before the mechanism physically exists, so software is ready when hardware arrives.
Caveats
Sim models friction crudely; real kS will differ. Treat sim as a design filter and a software head-start, then confirm on hardware with SysId. The combination, CAD mass properties feeding a physics sim, then SysId on the real build, is how strong teams arrive at competition with mechanisms that already work.
Key takeaways
- WPILib sim classes (ElevatorSim, SingleJointedArmSim, FlywheelSim) validate motor count, gear ratio, and mass before fabrication.
- Pull moment of inertia and center of mass from CAD mass properties so the simulation reflects the real mechanism.
- Use sim as a design filter and a software head-start, then confirm friction-dependent terms (kS) on hardware with SysId.
Go deeper
Lesson quiz
RequiredAnswer all 3 questions correctly to complete this lesson.
1.In WPILib physics simulation, which class does the differential drivetrain simulator NOT inherit from, unlike the other mechanism sims?
2.What does WPILib's BatterySim class model during simulation?
3.How do ElevatorSim and SingleJointedArmSim extend the base linear-system model?
Answer every question to submit.