1 |
|
|
#include <sys/time.h> |
2 |
|
|
#include <time.h> |
3 |
|
|
|
4 |
|
|
#include <ddp-actuator-solver/ddpsolver.hh> |
5 |
|
|
#include <fstream> |
6 |
|
|
#include <iostream> |
7 |
|
|
|
8 |
|
|
#include "ddp-actuator-solver/temperature_control/costtemp.hh" |
9 |
|
|
#include "ddp-actuator-solver/temperature_control/dctemp.hh" |
10 |
|
|
|
11 |
|
|
using namespace std; |
12 |
|
|
using namespace Eigen; |
13 |
|
|
|
14 |
|
|
int main() { |
15 |
|
|
struct timeval tbegin, tend; |
16 |
|
|
double texec = 0.0; |
17 |
|
|
DDPSolver<double, 5, 1>::stateVec_t xinit, xDes, x; |
18 |
|
|
DDPSolver<double, 5, 1>::commandVec_t u; |
19 |
|
|
|
20 |
|
|
/* |
21 |
|
|
* x0 -> actuator position |
22 |
|
|
* x1 -> actuator speed |
23 |
|
|
* x2 -> motor temperature |
24 |
|
|
* x3 -> external torque |
25 |
|
|
* x4 -> ambiant temperature |
26 |
|
|
*/ |
27 |
|
|
|
28 |
|
|
xinit << -1.0, 0.0, -100.0, 0.0, 0.0; |
29 |
|
|
xDes << 0.5, 0.0, 0.0, 0.0, 0.0; |
30 |
|
|
|
31 |
|
|
unsigned int T = 3000; |
32 |
|
|
double dt = 1e-3; |
33 |
|
|
unsigned int iterMax = 100; |
34 |
|
|
double stopCrit = 0.01; |
35 |
|
|
DDPSolver<double, 5, 1>::stateVecTab_t xList; |
36 |
|
|
DDPSolver<double, 5, 1>::commandVecTab_t uList; |
37 |
|
|
DDPSolver<double, 5, 1>::traj lastTraj; |
38 |
|
|
|
39 |
|
|
DCTemp model; |
40 |
|
|
DCTemp* noisyModel = NULL; |
41 |
|
|
CostTemp cost; |
42 |
|
|
DDPSolver<double, 5, 1> solver(model, cost, DISABLE_FULLDDP, DISABLE_QPBOX); |
43 |
|
|
solver.FirstInitSolver(xinit, xDes, T, dt, iterMax, stopCrit); |
44 |
|
|
|
45 |
|
|
int N = 100; |
46 |
|
|
gettimeofday(&tbegin, NULL); |
47 |
|
|
solver.solveTrajectory(); |
48 |
|
|
gettimeofday(&tend, NULL); |
49 |
|
|
|
50 |
|
|
lastTraj = solver.getLastSolvedTrajectory(); |
51 |
|
|
xList = lastTraj.xList; |
52 |
|
|
uList = lastTraj.uList; |
53 |
|
|
unsigned int iter = lastTraj.iter; |
54 |
|
|
|
55 |
|
|
texec = ((double)(1000 * (tend.tv_sec - tbegin.tv_sec) + |
56 |
|
|
((tend.tv_usec - tbegin.tv_usec) / 1000))) / |
57 |
|
|
1000.; |
58 |
|
|
texec /= N; |
59 |
|
|
|
60 |
|
|
cout << endl; |
61 |
|
|
cout << "temps d'execution total du solveur "; |
62 |
|
|
cout << texec << endl; |
63 |
|
|
cout << "temps d'execution par pas de temps "; |
64 |
|
|
cout << texec / T << endl; |
65 |
|
|
cout << "Nombre d'itérations : " << iter << endl; |
66 |
|
|
|
67 |
|
|
ofstream fichier1("results1.csv", ios::out | ios::trunc); |
68 |
|
|
if (fichier1) { |
69 |
|
|
fichier1 << "tau,tauDot,q,qDot,u" << endl; |
70 |
|
|
x = xinit; |
71 |
|
|
fichier1 << x(0, 0) << "," << x(1, 0) << "," << x(2, 0) << "," << x(3, 0) |
72 |
|
|
<< "," << uList[0] << endl; |
73 |
|
|
for (unsigned i = 1; i < T; i++) { |
74 |
|
|
x = model.computeNextState(dt, x, uList[i - 1]); |
75 |
|
|
fichier1 << x(0, 0) << "," << x(1, 0) << "," << x(2, 0) << "," << x(3, 0) |
76 |
|
|
<< "," << uList[i - 1] << endl; |
77 |
|
|
} |
78 |
|
|
fichier1 << xList[T](0, 0) << "," << xList[T](1, 0) << "," << xList[T](2, 0) |
79 |
|
|
<< "," << xList[T](3, 0) << "," << uList[T - 1](0, 0) << endl; |
80 |
|
|
fichier1.close(); |
81 |
|
|
} else |
82 |
|
|
cerr << "erreur ouverte fichier" << endl; |
83 |
|
|
|
84 |
|
|
ofstream fichier2("results2.csv", ios::out | ios::trunc); |
85 |
|
|
if (fichier2) { |
86 |
|
|
fichier2 << "tau,tauDot,q,qDot,u" << endl; |
87 |
|
|
fichier2 << T << ',' << 0 << endl; |
88 |
|
|
for (int j = 0; j < 0; j++) { |
89 |
|
|
noisyModel = new DCTemp(1); |
90 |
|
|
x = xinit; |
91 |
|
|
for (unsigned int i = 1; i < T; i++) { |
92 |
|
|
x = noisyModel->computeNextState(dt, x, uList[i - 1]); |
93 |
|
|
fichier2 << x(0, 0) << "," << x(1, 0) << "," << x(2, 0) << "," |
94 |
|
|
<< x(3, 0) << "," << uList[i - 1] << endl; |
95 |
|
|
} |
96 |
|
|
fichier2 << xList[T](0, 0) << "," << xList[T](1, 0) << "," |
97 |
|
|
<< xList[T](2, 0) << "," << xList[T](3, 0) << "," |
98 |
|
|
<< uList[T - 1](0, 0) << endl; |
99 |
|
|
delete noisyModel; |
100 |
|
|
} |
101 |
|
|
fichier2.close(); |
102 |
|
|
} else |
103 |
|
|
cerr << "erreur ouverte fichier" << endl; |
104 |
|
|
|
105 |
|
|
return 0; |
106 |
|
|
} |