Line |
Branch |
Exec |
Source |
1 |
|
|
/* |
2 |
|
|
* Copyright 2010, |
3 |
|
|
* François Bleibel, |
4 |
|
|
* Olivier Stasse, |
5 |
|
|
* |
6 |
|
|
* CNRS/AIST |
7 |
|
|
* |
8 |
|
|
*/ |
9 |
|
|
|
10 |
|
|
#include <sot/core/debug.hh> |
11 |
|
|
#include <sot/core/exception-feature.hh> |
12 |
|
|
#include <sot/core/factory.hh> |
13 |
|
|
#include <sot/core/joint-limitator.hh> |
14 |
|
|
|
15 |
|
|
using namespace std; |
16 |
|
|
using namespace dynamicgraph::sot; |
17 |
|
|
using namespace dynamicgraph; |
18 |
|
|
|
19 |
|
✗ |
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(JointLimitator, "JointLimitator"); |
20 |
|
|
|
21 |
|
✗ |
JointLimitator::JointLimitator(const string &fName) |
22 |
|
|
: Entity(fName), |
23 |
|
✗ |
jointSIN(NULL, "JointLimitator(" + name + ")::input(vector)::joint"), |
24 |
|
✗ |
upperJlSIN(NULL, "JointLimitator(" + name + ")::input(vector)::upperJl"), |
25 |
|
✗ |
lowerJlSIN(NULL, "JointLimitator(" + name + ")::input(vector)::lowerJl"), |
26 |
|
✗ |
controlSIN(NULL, |
27 |
|
✗ |
"JointLimitator(" + name + ")::input(vector)::controlIN"), |
28 |
|
✗ |
controlSOUT(boost::bind(&JointLimitator::computeControl, this, _1, _2), |
29 |
|
✗ |
jointSIN << upperJlSIN << lowerJlSIN << controlSIN, |
30 |
|
✗ |
"JointLimitator(" + name + ")::output(vector)::control"), |
31 |
|
✗ |
widthJlSINTERN(boost::bind(&JointLimitator::computeWidthJl, this, _1, _2), |
32 |
|
✗ |
upperJlSIN << lowerJlSIN, |
33 |
|
✗ |
"JointLimitator(" + name + ")::input(vector)::widthJl") |
34 |
|
|
|
35 |
|
|
{ |
36 |
|
✗ |
signalRegistration(jointSIN << upperJlSIN << lowerJlSIN << controlSIN |
37 |
|
✗ |
<< controlSOUT << widthJlSINTERN); |
38 |
|
|
} |
39 |
|
|
|
40 |
|
✗ |
dynamicgraph::Vector &JointLimitator::computeWidthJl(dynamicgraph::Vector &res, |
41 |
|
|
const int &time) { |
42 |
|
|
sotDEBUGIN(15); |
43 |
|
|
|
44 |
|
✗ |
const dynamicgraph::Vector UJL = upperJlSIN.access(time); |
45 |
|
✗ |
const dynamicgraph::Vector LJL = lowerJlSIN.access(time); |
46 |
|
✗ |
const dynamicgraph::Vector::Index SIZE = UJL.size(); |
47 |
|
✗ |
res.resize(SIZE); |
48 |
|
|
|
49 |
|
✗ |
for (unsigned int i = 0; i < SIZE; ++i) { |
50 |
|
✗ |
res(i) = UJL(i) - LJL(i); |
51 |
|
|
} |
52 |
|
|
|
53 |
|
|
sotDEBUGOUT(15); |
54 |
|
✗ |
return res; |
55 |
|
|
} |
56 |
|
|
|
57 |
|
✗ |
dynamicgraph::Vector &JointLimitator::computeControl(dynamicgraph::Vector &uOUT, |
58 |
|
|
int time) { |
59 |
|
|
sotDEBUGIN(15); |
60 |
|
|
|
61 |
|
✗ |
const dynamicgraph::Vector &q = jointSIN.access(time); |
62 |
|
✗ |
const dynamicgraph::Vector &UJL = upperJlSIN.access(time); |
63 |
|
✗ |
const dynamicgraph::Vector &LJL = lowerJlSIN.access(time); |
64 |
|
✗ |
const dynamicgraph::Vector &uIN = controlSIN.access(time); |
65 |
|
|
|
66 |
|
✗ |
dynamicgraph::Vector::Index controlSize = uIN.size(); |
67 |
|
✗ |
uOUT.resize(controlSize); |
68 |
|
✗ |
uOUT.setZero(); |
69 |
|
|
|
70 |
|
✗ |
dynamicgraph::Vector::Index offset = q.size() - uIN.size(); |
71 |
|
✗ |
assert(offset >= 0); |
72 |
|
|
|
73 |
|
✗ |
for (unsigned int i = 0; i < controlSize; ++i) { |
74 |
|
✗ |
double qnext = q(i + offset) + uIN(i) * 0.005; |
75 |
|
✗ |
if ((i + offset < 6) || // do not take into account of freeflyer |
76 |
|
✗ |
((qnext < UJL(i + offset)) && (qnext > LJL(i + offset)))) { |
77 |
|
✗ |
uOUT(i) = uIN(i); |
78 |
|
|
} |
79 |
|
|
sotDEBUG(25) << i << ": " << qnext << " in? [" << LJL(i) << "," << UJL(i) |
80 |
|
|
<< "]" << endl; |
81 |
|
|
} |
82 |
|
|
|
83 |
|
|
sotDEBUGOUT(15); |
84 |
|
✗ |
return uOUT; |
85 |
|
|
} |
86 |
|
|
|
87 |
|
✗ |
void JointLimitator::display(std::ostream &os) const { |
88 |
|
✗ |
os << "JointLimitator <" << name << "> ... TODO"; |
89 |
|
|
} |
90 |
|
|
|