feature-joint-limits.cpp
Go to the documentation of this file.
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 <sot/core/debug.hh>
18 using namespace std;
19 
20 #include <../src/feature/feature-joint-limits-command.h>
21 
22 #include <sot/core/factory.hh>
23 
24 /* --------------------------------------------------------------------- */
25 /* --- CLASS ----------------------------------------------------------- */
26 /* --------------------------------------------------------------------- */
27 
28 using namespace dynamicgraph::sot;
29 using namespace dynamicgraph;
31 
32 const double FeatureJointLimits::THRESHOLD_DEFAULT = .9;
33 
34 FeatureJointLimits::FeatureJointLimits(const string &fName)
35  : FeatureAbstract(fName),
36  threshold(THRESHOLD_DEFAULT)
37 
38  ,
39  jointSIN(NULL,
40  "sotFeatureJointLimits(" + name + ")::input(vector)::joint"),
41  upperJlSIN(NULL,
42  "sotFeatureJointLimits(" + name + ")::input(vector)::upperJl"),
43  lowerJlSIN(NULL,
44  "sotFeatureJointLimits(" + name + ")::input(vector)::lowerJl"),
45  widthJlSINTERN(
46  boost::bind(&FeatureJointLimits::computeWidthJl, this, _1, _2),
47  upperJlSIN << lowerJlSIN,
48  "sotFeatureJointLimits(" + name + ")::input(vector)::widthJl") {
52 
54 
55  // Commands
56  //
57  std::string docstring;
58  // Actuate
59  docstring =
60  " \n"
61  " Actuate\n"
62  " \n";
63  addCommand("actuate",
64  new command::featureJointLimits::Actuate(*this, docstring));
65 }
66 
67 /* --------------------------------------------------------------------- */
68 
71 
72 /* --------------------------------------------------------------------- */
73 /* --------------------------------------------------------------------- */
74 /* --------------------------------------------------------------------- */
75 
76 unsigned int &FeatureJointLimits::getDimension(unsigned int &dim, int time) {
77  sotDEBUG(25) << "# In {" << endl;
78 
79  const Flags &fl = selectionSIN.access(time);
80  const Matrix::Index NBJL = upperJlSIN.access(time).size();
81 
82  dim = 0;
83  for (Matrix::Index i = 0; i < NBJL; ++i)
84  if (fl(static_cast<int>(i))) dim++;
85 
86  sotDEBUG(25) << "# Out }" << endl;
87  return dim;
88 }
89 
91  sotDEBUGIN(15);
92 
93  const Vector UJL = upperJlSIN.access(time);
94  const Vector LJL = lowerJlSIN.access(time);
95  const Vector::Index SIZE = UJL.size();
96  res.resize(SIZE);
97 
98  for (Vector::Index i = 0; i < SIZE; ++i) {
99  res(i) = UJL(i) - LJL(i);
100  }
101 
102  sotDEBUGOUT(15);
103  return res;
104 }
105 
110  sotDEBUG(15) << "# In {" << endl;
111 
112  const unsigned int SIZE = dimensionSOUT.access(time);
113  const Vector q = jointSIN.access(time);
114  const Flags &fl = selectionSIN(time);
115  // const unsigned int SIZE_FF=SIZE+freeFloatingSize;
116  const Vector::Index SIZE_TOTAL = q.size();
117  const Vector WJL = widthJlSINTERN.access(time);
118  J.resize(SIZE, SIZE_TOTAL);
119  J.setZero();
120 
121  unsigned int idx = 0;
122  for (unsigned int i = 0; i < SIZE_TOTAL; ++i) {
123  if (fl(i)) {
124  if (fabs(WJL(i)) > 1e-3)
125  J(idx, i) = 1 / WJL(i);
126  else
127  J(idx, i) = 1.;
128  idx++;
129  }
130  }
131  // if( 0!=freeFloatingIndex )
132  // for( unsigned int i=0;i<freeFloatingIndex;++i )
133  // {
134  // if( fabs(WJL(i))>1e-3 ) J(i,i)=1/WJL(i); else J(i,i)=1.;
135  // }
136 
137  // if( SIZE!=freeFloatingIndex )
138  // for( unsigned int i=freeFloatingIndex;i<SIZE;++i )
139  // {
140  // if( fabs(WJL(i))>1e-3 ) J(i,i+freeFloatingSIZE)=1/WJL(i);
141  // else J(i,i)=1.;
142  // }
143 
144  sotDEBUG(15) << "# Out }" << endl;
145  return J;
146 }
147 
152  sotDEBUGIN(15);
153 
154  const Flags &fl = selectionSIN(time);
155  const Vector q = jointSIN.access(time);
156  const Vector UJL = upperJlSIN.access(time);
157  const Vector LJL = lowerJlSIN.access(time);
158  const Vector WJL = widthJlSINTERN.access(time);
159  const int SIZE = dimensionSOUT.access(time);
160  const Vector::Index SIZE_TOTAL = q.size();
161 
162  sotDEBUG(25) << "q = " << q << endl;
163  sotDEBUG(25) << "ljl = " << LJL << endl;
164  sotDEBUG(25) << "Wjl = " << WJL << endl;
165  sotDEBUG(25) << "dim = " << SIZE << endl;
166 
167  assert(UJL.size() == SIZE_TOTAL);
168  assert(WJL.size() == SIZE_TOTAL);
169  assert(LJL.size() == SIZE_TOTAL);
170  assert(SIZE <= SIZE_TOTAL);
171 
172  error.resize(SIZE);
173 
174  unsigned int parcerr = 0;
175  for (int i = 0; i < SIZE_TOTAL; ++i) {
176  if (fl(i)) {
177  error(parcerr++) = (q(i) - LJL(i)) / WJL(i) * 2 - 1;
178  }
179  }
180 
181  sotDEBUGOUT(15);
182  return error;
183 }
184 
185 void FeatureJointLimits::display(std::ostream &os) const {
186  os << "JointLimits <" << name << "> ... TODO";
187 }
virtual void removeDependenciesFromReference(void)=0
const T & access(const Time &t1)
dynamicgraph::SignalTimeDependent< dynamicgraph::Vector, int > widthJlSINTERN
Eigen::VectorXd Vector
q
SignalPtr< Flags, int > selectionSIN
This vector specifies which dimension are used to perform the computation. For instance let us assume...
int i
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(FeatureJointLimits, "FeatureJointLimits")
SignalTimeDependent< unsigned int, int > dimensionSOUT
Returns the dimension of the feature as an output signal.
void signalRegistration(const SignalArray< int > &signals)
#define sotDEBUGOUT(level)
Definition: debug.hh:212
virtual dynamicgraph::Matrix & computeJacobian(dynamicgraph::Matrix &res, int time)
dynamicgraph::Vector & computeWidthJl(dynamicgraph::Vector &res, const int &time)
#define sotDEBUGIN(level)
Definition: debug.hh:211
virtual void display(std::ostream &os) const
unsigned int getDimension(void) const
Shortest method.
dynamicgraph::SignalPtr< dynamicgraph::Vector, int > lowerJlSIN
virtual const T & access(const Time &t)
virtual void addDependency(const SignalBase< Time > &signal)
#define sotDEBUG(level)
Definition: debug.hh:165
dynamicgraph::SignalPtr< dynamicgraph::Vector, int > upperJlSIN
Class that defines gradient vector for jl avoidance.
This class gives the abstract definition of a feature.
Eigen::MatrixXd Matrix
std::size_t Index
dynamicgraph::SignalPtr< dynamicgraph::Vector, int > jointSIN
virtual void addDependenciesFromReference(void)=0
virtual dynamicgraph::Vector & computeError(dynamicgraph::Vector &res, int time)
void addCommand(const std::string &name, command::Command *command)
SignalTimeDependent< dynamicgraph::Vector, int > errorSOUT
This signal returns the error between the desired value and the current value : . ...


sot-core
Author(s): Olivier Stasse, ostasse@laas.fr
autogenerated on Wed Jun 21 2023 02:51:26