feature-generic.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>
17 #include <sot/core/factory.hh>
19 
20 using namespace std;
21 using namespace dynamicgraph::sot;
22 using namespace dynamicgraph;
24 
25 /* --------------------------------------------------------------------- */
26 /* --- CLASS ----------------------------------------------------------- */
27 /* --------------------------------------------------------------------- */
28 
29 FeatureGeneric::FeatureGeneric(const string &pointName)
30  : FeatureAbstract(pointName),
31  dimensionDefault(0),
32  errorSIN(NULL, "sotFeatureGeneric(" + name + ")::input(vector)::errorIN"),
33  jacobianSIN(NULL,
34  "sotFeatureGeneric(" + name + ")::input(matrix)::jacobianIN")
35 
36 {
39 
41 }
42 
43 /* --------------------------------------------------------------------- */
44 /* --------------------------------------------------------------------- */
45 /* --------------------------------------------------------------------- */
46 
48  assert(SP::isReferenceSet());
51 }
52 
54  assert(SP::isReferenceSet());
57 }
58 
59 /* --------------------------------------------------------------------- */
60 /* --------------------------------------------------------------------- */
61 /* --------------------------------------------------------------------- */
62 
63 unsigned int &FeatureGeneric::getDimension(unsigned int &dim, int time) {
64  sotDEBUG(25) << "# In {" << endl;
65 
66  const Flags &fl = selectionSIN.access(time);
67 
68  if (dimensionDefault == 0) dimensionDefault = errorSIN.access(time).size();
69 
70  dim = 0;
71  for (unsigned int i = 0; i < dimensionDefault; ++i)
72  if (fl(i)) dim++;
73 
74  sotDEBUG(25) << "# Out }" << endl;
75  return dim;
76 }
77 
79  const Vector &err = errorSIN.access(time);
80  const Flags &fl = selectionSIN.access(time);
81  const int &dim = dimensionSOUT(time);
82 
83  unsigned int curr = 0;
84  res.resize(dim);
85  if (err.size() < dim) {
88  "Error: dimension uncompatible with des->errorIN size."
89  " (while considering feature <%s>).",
90  getName().c_str());
91  }
92 
93  sotDEBUG(15) << "Err = " << err;
94  sotDEBUG(25) << "Dim = " << dim << endl;
95 
96  if (isReferenceSet()) {
97  const Vector &errDes = getReference()->errorSIN(time);
98  sotDEBUG(15) << "Err* = " << errDes;
99  if (errDes.size() < dim) {
102  "Error: dimension uncompatible with des->errorIN size."
103  " (while considering feature <%s>).",
104  getName().c_str());
105  }
106 
107  for (int i = 0; i < err.size(); ++i)
108  if (fl(i))
109  if (fl(i)) res(curr++) = err(i) - errDes(i);
110  } else {
111  for (int i = 0; i < err.size(); ++i)
112  if (fl(i)) res(curr++) = err(i);
113  }
114 
115  return res;
116 }
117 
119  sotDEBUGIN(15);
120 
121  const Matrix &Jac = jacobianSIN.access(time);
122  const Flags &fl = selectionSIN.access(time);
123  const unsigned int &dim = dimensionSOUT(time);
124 
125  unsigned int curr = 0;
126  res.resize(dim, Jac.cols());
127 
128  for (unsigned int i = 0; curr < dim; ++i)
129  if (fl(i)) {
130  for (int j = 0; j < Jac.cols(); ++j) res(curr, j) = Jac(i, j);
131  curr++;
132  }
133 
134  sotDEBUGOUT(15);
135  return res;
136 }
137 
138 /* --------------------------------------------------------------------- */
139 /* --------------------------------------------------------------------- */
140 /* --------------------------------------------------------------------- */
141 
142 void FeatureGeneric::display(std::ostream &os) const {
143  os << "Generic <" << name << ">: " << std::endl;
144 
145  try {
146  os << " error= " << errorSIN.accessCopy() << endl
147  << " J = " << jacobianSIN.accessCopy() << endl;
148  } catch (ExceptionSignal &e) {
149  os << e.what();
150  }
151 }
virtual void removeDependenciesFromReference(void)=0
#define SOT_THROW
SignalTimeDependent< dynamicgraph::Vector, int > errordotSOUT
Derivative of the error with respect to time: .
virtual dynamicgraph::Vector & computeError(dynamicgraph::Vector &res, int time)
Compute the error between the desired value and the value itself.
Eigen::VectorXd Vector
SignalPtr< Flags, int > selectionSIN
This vector specifies which dimension are used to perform the computation. For instance let us assume...
int i
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 bool isReferenceSet(void) const
dynamicgraph::SignalPtr< dynamicgraph::Matrix, int > jacobianSIN
Input for the Jacobian.
int dim
#define sotDEBUGIN(level)
Definition: debug.hh:211
SignalTimeDependent< dynamicgraph::Matrix, int > jacobianSOUT
Jacobian of the error wrt the robot state: .
unsigned int getDimension(void) const
Shortest method.
SignalPtr< dynamicgraph::Vector, int > errordotSIN
Derivative of the reference value.
virtual const T & access(const Time &t)
virtual void removeDependency(const SignalBase< Time > &signal)
virtual void addDependency(const SignalBase< Time > &signal)
virtual const T & accessCopy() const
#define sotDEBUG(level)
Definition: debug.hh:165
dynamicgraph::Vector::Index dimensionDefault
This class gives the abstract definition of a feature.
const std::string & getName() const
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(FeatureGeneric, "FeatureGeneric")
Eigen::MatrixXd Matrix
virtual void addDependenciesFromReference(void)=0
virtual const char * what() const
virtual void display(std::ostream &os) const
Display the information related to this generic implementation.
virtual dynamicgraph::Matrix & computeJacobian(dynamicgraph::Matrix &res, int time)
Compute the Jacobian of the value according to the robot state..
dynamicgraph::SignalPtr< dynamicgraph::Vector, int > errorSIN
Input for the error.
SignalTimeDependent< dynamicgraph::Vector, int > errorSOUT
This signal returns the error between the desired value and the current value : . ...
err
Class that defines a generic implementation of the abstract interface for features.


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