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/pyrene_actuator/pyreneActuator.hh" |
9 |
|
|
#include "ddp-actuator-solver/pyrene_actuator/pyreneCostFunction.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 |
|
|
|
18 |
|
|
DDPSolver<double, 2, 1>::stateVec_t xinit, xDes; |
19 |
|
|
|
20 |
|
|
xinit << -1.29653, 0.973714; |
21 |
|
|
xDes << -1.3, 0; |
22 |
|
|
|
23 |
|
|
unsigned int T = 50; |
24 |
|
|
double dt = 1e-3; |
25 |
|
|
unsigned int iterMax = 100; |
26 |
|
|
double stopCrit = 1e-3; |
27 |
|
|
|
28 |
|
|
DDPSolver<double, 2, 1>::stateVecTab_t xList; |
29 |
|
|
DDPSolver<double, 2, 1>::commandVecTab_t uList; |
30 |
|
|
DDPSolver<double, 2, 1>::traj lastTraj; |
31 |
|
|
|
32 |
|
|
pyreneActuator pyreneActuator; |
33 |
|
|
CostFunctionPyreneActuator costFunction; |
34 |
|
|
costFunction.setTauLimit(70); |
35 |
|
|
costFunction.setJointLimit(0.0, -2.35619449019); |
36 |
|
|
costFunction.setJointVelLimit(30.0, -30.0); |
37 |
|
|
DDPSolver<double, 2, 1> testSolverActuator(pyreneActuator, costFunction, |
38 |
|
|
DISABLE_FULLDDP, DISABLE_QPBOX); |
39 |
|
|
testSolverActuator.FirstInitSolver(xinit, xDes, T, dt, iterMax, stopCrit); |
40 |
|
|
|
41 |
|
|
int N = 100; |
42 |
|
|
gettimeofday(&tbegin, NULL); |
43 |
|
|
for (int i = 0; i < N; i++) testSolverActuator.solveTrajectory(); |
44 |
|
|
gettimeofday(&tend, NULL); |
45 |
|
|
|
46 |
|
|
lastTraj = testSolverActuator.getLastSolvedTrajectory(); |
47 |
|
|
xList = lastTraj.xList; |
48 |
|
|
uList = lastTraj.uList; |
49 |
|
|
unsigned int iter = lastTraj.iter; |
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 fichier("results_simple.csv", ios::out | ios::trunc); |
63 |
|
|
if (fichier) { |
64 |
|
|
fichier << "q,qDot,u" << endl; |
65 |
|
|
for (unsigned int i = 0; i < T; i++) { |
66 |
|
|
fichier << xList[i](0, 0) << "," << xList[i](1, 0) << "," |
67 |
|
|
<< uList[i](0, 0) << endl; |
68 |
|
|
} |
69 |
|
|
fichier << xList[T](0, 0) << "," << xList[T](1, 0) << "," |
70 |
|
|
<< uList[T - 1](0, 0) << endl; |
71 |
|
|
fichier.close(); |
72 |
|
|
|
73 |
|
|
} else |
74 |
|
|
cerr << "erreur ouverte fichier" << endl; |
75 |
|
|
return 0; |
76 |
|
|
} |