What is State-Space Control?
State-space control represents a system using matrices that describe how the system evolves over time. Instead of dealing with individual variables, state-space models group all system states into vectors and use linear algebra to predict and control behavior. A state-space system is defined by:- A matrix: System dynamics (how states evolve)
- B matrix: Input influence (how control inputs affect states)
- C matrix: Output mapping (what we can measure)
- D matrix: Feedthrough (direct input-to-output connection)
Linear System
TheLinearSystem class represents a plant (physical system) using state-space notation.
Creating a Linear System
wpimath/src/main/native/include/frc/system/LinearSystem.h:35
Linear Quadratic Regulator (LQR)
TheLinearQuadraticRegulator class implements optimal state feedback control. LQR controllers minimize a cost function that balances control effort against tracking error.
Control Law
LQR uses the control law: u = K(r - x) Where:- u: Control input (voltages)
- K: Optimal gain matrix
- r: Reference state
- x: Current state
Creating an LQR Controller
wpimath/src/main/native/include/frc/controller/LinearQuadraticRegulator.h:38
Tuning LQR Controllers
The Q and R matrices determine controller behavior:- Q (State Cost): Larger values make the controller try harder to minimize error in that state
- R (Control Cost): Larger values limit control effort (prevent aggressive control)
- Start with Q elements as maximum acceptable errors
- Start with R elements as maximum control inputs
- Increase Q values to make response more aggressive
- Increase R values to reduce control effort and smooth response
Using the Controller
Latency Compensation
LQR controllers can compensate for input delays, which is critical when sensor measurements are delayed:wpimath/src/main/native/include/frc/controller/LinearQuadraticRegulator.h:297
State-Space System Loop
Combine a plant, controller, and observer for complete state-space control:Common Plant Models
WPILib provides factory methods for common FRC mechanisms:Advantages of State-Space Control
- Optimal Control: LQR provides mathematically optimal gains
- Multiple Objectives: Balance multiple goals (speed, accuracy, control effort)
- MIMO Systems: Control multiple inputs and outputs simultaneously
- State Estimation: Integrate Kalman filters for robust control with noisy sensors
- Predictable Behavior: Well-understood mathematical framework
When to Use State-Space Control
State-space control is ideal for:- Mechanisms requiring optimal performance (flywheels, arms, elevators)
- Systems with multiple states to control
- Applications requiring smooth, predictable control
- When you have good system models
Further Reading
- Controls Engineering in FRC - Comprehensive guide to state-space control
- WPILib State-Space Documentation - Official tutorials and examples