GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/romeo_actuator/main.cpp Lines: 0 67 0.0 %
Date: 2023-06-02 15:50:43 Branches: 0 264 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/romeo_actuator/costfunctionromeoactuator.hh"
9
#include "ddp-actuator-solver/romeo_actuator/romeosimpleactuator.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, 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 = 0.01;
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(
35
      romeoActuatorModel, 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))) /
51
          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
  ofstream fichier1("results1.csv", ios::out | ios::trunc);
62
  if (fichier1) {
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++) {
68
      x = romeoActuatorModel.computeNextState(dt, x, uList[i - 1]);
69
      fichier1 << x(0, 0) << "," << x(1, 0) << "," << x(2, 0) << "," << x(3, 0)
70
               << "," << uList[i - 1] << endl;
71
    }
72
    fichier1 << xList[T](0, 0) << "," << xList[T](1, 0) << "," << xList[T](2, 0)
73
             << "," << xList[T](3, 0) << "," << uList[T - 1](0, 0) << endl;
74
    fichier1.close();
75
  } else
76
    cerr << "erreur ouverte fichier" << endl;
77
78
  ofstream fichier2("results2.csv", ios::out | ios::trunc);
79
  if (fichier2) {
80
    fichier2 << "tau,tauDot,q,qDot,u" << endl;
81
    fichier2 << T << ',' << 0 << endl;
82
    for (int j = 0; j < 0; j++) {
83
      romeoNoisyModel = new RomeoSimpleActuator(dt, 1);
84
      x = xinit;
85
      for (unsigned int i = 1; i < T; i++) {
86
        x = romeoNoisyModel->computeNextState(dt, x, uList[i - 1]);
87
        fichier2 << x(0, 0) << "," << x(1, 0) << "," << x(2, 0) << ","
88
                 << x(3, 0) << "," << uList[i - 1] << endl;
89
      }
90
      fichier2 << xList[T](0, 0) << "," << xList[T](1, 0) << ","
91
               << xList[T](2, 0) << "," << xList[T](3, 0) << ","
92
               << uList[T - 1](0, 0) << endl;
93
      delete romeoNoisyModel;
94
    }
95
    fichier2.close();
96
  } else
97
    cerr << "erreur ouverte fichier" << endl;
98
99
  return 0;
100
}