bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
lqr.h
Go to the documentation of this file.
1#ifndef BITSIM_CONTROL_LQR_H
2#define BITSIM_CONTROL_LQR_H
3
9
10#include "bitsim/bitsim_types.h"
11
12#include <Eigen/Dense>
13
14namespace bitsim
15{
16namespace control
17{
18
21
24
33
39DiscreteLinearModel discretise(const Matrix &A, const Matrix &B, real_t dt);
40
53Matrix solve_dare(const Matrix &A, const Matrix &B, const Matrix &Q, const Matrix &R);
54
66Matrix solve_care(const Matrix &A, const Matrix &B, const Matrix &Q, const Matrix &R);
67
74{
77};
78
83LQRSolution dlqr(const Matrix &A, const Matrix &B, const Matrix &Q, const Matrix &R);
84
88LQRSolution lqr(const Matrix &A, const Matrix &B, const Matrix &Q, const Matrix &R);
89
105{
106 public:
110 explicit LQRController(const Matrix &K);
111
117 void set_reference(const Vector &x_ref, const Vector &u_ref);
118
123 void set_input_bounds(const Vector &lower, const Vector &upper);
124
128 Vector control(const Vector &x) const;
129
130 const Matrix &gain() const noexcept { return K_; }
131 const Vector &state_reference() const noexcept { return x_ref_; }
132 const Vector &input_reference() const noexcept { return u_ref_; }
133 uint_t n_states() const noexcept { return static_cast<uint_t>(K_.cols()); }
134 uint_t n_inputs() const noexcept { return static_cast<uint_t>(K_.rows()); }
135
136 private:
137 Matrix K_;
138 Vector x_ref_;
139 Vector u_ref_;
140 bool bounded_{false};
141 Vector lower_;
142 Vector upper_;
143};
144
145} // namespace control
146} // namespace bitsim
147
148#endif // BITSIM_CONTROL_LQR_H
The basic types of bitsim. Code outside this file names Eigen's matrix and vector types only through ...
const Matrix & gain() const noexcept
Definition lqr.h:130
Vector control(const Vector &x) const
Definition lqr.cpp:200
const Vector & state_reference() const noexcept
Definition lqr.h:131
LQRController(const Matrix &K)
Definition lqr.cpp:167
void set_reference(const Vector &x_ref, const Vector &u_ref)
Set the operating point: the state to hold and the input that holds it. Both start at zero.
Definition lqr.cpp:176
const Vector & input_reference() const noexcept
Definition lqr.h:132
uint_t n_states() const noexcept
Definition lqr.h:133
void set_input_bounds(const Vector &lower, const Vector &upper)
Clip each input to [lower, upper].
Definition lqr.cpp:187
uint_t n_inputs() const noexcept
Definition lqr.h:134
Controllers: PID controllers, line following, a quadrotor flight controller, a fixed wing autopilot,...
Definition control_module.h:18
DiscreteLinearModel discretise(const Matrix &A, const Matrix &B, real_t dt)
Discretise for a step dt, with the input held over the step (zero-order hold): and ,...
Definition lqr.cpp:41
Matrix solve_care(const Matrix &A, const Matrix &B, const Matrix &Q, const Matrix &R)
Solve the continuous algebraic Riccati equation.
Definition lqr.cpp:101
LQRSolution dlqr(const Matrix &A, const Matrix &B, const Matrix &Q, const Matrix &R)
The LQR of : with P from solve_dare().
Definition lqr.cpp:154
RealMat Matrix
The matrices of the linear models and the controllers.
Definition lqr.h:20
LQRSolution lqr(const Matrix &A, const Matrix &B, const Matrix &Q, const Matrix &R)
The LQR of : with P from solve_care().
Definition lqr.cpp:161
Matrix solve_dare(const Matrix &A, const Matrix &B, const Matrix &Q, const Matrix &R)
Solve the discrete algebraic Riccati equation.
Definition lqr.cpp:62
RealColVec Vector
The vectors of the linear models and the controllers: states, inputs.
Definition lqr.h:23
Definition dc_motor_backend_base.h:9
std::size_t uint_t
uint_t
Definition bitsim_types.h:40
ColVec< real_t > RealColVec
Dynamically sized column vector.
Definition bitsim_types.h:122
double real_t
real_t
Definition bitsim_types.h:20
DynMat< real_t > RealMat
Dynamically sized matrix of type double.
Definition bitsim_types.h:56
A linear model in discrete time, .
Definition lqr.h:29
Matrix A
Definition lqr.h:30
Matrix B
Definition lqr.h:31
The gain of a linear quadratic regulator and the cost matrix it comes from: the input minimises the ...
Definition lqr.h:74
Matrix K
Definition lqr.h:75
Matrix P
Definition lqr.h:76