GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/inverse_pendulum/mainIP.cpp Lines: 0 70 0.0 %
Date: 2023-06-02 15:50:43 Branches: 0 298 0.0 %

Line Branch Exec Source
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/inverse_pendulum/costIP.hh"
9
#include "ddp-actuator-solver/inverse_pendulum/modelIP.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
  xinit << -1.0, 0.0, -100.0, 0.0, 0.0;
21
  xDes << 0.5, 0.0, 0.0, 0.0, 0.0;
22
23
  unsigned int i;
24
  unsigned int T = 3000;
25
  double dt = 1e-3;
26
  unsigned int iterMax = 100;
27
  double stopCrit = 0.01;
28
  DDPSolver<double, 5, 1>::stateVecTab_t xList;
29
  DDPSolver<double, 5, 1>::commandVecTab_t uList;
30
  DDPSolver<double, 5, 1>::traj lastTraj;
31
32
  ModelIP model(dt);
33
  ModelIP* noisyModel = NULL;
34
  CostIP cost;
35
  DDPSolver<double, 5, 1> solver(model, cost, DISABLE_FULLDDP, DISABLE_QPBOX);
36
  solver.FirstInitSolver(xinit, xDes, T, dt, iterMax, stopCrit);
37
38
  int N = 100;
39
  gettimeofday(&tbegin, NULL);
40
  solver.solveTrajectory();
41
  gettimeofday(&tend, NULL);
42
43
  lastTraj = solver.getLastSolvedTrajectory();
44
  xList = lastTraj.xList;
45
  uList = lastTraj.uList;
46
  unsigned int iter = lastTraj.iter;
47
48
  texec = ((double)(1000 * (tend.tv_sec - tbegin.tv_sec) +
49
                    ((tend.tv_usec - tbegin.tv_usec) / 1000))) /
50
          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
    fichier1 << "tau,tauDot,q,qDot,u" << endl;
63
    x = xinit;
64
    fichier1 << x(0, 0) << "," << x(1, 0) << "," << x(2, 0) << "," << x(3, 0)
65
             << "," << uList[0] << endl;
66
    for (i = 1; i < T; i++) {
67
      x = model.computeNextState(dt, x, uList[i - 1]);
68
      fichier1 << x(0, 0) << "," << x(1, 0) << "," << x(2, 0) << "," << x(3, 0)
69
               << "," << uList[i - 1] << endl;
70
    }
71
    fichier1 << xList[T](0, 0) << "," << xList[T](1, 0) << "," << xList[T](2, 0)
72
             << "," << xList[T](3, 0) << "," << uList[T - 1](0, 0) << endl;
73
    fichier1.close();
74
  } else
75
    cerr << "erreur ouverte fichier" << endl;
76
77
  ofstream fichier2("results2.csv", ios::out | ios::trunc);
78
  if (fichier2) {
79
    fichier2 << "tau,tauDot,q,qDot,u" << endl;
80
    fichier2 << T << ',' << 0 << endl;
81
    for (int j = 0; j < 0; j++) {
82
      noisyModel = new ModelIP(dt, 1);
83
      fichier2 << xList[i](0, 0) << "," << xList[i](1, 0) << ","
84
               << xList[i](2, 0) << "," << xList[i](3, 0) << ","
85
               << uList[i](0, 0) << endl;
86
      x = xinit;
87
      for (i = 1; i < T; i++) {
88
        x = noisyModel->computeNextState(dt, x, uList[i - 1]);
89
        fichier2 << x(0, 0) << "," << x(1, 0) << "," << x(2, 0) << ","
90
                 << x(3, 0) << "," << uList[i - 1] << endl;
91
      }
92
      fichier2 << xList[T](0, 0) << "," << xList[T](1, 0) << ","
93
               << xList[T](2, 0) << "," << xList[T](3, 0) << ","
94
               << uList[T - 1](0, 0) << endl;
95
      delete noisyModel;
96
    }
97
    fichier2.close();
98
  } else
99
    cerr << "erreur ouverte fichier" << endl;
100
101
  return 0;
102
}