1 |
|
|
#include "ddp-actuator-solver/temperature_control/dctemp.hh" |
2 |
|
|
|
3 |
|
|
#include <math.h> |
4 |
|
|
#include <sys/time.h> |
5 |
|
|
|
6 |
|
|
#include <eigen3/unsupported/Eigen/MatrixFunctions> |
7 |
|
|
#include <iostream> |
8 |
|
|
|
9 |
|
|
/* |
10 |
|
|
* x0 -> actuator position |
11 |
|
|
* x1 -> actuator speed |
12 |
|
|
* x2 -> motor temperature |
13 |
|
|
* x3 -> external torque |
14 |
|
|
* x4 -> ambiant temperature |
15 |
|
|
*/ |
16 |
|
|
|
17 |
|
|
DCTemp::DCTemp(bool noiseOnParameters) { |
18 |
|
|
stateNb = 5; |
19 |
|
|
commandNb = 1; |
20 |
|
|
|
21 |
|
|
if (!noiseOnParameters) { |
22 |
|
|
J_ = 119e-7; |
23 |
|
|
K_M_ = 77.1e-3; |
24 |
|
|
f_VL_ = 0.429e-6; |
25 |
|
|
R_th_ = 2.8; |
26 |
|
|
tau_th_ = 15.7; |
27 |
|
|
} else { |
28 |
|
|
J_ = 119e-17; |
29 |
|
|
K_M_ = 77.1e-3; |
30 |
|
|
f_VL_ = 0.429e-6; |
31 |
|
|
R_th_ = 2.8; |
32 |
|
|
tau_th_ = 15.7; |
33 |
|
|
} |
34 |
|
|
|
35 |
|
|
Id_.setIdentity(); |
36 |
|
|
|
37 |
|
|
fu.setZero(); |
38 |
|
|
fx.setZero(); |
39 |
|
|
|
40 |
|
|
fu.setZero(); |
41 |
|
|
fx.setZero(); |
42 |
|
|
|
43 |
|
|
fxx[0].setZero(); |
44 |
|
|
fxx[1].setZero(); |
45 |
|
|
fxx[2].setZero(); |
46 |
|
|
fxx[3].setZero(); |
47 |
|
|
fxx[4].setZero(); |
48 |
|
|
|
49 |
|
|
fxu[0].setZero(); |
50 |
|
|
fxu[0].setZero(); |
51 |
|
|
|
52 |
|
|
fuu[0].setZero(); |
53 |
|
|
fux[0].setZero(); |
54 |
|
|
fxu[0].setZero(); |
55 |
|
|
|
56 |
|
|
QxxCont_.setZero(); |
57 |
|
|
QuuCont_.setZero(); |
58 |
|
|
QuxCont_.setZero(); |
59 |
|
|
|
60 |
|
|
lowerCommandBounds << -1.0; |
61 |
|
|
upperCommandBounds << 1.0; |
62 |
|
|
} |
63 |
|
|
|
64 |
|
|
DCTemp::stateVec_t DCTemp::computeDeriv(double&, const stateVec_t& X, |
65 |
|
|
const commandVec_t& U) { |
66 |
|
|
dX_[0] = X[1]; |
67 |
|
|
dX_[1] = (K_M_ / J_) * U[0] - (f_VL_ / J_) * X[1] - (1.0 / J_) * X[3]; |
68 |
|
|
dX_[2] = R_th_ * U[0] * U[0] - (X[2] - X[4]) / tau_th_; |
69 |
|
|
dX_[3] = 0.0; |
70 |
|
|
dX_[4] = 0.0; |
71 |
|
|
// std::cout << dX.transpose() << std::endl; |
72 |
|
|
return dX_; |
73 |
|
|
} |
74 |
|
|
|
75 |
|
|
DCTemp::stateVec_t DCTemp::computeNextState(double& dt, const stateVec_t& X, |
76 |
|
|
const commandVec_t& U) { |
77 |
|
|
k1_ = computeDeriv(dt, X, U); |
78 |
|
|
k2_ = computeDeriv(dt, X + (dt / 2) * k1_, U); |
79 |
|
|
k3_ = computeDeriv(dt, X + (dt / 2) * k2_, U); |
80 |
|
|
k4_ = computeDeriv(dt, X + dt * k3_, U); |
81 |
|
|
x_next_ = X + (dt_ / 6) * (k1_ + 2 * k2_ + 2 * k3_ + k4_); |
82 |
|
|
return x_next_; |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
void DCTemp::computeModelDeriv(double& dt, const stateVec_t& X, |
86 |
|
|
const commandVec_t& U) { |
87 |
|
|
double dh = 1e-7; |
88 |
|
|
stateVec_t Xp, Xm; |
89 |
|
|
Xp = X; |
90 |
|
|
Xm = X; |
91 |
|
|
for (unsigned int i = 0; i < stateNb; i++) { |
92 |
|
|
Xp[i] += dh / 2; |
93 |
|
|
Xm[i] -= dh / 2; |
94 |
|
|
fx.col(i) = |
95 |
|
|
(computeNextState(dt, Xp, U) - computeNextState(dt, Xm, U)) / dh; |
96 |
|
|
Xp = X; |
97 |
|
|
Xm = X; |
98 |
|
|
} |
99 |
|
|
} |
100 |
|
|
|
101 |
|
|
DCTemp::stateMat_t DCTemp::computeTensorContxx(const stateVec_t&) { |
102 |
|
|
return QxxCont_; |
103 |
|
|
} |
104 |
|
|
|
105 |
|
|
DCTemp::commandMat_t DCTemp::computeTensorContuu(const stateVec_t&) { |
106 |
|
|
return QuuCont_; |
107 |
|
|
} |
108 |
|
|
|
109 |
|
|
DCTemp::commandR_stateC_t DCTemp::computeTensorContux(const stateVec_t&) { |
110 |
|
|
return QuxCont_; |
111 |
|
|
} |