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 
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<size_type>(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 std::size_t SIZE = dimensionSOUT.access(time);
113  const Vector q = jointSIN.access(time);
114  const Flags &fl = selectionSIN(time);
115  // const std::size_t 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  std::size_t idx = 0;
122  for (size_type 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( std::size_t 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( std::size_t 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 size_type 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  std::size_t parcerr = 0;
175  for (size_type 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 }
feature-joint-limits.hh
dynamicgraph::sot::FeatureAbstract::addDependenciesFromReference
virtual void addDependenciesFromReference(void)=0
dynamicgraph::SignalTimeDependent::access
const T & access(const Time &t1)
dynamicgraph::sot::FeatureJointLimits::lowerJlSIN
dynamicgraph::SignalPtr< dynamicgraph::Vector, sigtime_t > lowerJlSIN
Definition: feature-joint-limits.hh:65
factory.hh
dynamicgraph::sot::FeatureAbstract::errorSOUT
SignalTimeDependent< dynamicgraph::Vector, sigtime_t > errorSOUT
This signal returns the error between the desired value and the current value : .
Definition: feature-abstract.hh:185
dynamicgraph
J
J
i
int i
dynamicgraph::sot::FeatureJointLimits::computeJacobian
virtual dynamicgraph::Matrix & computeJacobian(dynamicgraph::Matrix &res, sigtime_t time)
Definition: feature-joint-limits.cpp:109
boost
dynamicgraph::sot::FeatureAbstract::selectionSIN
SignalPtr< Flags, sigtime_t > selectionSIN
This vector specifies which dimension are used to perform the computation. For instance let us assume...
Definition: feature-abstract.hh:173
dynamicgraph::Entity::name
std::string name
dynamicgraph::Matrix
Eigen::MatrixXd Matrix
dynamicgraph::sot::FeatureJointLimits::display
virtual void display(std::ostream &os) const
Definition: feature-joint-limits.cpp:185
dynamicgraph::sot::FeatureAbstract
This class gives the abstract definition of a feature.
Definition: feature-abstract.hh:76
dynamicgraph::sot::FeatureJointLimits
Class that defines gradient vector for jl avoidance.
Definition: feature-joint-limits.hh:46
dynamicgraph::sot::command::featureJointLimits::Actuate
Definition: feature-joint-limits-command.h:26
debug.hh
res
res
dynamicgraph::sot::FeatureJointLimits::computeError
virtual dynamicgraph::Vector & computeError(dynamicgraph::Vector &res, sigtime_t time)
Definition: feature-joint-limits.cpp:151
dynamicgraph::SignalPtr::access
virtual const T & access(const Time &t)
sotDEBUGOUT
#define sotDEBUGOUT(level)
Definition: debug.hh:215
dim
int dim
dynamicgraph::sigtime_t
int64_t sigtime_t
dynamicgraph::SignalTimeDependent::addDependency
virtual void addDependency(const SignalBase< Time > &signal)
sotDEBUGIN
#define sotDEBUGIN(level)
Definition: debug.hh:214
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(FeatureJointLimits, "FeatureJointLimits")
Index
std::size_t Index
dynamicgraph::sot::FeatureJointLimits::upperJlSIN
dynamicgraph::SignalPtr< dynamicgraph::Vector, sigtime_t > upperJlSIN
Definition: feature-joint-limits.hh:64
q
q
dynamicgraph::size_type
Matrix::Index size_type
dynamicgraph::Vector
Eigen::VectorXd Vector
dynamicgraph::sot::FeatureAbstract::removeDependenciesFromReference
virtual void removeDependenciesFromReference(void)=0
exception-feature.hh
dynamicgraph::sot::FeatureJointLimits::jointSIN
dynamicgraph::SignalPtr< dynamicgraph::Vector, sigtime_t > jointSIN
Definition: feature-joint-limits.hh:63
dynamicgraph::sot
dynamicgraph::sot::FeatureAbstract::getDimension
size_type getDimension(void) const
Shortest method.
Definition: feature-abstract.hh:121
dynamicgraph::sot::FeatureJointLimits::widthJlSINTERN
dynamicgraph::SignalTimeDependent< dynamicgraph::Vector, sigtime_t > widthJlSINTERN
Definition: feature-joint-limits.hh:67
dynamicgraph::Entity::addCommand
void addCommand(const std::string &name, command::Command *command)
dynamicgraph::sot::FeatureJointLimits::computeWidthJl
dynamicgraph::Vector & computeWidthJl(dynamicgraph::Vector &res, const sigtime_t &time)
Definition: feature-joint-limits.cpp:90
dynamicgraph::sot::FeatureAbstract::dimensionSOUT
SignalTimeDependent< size_type, sigtime_t > dimensionSOUT
Returns the dimension of the feature as an output signal.
Definition: feature-abstract.hh:196
dynamicgraph::sot::Flags
Definition: flags.hh:33
dynamicgraph::Entity::signalRegistration
void signalRegistration(const SignalArray< sigtime_t > &signals)
compile.name
name
Definition: compile.py:23
sotDEBUG
#define sotDEBUG(level)
Definition: debug.hh:168


sot-core
Author(s): Olivier Stasse, ostasse@laas.fr
autogenerated on Tue Oct 24 2023 02:26:31