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