13 #include <yarp/os/Log.h>
14 #include <yarp/math/Math.h>
15 #include <yarp/math/SVD.h>
19 using namespace yarp::os;
20 using namespace yarp::sig;
21 using namespace yarp::math;
26 Riccati::Riccati(
const Matrix &_A,
const Matrix &_B,
const Matrix &_V,
27 const Matrix &_P,
const Matrix &_VN,
bool verb)
29 A = _A; At =
A.transposed();
30 B = _B; Bt = B.transposed();
35 Ti =
new Matrix[1]; Ti[0].resize(1,1); Ti[0].zero();
36 Li =
new Matrix[1]; Li[0].resize(1,1); Li[0].zero();
44 yWarning(
"Riccati: problem defined, unsolved.");
49 void Riccati::setVerbose(
bool verb)
56 Matrix Riccati::L(
int step)
61 yWarning(
"Riccati: DARE has not been solved yet.");
64 if(step>=0 && step>=N)
67 yWarning(
"Riccati: Index for gain matrix out of bound.");
80 yError(
"Riccati: DARE has not been solved yet.");
86 yError(
"Riccati: Index for DARE matrix out of bound.");
94 void Riccati::setProblemData(
const Matrix &_A,
const Matrix &_B,
const Matrix &_V,
95 const Matrix &_P,
const Matrix &_VN)
97 A = _A; At =
A.transposed();
98 B = _B; Bt = B.transposed();
108 yWarning(
"Riccati: problem defined, unsolved.");
113 void Riccati::solveRiccati(
int steps)
119 Ti =
new Matrix[steps+1];
120 Li =
new Matrix[steps];
121 for(i=0; i<=steps; i++)
122 Ti[i].resize(VN.rows(),VN.cols());
126 for(i=steps-1; i>=0; i--)
130 Ti[i] = V + At *(lastT - lastT * B* pinv(P+Bt*lastT*B)*Bt*lastT )*
A;
133 for(i=0;i<steps; i++)
136 Li[i] = pinv(P + Bt*Ti[i+1]*B) *Bt * Ti[i+1] *
A;
140 yInfo(
"Riccati: DARE solved, matrices Li and Ti computed and stored.");
145 Vector Riccati::doLQcontrol(
int step,
const Vector &
x)
150 yError(
"Riccati: DARE has not been solved yet.");
154 if(step>=0 && step>N)
157 yError(
"Riccati: Index for DARE matrix out of bound.");
161 return (Li[step] * (-1.0*
x));
166 void Riccati::doLQcontrol(
int step,
const Vector &
x, Vector &ret)
171 yError(
"Riccati: DARE has not been solved yet.");
174 else if(step>=0 && step>N)
177 yError(
"Riccati: Index for DARE matrix out of bound.");
183 ret = Li[step] * (-1.0*
x);