LQRController

A Linear Quadratic Regulator (LQR) for controlling a system modeled by state-space equations.

LQR is a form of optimal control that finds the best control input to apply to a system by minimizing a quadratic cost function. The cost function balances two competing goals:

  1. State Error: How far the system is from its desired target state (penalized by the Q matrix).

  2. Control Effort: How much energy or effort is used to control the system (penalized by the R matrix).

The controller computes the optimal control input u using a simple state-feedback law: u = -Kx, where x is the system's state error and K is the optimal gain matrix.

Thank you to Tyler Veness and WPILib!

Parameters

A

The state matrix.

B

The input matrix.

Q

The state cost matrix.

R

The control cost matrix.

dt

The time step for the discrete-time model (your loop time)

See also

Constructors

Link copied to clipboard
constructor(A: Matrix<States, States>, B: Matrix<States, Inputs>, Q: Matrix<States, States>, R: Matrix<Inputs, Inputs>, dt: Double = 0.05)
constructor(A: Matrix<States, States>, B: Matrix<States, Inputs>, Qelems: Vector<States>, Relems: Vector<Inputs>, dt: Double = 0.05)

Constructs a controller with the given coefficient matrices.

constructor(plant: LinearModel<States, Inputs, Outputs>, Qelems: Vector<States>, Relems: Vector<Inputs>, dt: Double = 0.05)

Constructs a controller with the given plant model and cost matrices.

Functions

Link copied to clipboard
fun update(error: Matrix<States, N1>): Matrix<Inputs, N1>

Calculates the optimal control input to correct for the given state error.