Brick
Loading...
Searching...
No Matches
LinearQuadraticRegulator< STATES, INPUTS > Class Template Reference

#include <linear_quadratic_regulator.h>

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.
Inheritance diagram for LinearQuadraticRegulator< STATES, INPUTS >:

Public Types

using MatrixA = EMat<STATES, STATES>
using MatrixB = EMat<STATES, INPUTS>
using VectorX = EVec<STATES>
using VectorU = EVec<INPUTS>

Public Member Functions

template<int OUTPUTS>
 LinearQuadraticRegulator (LinearSystem< STATES, INPUTS, OUTPUTS > &plant, const VectorX &Qtolerances, const VectorU &Rtolerances, const units::Time &dt)
 LinearQuadraticRegulator (const MatrixA &A, const MatrixB &B, const VectorX &Qtolerances, const VectorU &Rtolerances, const units::Time &dt)
 LinearQuadraticRegulator (const MatrixA &A, const MatrixB &B, const EMat< STATES, STATES > &Q, const EMat< INPUTS, INPUTS > &R, const units::Time &dt)
void reset () override
 Resets the internal state of the LQR.
VectorU update (const VectorX &x, const VectorX &r, const units::Time &dt=10_ms) override
template<int OUTPUTS>
void latency_compensate (LinearSystem< STATES, INPUTS, OUTPUTS > &plant, const units::Time &dt, const units::Time &input_delay)
Public Member Functions inherited from Feedback< EVec< STATES >, EVec< INPUTS > >
virtual EVec< INPUTS > update (const EVec< STATES > &state, const EVec< STATES > &reference, const units::Time &dt)=0
 Updates the control loop output.
EVec< INPUTS > get_output ()
 Gets the last saved output value.
EVec< INPUTS > get_last_error ()
 Gets the last saved error.
EVec< STATES > get_reference ()
 Gets the currently stored reference state.
EVec< STATES > get_state ()
 Gets the currently stored state.

Additional Inherited Members

Public Attributes inherited from Feedback< EVec< STATES >, EVec< INPUTS > >
EVec< INPUTS > output_min_
EVec< INPUTS > output_max_
Protected Attributes inherited from Feedback< EVec< STATES >, EVec< INPUTS > >
EVec< STATES > reference_
EVec< STATES > state_
EVec< STATES > last_error_
EVec< INPUTS > output_

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 units::Time & 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 units::Time & 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 units::Time & 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

◆ latency_compensate()

template<int STATES, int INPUTS>
template<int OUTPUTS>
void LinearQuadraticRegulator< STATES, INPUTS >::latency_compensate ( LinearSystem< STATES, INPUTS, OUTPUTS > & plant,
const units::Time & dt,
const units::Time & 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.

◆ reset()

template<int STATES, int INPUTS>
void LinearQuadraticRegulator< STATES, INPUTS >::reset ( )
inlineoverridevirtual

Resets the internal state of the LQR.

Implements Feedback< EVec< STATES >, EVec< INPUTS > >.

◆ update()

template<int STATES, int INPUTS>
VectorU LinearQuadraticRegulator< STATES, INPUTS >::update ( const VectorX & x,
const VectorX & r,
const units::Time & dt = 10_ms )
inlineoverride

Computes the control input u as:

u = K(r - x)

Parameters
xThe current state.
rThe reference state.
dtthe timestep since the last time this method was called

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