RIT VEXU Core API
Loading...
Searching...
No Matches
LinearQuadraticRegulator< STATES, INPUTS > Class Template Reference

#include <linear_quadratic_regulator.h>

Public Member Functions

template<int OUTPUTS>
 LinearQuadraticRegulator (LinearSystem< STATES, INPUTS, OUTPUTS > &plant, const VectorX &Qtolerances, const VectorU &Rtolerances, const double &dt)
 
 LinearQuadraticRegulator (const MatrixA &A, const MatrixB &B, const VectorX &Qtolerances, const VectorU &Rtolerances, const double &dt)
 
 LinearQuadraticRegulator (const MatrixA &A, const MatrixB &B, const EMat< STATES, STATES > &Q, const EMat< INPUTS, INPUTS > &R, const double &dt)
 
VectorU calculate (const VectorX &x, const VectorX &r)
 
template<int OUTPUTS>
void latency_compensate (LinearSystem< STATES, INPUTS, OUTPUTS > &plant, const double &dt, const double &input_delay)
 

Detailed Description

template<int STATES, int INPUTS>
class LinearQuadraticRegulator< STATES, INPUTS >

Class implements an LQR controller. This finds the optimal gain matrix K where:

u = K(r - x)

K is optimized to minimize a cost function:

J = ∑ xₖᵀQxₖ + uₖᵀRuₖ k=0

Where Q and R are the state and control cost matrices.

Template Parameters
STATESThe number of states in the system.
INPUTSThe number of inputs to the system.

Constructor & Destructor Documentation

◆ LinearQuadraticRegulator() [1/3]

template<int STATES, int INPUTS>
template<int OUTPUTS>
LinearQuadraticRegulator< STATES, INPUTS >::LinearQuadraticRegulator ( LinearSystem< STATES, INPUTS, OUTPUTS > & plant,
const VectorX & Qtolerances,
const VectorU & Rtolerances,
const double & dt )
inline

Constructs an LQR given a plant, a vector of tolerances for the states and inputs, and the timestep in seconds.

Template Parameters
OUTPUTSThe number of outputs of the plant.
Parameters
plantThe linear system to control.
QtolerancesA vector of tolerances for each state.
RtolerancesA vector of tolerances for each input.

◆ LinearQuadraticRegulator() [2/3]

template<int STATES, int INPUTS>
LinearQuadraticRegulator< STATES, INPUTS >::LinearQuadraticRegulator ( const MatrixA & A,
const MatrixB & B,
const VectorX & Qtolerances,
const VectorU & Rtolerances,
const double & dt )
inline

Constructs an LQR given state and input matrices, a vector of tolerances for the states and inputs, and the timestep in seconds.

Parameters
AThe state matrix of the linear system.
BThe input matrix of the linear system.
QtolerancesA vector of tolerances for each state.
RtolerancesA vector of tolerances for each input.

◆ LinearQuadraticRegulator() [3/3]

template<int STATES, int INPUTS>
LinearQuadraticRegulator< STATES, INPUTS >::LinearQuadraticRegulator ( const MatrixA & A,
const MatrixB & B,
const EMat< STATES, STATES > & Q,
const EMat< INPUTS, INPUTS > & R,
const double & dt )
inline

Constructs an LQR given state and input matrices, the cost matrices of states and inputs, and the timestep in seconds.

Parameters
AThe state matrix of the linear system.
BThe input matrix of the linear system.
QThe cost matrix of the states.
RThe cost matrix of the inputs.

Member Function Documentation

◆ calculate()

template<int STATES, int INPUTS>
VectorU LinearQuadraticRegulator< STATES, INPUTS >::calculate ( const VectorX & x,
const VectorX & r )
inline

Computes the control input u as:

u = K(r - x)

Parameters
xThe current state.
rThe reference state.

◆ latency_compensate()

template<int STATES, int INPUTS>
template<int OUTPUTS>
void LinearQuadraticRegulator< STATES, INPUTS >::latency_compensate ( LinearSystem< STATES, INPUTS, OUTPUTS > & plant,
const double & dt,
const double & input_delay )
inline

Recomputes K to work for a time delayed state.

Kdelay = K(A - BK)^(delay / dt)

Template Parameters
OUTPUTSThe number of outputs of the plant
Parameters
plantThe linear system.
dtThe timestep in seconds.
input_delayThe time delay of the system.

The documentation for this class was generated from the following file: