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