GCC Code Coverage Report


Directory: ./
File: src/task/task-conti.cpp
Date: 2024-11-13 12:35:17
Exec Total Coverage
Lines: 0 43 0.0%
Branches: 0 84 0.0%

Line Branch Exec Source
1 /*
2 * Copyright 2010,
3 * François Bleibel,
4 * Olivier Stasse,
5 *
6 * CNRS/AIST
7 *
8 */
9
10 /* --------------------------------------------------------------------- */
11 /* --- INCLUDE --------------------------------------------------------- */
12 /* --------------------------------------------------------------------- */
13
14 /* SOT */
15 #include <dynamic-graph/linear-algebra.h>
16
17 #include <sot/core/debug.hh>
18 #include <sot/core/factory.hh>
19 #include <sot/core/task-conti.hh>
20
21 using namespace std;
22 using namespace dynamicgraph::sot;
23 using namespace dynamicgraph;
24
25 DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(TaskConti, "TaskConti");
26
27 /* --------------------------------------------------------------------- */
28 /* --- CLASS ----------------------------------------------------------- */
29 /* --------------------------------------------------------------------- */
30
31 TaskConti::TaskConti(const std::string &n)
32 : Task(n),
33 timeRef(TIME_REF_UNSIGNIFICANT),
34 mu(0),
35 controlPrevSIN(NULL, "sotTaskConti(" + n + ")::input(double)::q0") {
36 taskSOUT.setFunction(
37 boost::bind(&TaskConti::computeContiDesiredVelocity, this, _1, _2));
38 signalRegistration(controlPrevSIN);
39 }
40
41 VectorMultiBound &TaskConti::computeContiDesiredVelocity(
42 VectorMultiBound &desvel2b, const int &timecurr) {
43 sotDEBUG(15) << "# In {" << endl;
44
45 dynamicgraph::Vector desvel = errorSOUT(timecurr);
46 const double &lambda = controlGainSIN(timecurr);
47
48 try {
49 const dynamicgraph::Matrix &J = jacobianSOUT(timecurr);
50
51 dynamicgraph::Vector deref(J.rows());
52 sotDEBUG(15) << "q0 = " << q0 << std::endl;
53 sotDEBUG(25) << "J = " << J << std::endl;
54 if (q0.size() != (J.cols() - 6)) throw; // TODO
55 for (int i = 0; i < J.rows(); ++i) {
56 deref(i) = 0;
57 for (int j = 6; j < J.cols(); ++j) deref(i) += J(i, j) * q0(j - 6);
58 }
59
60 if (timeRef == TIME_REF_TO_BE_SET) {
61 timeRef = timecurr;
62 }
63 if (timeRef < 0) {
64 sotDEBUG(10) << "Time not used. " << std::endl;
65 throw 1;
66 }
67
68 double dt = timeRef - timecurr;
69 dt *= mu / 200.0;
70 double contiGain = exp(dt);
71 double gain = (contiGain - 1) * lambda;
72
73 sotDEBUG(25) << "T: ref=" << timeRef << ", cur=" << timecurr << std::endl;
74 sotDEBUG(25) << "Gains: l=" << lambda << ", expmu=" << contiGain
75 << std::endl;
76 sotDEBUG(25) << "e = " << deref << std::endl;
77
78 desvel *= gain;
79 sotDEBUG(25) << "dedes: " << desvel << std::endl;
80 deref *= contiGain;
81 desvel += deref;
82 sotDEBUG(25) << "task: " << desvel << std::endl;
83
84 desvel2b.resize(desvel.size());
85 for (int i = 0; i < desvel.size(); ++i) desvel2b[i] = desvel(i);
86
87 sotDEBUG(15) << "# Out }" << endl;
88 return desvel2b;
89 } catch (...) {
90 const dynamicgraph::Vector &desvel = errorSOUT(timecurr);
91 const double &gain = controlGainSIN(timecurr);
92 desvel2b.resize(desvel.size());
93 for (int i = 0; i < desvel.size(); ++i) desvel2b[i] = -gain * desvel(i);
94 return desvel2b;
95 }
96 }
97
98 /* --- COMPUTATION ---------------------------------------------------------- */
99 /* --- COMPUTATION ---------------------------------------------------------- */
100 /* --- COMPUTATION ---------------------------------------------------------- */
101
102 /* --- DISPLAY ------------------------------------------------------------ */
103 /* --- DISPLAY ------------------------------------------------------------ */
104 /* --- DISPLAY ------------------------------------------------------------ */
105
106 void TaskConti::display(std::ostream &os) const {
107 os << "TaskConti " << name << " [t=" << timeRef << "] "
108 << ": " << endl;
109 os << "--- LIST --- " << std::endl;
110
111 for (FeatureList_t::const_iterator iter = featureList.begin();
112 iter != featureList.end(); ++iter) {
113 os << "-> " << (*iter)->getName() << endl;
114 }
115 }
116