GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/romeo_actuator/mainMPC.cpp Lines: 0 50 0.0 %
Date: 2023-06-02 15:50:43 Branches: 0 142 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
  cout << endl;
16
  struct timeval tbegin, tend;
17
  double texec = 0.0;
18
  DDPSolver<double, 4, 1>::stateVec_t xinit, xDes;
19
20
  xinit << 0.0, 0.0, 0.0, 0.0;
21
  xDes << 1.0, 0.0, 0.0, 0.0;
22
23
  unsigned int T = 100;
24
  unsigned int M = 3000;
25
  double dt = 1e-3;
26
  unsigned int iterMax = 100;
27
  double stopCrit = 0.01;
28
  DDPSolver<double, 4, 1>::stateVecTab_t xList;
29
  DDPSolver<double, 4, 1>::commandVecTab_t uList;
30
  DDPSolver<double, 4, 1>::traj lastTraj;
31
32
  srand(static_cast<unsigned int>(time(NULL)));
33
34
  RomeoSimpleActuator romeoActuatorModel(dt);
35
  RomeoSimpleActuator romeoNoisyModel(dt, 1);
36
  CostFunctionRomeoActuator costRomeoActuator;
37
  DDPSolver<double, 4, 1> testSolverRomeoActuator(
38
      romeoActuatorModel, costRomeoActuator, DISABLE_FULLDDP, DISABLE_QPBOX);
39
40
  ofstream fichier("resultsMPC.csv", ios::out | ios::trunc);
41
  if (!fichier) {
42
    cerr << "erreur fichier ! " << endl;
43
    return 1;
44
  }
45
  fichier << T << "," << M << endl;
46
  fichier << "tau,tauDot,q,qDot,u" << endl;
47
48
  testSolverRomeoActuator.FirstInitSolver(xinit, xDes, T, dt, iterMax,
49
                                          stopCrit);
50
51
  gettimeofday(&tbegin, NULL);
52
  for (unsigned int i = 0; i < M; i++) {
53
    testSolverRomeoActuator.initSolver(xinit, xDes);
54
    testSolverRomeoActuator.solveTrajectory();
55
    lastTraj = testSolverRomeoActuator.getLastSolvedTrajectory();
56
    xList = lastTraj.xList;
57
    uList = lastTraj.uList;
58
    xinit = romeoNoisyModel.computeNextState(dt, xinit, uList[0]);
59
60
    for (unsigned int j = 0; j < T; j++)
61
      fichier << xList[j](0, 0) << "," << xList[j](1, 0) << ","
62
              << xList[j](2, 0) << "," << xList[j](3, 0) << ","
63
              << uList[j](0, 0) << endl;
64
    fichier << xList[T](0, 0) << "," << xList[T](1, 0) << "," << xList[T](2, 0)
65
            << "," << xList[T](3, 0) << "," << 0.0 << endl;
66
  }
67
  gettimeofday(&tend, NULL);
68
69
  texec = ((double)(1000 * (tend.tv_sec - tbegin.tv_sec) +
70
                    ((tend.tv_usec - tbegin.tv_usec) / 1000))) /
71
          1000.;
72
  texec = (double)(tend.tv_usec - tbegin.tv_usec);
73
74
  cout << "temps d'execution total du solveur ";
75
  cout << texec / 1000000.0 << endl;
76
  cout << "temps d'execution par pas de MPC ";
77
  cout << texec / (T * 1000000) << endl;
78
79
  fichier.close();
80
81
  return 0;
82
}