PID Control Documentation
Overview
PID (Proportional-Integral-Derivative) control is a feedback control mechanism used in our robot's motion control system. LemLib implements PID controllers for both lateral (forward/backward) and angular (turning) movements.
Current PID Settings
Lateral Controller (Forward/Backward Movement)
lemlib::ControllerSettings lateral_controller(
10, // kP - Proportional gain
0, // kI - Integral gain
3, // kD - Derivative gain
3, // Anti-windup
1, // Small error range (inches)
100, // Small error timeout (ms)
3, // Large error range (inches)
500, // Large error timeout (ms)
20 // Maximum acceleration (slew)
);
Angular Controller (Turning)
lemlib::ControllerSettings angular_controller(
2, // kP - Proportional gain
0, // kI - Integral gain
10, // kD - Derivative gain
3, // Anti-windup
1, // Small error range (degrees)
100, // Small error timeout (ms)
3, // Large error range (degrees)
500, // Large error timeout (ms)
0 // Maximum acceleration (slew)
);
PID Components Explained
Proportional (P)
- What it does: Provides output proportional to the current error
- Effect: Higher values = more aggressive response to error
- Tuning: Start low and increase until oscillation begins
Integral (I)
- What it does: Accumulates error over time to eliminate steady-state error
- Effect: Helps reach exact target but can cause overshoot
- Tuning: Usually kept at 0 or very low values in FRC/VEX
Derivative (D)
- What it does: Predicts future error based on rate of change
- Effect: Reduces overshoot and oscillation
- Tuning: Add after P is tuned to smooth response
Tuning Guidelines
Step-by-Step Tuning Process
- Start with P only (I=0, D=0)
- Increase P until robot oscillates around target
- Reduce P slightly to eliminate oscillation
- Add D to reduce overshoot and smooth response
- Add I only if steady-state error exists (rare in VEX)
Common Issues and Solutions
Problem | Likely Cause | Solution |
---|---|---|
Robot overshoots target | P too high | Reduce P, add D |
Robot doesn't reach target | P too low | Increase P |
Robot oscillates | P too high, D too low | Reduce P, increase D |
Slow response | P too low | Increase P |
Steady-state error | Need integral action | Add small I value |
Testing and Validation
Recommended Tests
- Step Response: Move robot 24 inches forward
- Turn Test: Rotate robot 90 degrees
- Repeatability: Run same movement 10 times
- Different Distances: Test 12", 24", 48" movements
Performance Metrics
- Settling Time: Time to reach and stay within ±1" of target
- Overshoot: Maximum distance past target
- Steady-State Error: Final error after settling
- Rise Time: Time to reach 90% of target
Advanced Features
Anti-Windup
- Prevents integral term from growing too large
- Set to 3 in our configuration
- Helps prevent overshoot when changing directions
Error Ranges
- Small Error Range: Tolerance for "close enough" (1" or 1°)
- Large Error Range: Tolerance for major corrections (3" or 3°)
- Timeouts: Maximum time to spend in each error range
Slew Rate Limiting
- Lateral: 20 units/second maximum acceleration
- Angular: 0 (disabled) for turning
- Prevents wheel slipping and mechanical stress
Code Integration
The PID controllers are integrated into the chassis object:
lemlib::Chassis chassis(
drivetrain, // drivetrain settings
lateral_controller, // lateral PID settings
angular_controller, // angular PID settings
sensors // odometry sensors
);
Future Improvements
- Tune PID values through testing
- Implement feedforward control
- Add velocity PID for smoother motion
- Create automated tuning routine
- Log PID performance data
Last updated: 2025-08-25