Understanding closed-loop control through equations alone can be difficult. Visual simulators provide real-time feedback on how controller gains affect setpoint tracking, disturbance rejection, and stability.
Live In-Browser Simulator
Section titled “Live In-Browser Simulator”Experiment with feedforward and feedback gains below. Observe how changing (gravity), (velocity), (friction), (spring pull), and (damping) changes the response curve.
Closed-Loop PID & Feedforward Simulator
Recommended Experiments in the Simulator:
Section titled “Recommended Experiments in the Simulator:”- The Gravity Droop Test (“Untuned Elevator” Preset):
- Select the Elevator: Pure P (Gravity Sag Error) preset.
- Notice that with and zero feedforward (), the elevator stalls significantly below the target setpoint.
- Gradually increase Gravity Feedforward () to
1.20 V. Watch the elevator rise to the target setpoint without modifying .
- The Integral Windup Demonstration (“High kI” Preset):
- Select Elevator: High kI (Severe Integral Windup).
- Notice how accumulated historical error creates a voltage spike that overshoots the target, resulting in sluggish, ringing oscillations.
- The Disturbance Rejection Test:
- With the Elevator: Tuned PID + kG preset running, click Apply Disturbance Force (simulating game-piece contact or defense).
- Observe how and catch the carriage and return it stably to the setpoint.
- Velocity Feedforward on Flywheels (“Tuned Flywheel” Preset):
- Select the flywheel presets to see why provides instantaneous response at high rotational speeds without motor lag.
External Simulator: PID Playground
Section titled “External Simulator: PID Playground”For additional multi-physics experiments, we also recommend PID Playground (pidexplained.com) as a companion resource.
Key Concepts to Explore:
Section titled “Key Concepts to Explore:”- Proportional Gain ():
- Start with . Increase gradually until the mechanism responds toward the setpoint.
- Observe the persistent steady-state error when friction or gravity opposes the system.
- Derivative Gain ():
- Add to counteract oscillation and overshoot.
- Notice how derivative gain acts like a virtual damper or shock absorber.
- Feedforward ():
- Observe why adding feedforward eliminates steady-state error without needing aggressive integral gain ().
- Integral Windup ():
- See how slowly accumulates error, and observe the overshoot when integral windup is not constrained.
Before tuning an elevator or flywheel in Phoenix Tuner X, spend 10 minutes in the simulator tuning a system. Notice how adding feedforward dramatically reduces the required proportional gain.
WPILib Desktop Simulation (SimGUI)
Section titled “WPILib Desktop Simulation (SimGUI)”WPILib includes built-in physics simulation for flywheels, elevators, single-jointed arms, and drivetrains:
- Launch Command: In VS Code, press Ctrl + Shift + P and select WPILib: Simulate Robot Code on Desktop.
- Keyboard & Gamepad Emulation: Connect an Xbox controller to your PC to test teleop driving and button triggers without needing physical robot hardware.
- Mechanism2d Visualization: View 2D representations of moving elevators and rotating arms rendered in real time.