GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/linear/mainLinear.cpp Lines: 0 49 0.0 %
Date: 2023-06-02 15:50:43 Branches: 0 128 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/linear/costLinear.hh"
9
#include "ddp-actuator-solver/linear/modelLinear.hh"
10
11
using namespace std;
12
using namespace Eigen;
13
14
#define STATE_NB 2
15
#define COMMAND_NB 1
16
17
int main() {
18
  struct timeval tbegin, tend;
19
  double texec = 0.0;
20
  DDPSolver<double, STATE_NB, COMMAND_NB>::stateVec_t xinit, xDes, x;
21
  DDPSolver<double, STATE_NB, COMMAND_NB>::commandVec_t u;
22
23
  xinit << 0.0, 0.0;
24
  xDes << 1.0, 0.0;
25
26
  unsigned int T = 300;
27
  double dt = 1e-2;
28
  unsigned int iterMax = 20;
29
  double stopCrit = 0.01;
30
  DDPSolver<double, STATE_NB, COMMAND_NB>::stateVecTab_t xList;
31
  DDPSolver<double, STATE_NB, COMMAND_NB>::commandVecTab_t uList;
32
  DDPSolver<double, STATE_NB, COMMAND_NB>::traj lastTraj;
33
34
  ModelLinear model(dt);
35
  CostLinear cost;
36
  DDPSolver<double, STATE_NB, COMMAND_NB> solver(model, cost, DISABLE_FULLDDP,
37
                                                 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
  texec = ((double)(1000 * (tend.tv_sec - tbegin.tv_sec) +
51
                    ((tend.tv_usec - tbegin.tv_usec) / 1000))) /
52
          1000.;
53
  texec /= N;
54
55
  cout << endl;
56
  cout << "temps d'execution total du solveur ";
57
  cout << texec << endl;
58
  cout << "temps d'execution par pas de temps ";
59
  cout << texec / T << endl;
60
  cout << "Nombre d'itérations : " << iter << endl;
61
62
  ofstream fichier1("results1.csv", ios::out | ios::trunc);
63
  if (fichier1) {
64
    fichier1 << "pos,vel,u" << endl;
65
    fichier1 << T << "," << STATE_NB << "," << COMMAND_NB << endl;
66
    u << uList[0];
67
    x = xinit;
68
    fichier1 << x(0, 0) << "," << x(1, 0) << "," << u(0, 0) << endl;
69
    for (unsigned int i = 1; i < T; i++) {
70
      u << uList[i];
71
      x = model.computeNextState(dt, x, u);
72
      x = xList[i];
73
      fichier1 << x(0, 0) << "," << x(1, 0) << "," << u(0, 0) << endl;
74
    }
75
    fichier1.close();
76
  } else
77
    cerr << "erreur ouverte fichier" << endl;
78
79
  return 0;
80
}