feature-abstract.hh
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 #ifndef __SOT_FEATURE_ABSTRACT_H__
11 #define __SOT_FEATURE_ABSTRACT_H__
12 
13 /* --------------------------------------------------------------------- */
14 /* --- INCLUDE --------------------------------------------------------- */
15 /* --------------------------------------------------------------------- */
16 
17 /* Matrix */
18 #include <dynamic-graph/linear-algebra.h>
19 namespace dg = dynamicgraph;
20 
21 /* SOT */
22 #include "sot/core/api.hh"
23 #include "sot/core/deprecated.hh"
24 #include <dynamic-graph/all-signals.h>
25 #include <dynamic-graph/entity.h>
26 #include <sot/core/flags.hh>
27 #include <sot/core/pool.hh>
28 
29 /* STD */
30 #include <string>
31 
32 namespace dynamicgraph {
33 namespace sot {
34 
35 /* --------------------------------------------------------------------- */
36 /* --- CLASS ----------------------------------------------------------- */
37 /* --------------------------------------------------------------------- */
38 
76 class SOT_CORE_EXPORT FeatureAbstract : public Entity {
77 public:
79  static const std::string CLASS_NAME;
80 
82  virtual const std::string &getClassName(void) const { return CLASS_NAME; }
83 
85  void featureRegistration(void);
86 
87  void initCommands(void);
88 
89 public:
91  FeatureAbstract(const std::string &name);
93  virtual ~FeatureAbstract(void){};
94 
104  virtual unsigned int &getDimension(unsigned int &res, int time) = 0;
105 
111  inline unsigned int getDimension(int time) {
112  unsigned int res;
113  getDimension(res, time);
114  return res;
115  }
116 
121  inline unsigned int getDimension(void) const {
122  return dimensionSOUT.accessCopy();
123  }
140  virtual dg::Vector &computeError(dg::Vector &res, int time) = 0;
141 
147  virtual dg::Matrix &computeJacobian(dg::Matrix &res, int time) = 0;
148 
153  virtual dg::Vector &computeErrorDot(dg::Vector &res, int time);
154 
157  /* --- SIGNALS ------------------------------------------------------------ */
158 public:
170  SignalPtr<Flags, int> selectionSIN;
171 
173  SignalPtr<dg::Vector, int> errordotSIN;
174 
182  SignalTimeDependent<dg::Vector, int> errorSOUT;
183 
186  SignalTimeDependent<dg::Vector, int> errordotSOUT;
187 
190  SignalTimeDependent<dg::Matrix, int> jacobianSOUT;
191 
193  SignalTimeDependent<unsigned int, int> dimensionSOUT;
194 
197  virtual std::ostream &writeGraph(std::ostream &os) const;
198 
199  virtual SignalTimeDependent<dg::Vector, int> &getErrorDot() {
200  return errordotSOUT;
201  }
202 
205  /* --- REFERENCE VALUE S* ------------------------------------------------- */
206 public:
210  virtual void setReference(FeatureAbstract *sdes) = 0;
211  virtual void unsetReference(void) { setReference(NULL); }
212  virtual const FeatureAbstract *getReferenceAbstract(void) const = 0;
213  virtual FeatureAbstract *getReferenceAbstract(void) = 0;
214  virtual bool isReferenceSet(void) const { return false; }
215 
216  virtual void addDependenciesFromReference(void) = 0;
217  virtual void removeDependenciesFromReference(void) = 0;
218 
219  /* Commands for bindings. */
220  void setReferenceByName(const std::string &name);
221  std::string getReferenceByName(void) const;
223 };
224 
225 template <class FeatureSpecialized> class FeatureReferenceHelper {
226  FeatureSpecialized *ptr;
227  FeatureAbstract *ptrA;
228 
229 public:
230  FeatureReferenceHelper(void) : ptr(NULL) {}
231 
232  void setReference(FeatureAbstract *sdes);
233  // void setReferenceByName( const std::string & name );
234  void unsetReference(void) { setReference(NULL); }
235  bool isReferenceSet(void) const { return ptr != NULL; }
236  FeatureSpecialized *getReference(void) { return ptr; }
237  const FeatureSpecialized *getReference(void) const { return ptr; }
238 };
239 
240 template <class FeatureSpecialized>
242  FeatureAbstract *sdes) {
243  ptr = dynamic_cast<FeatureSpecialized *>(sdes);
244  ptrA = ptr;
245 }
246 
247 #define DECLARE_REFERENCE_FUNCTIONS(FeatureSpecialized) \
248  typedef FeatureReferenceHelper<FeatureSpecialized> SP; \
249  virtual void setReference(FeatureAbstract *sdes) { \
250  if (sdes == NULL) { \
251  /* UNSET */ \
252  if (SP::isReferenceSet()) \
253  removeDependenciesFromReference(); \
254  SP::unsetReference(); \
255  } else { \
256  /* SET */ \
257  SP::setReference(sdes); \
258  if (SP::isReferenceSet()) \
259  addDependenciesFromReference(); \
260  } \
261  } \
262  virtual const FeatureAbstract *getReferenceAbstract(void) const { \
263  return SP::getReference(); \
264  } \
265  virtual FeatureAbstract *getReferenceAbstract(void) { \
266  return (FeatureAbstract *)SP::getReference(); \
267  } \
268  bool isReferenceSet(void) const { return SP::isReferenceSet(); } \
269  virtual void addDependenciesFromReference(void); \
270  virtual void removeDependenciesFromReference(void)
271 /* END OF define DECLARE_REFERENCE_FUNCTIONS */
272 
273 #define DECLARE_NO_REFERENCE \
274  virtual void setReference(FeatureAbstract *) {} \
275  virtual const FeatureAbstract *getReferenceAbstract(void) const { \
276  return NULL; \
277  } \
278  virtual FeatureAbstract *getReferenceAbstract(void) { return NULL; } \
279  virtual void addDependenciesFromReference(void) {} \
280  virtual void removeDependenciesFromReference(void) {} \
281  /* To force a ; */ bool NO_REFERENCE
282 /* END OF define DECLARE_REFERENCE_FUNCTIONS */
283 
284 } // namespace sot
285 } // namespace dynamicgraph
286 
287 #endif // #ifndef __SOT_FEATURE_ABSTRACT_H__
dynamicgraph::sot::FeatureAbstract::getDimension
unsigned int getDimension(void) const
Shortest method.
Definition: feature-abstract.hh:121
dynamicgraph::sot::FeatureAbstract::jacobianSOUT
SignalTimeDependent< dg::Matrix, int > jacobianSOUT
Jacobian of the error wrt the robot state: .
Definition: feature-abstract.hh:190
SOT_CORE_EXPORT
#define SOT_CORE_EXPORT
Definition: api.hh:20
dynamicgraph::sot::FeatureAbstract::~FeatureAbstract
virtual ~FeatureAbstract(void)
Default destructor.
Definition: feature-abstract.hh:93
dynamicgraph::sot::FeatureAbstract::CLASS_NAME
static const std::string CLASS_NAME
Store the name of the class.
Definition: feature-abstract.hh:79
dynamicgraph::sot::FeatureReferenceHelper
Definition: feature-abstract.hh:225
dynamicgraph
Definition: abstract-sot-external-interface.hh:17
dynamicgraph::sot::FeatureReferenceHelper::getReference
FeatureSpecialized * getReference(void)
Definition: feature-abstract.hh:236
dynamicgraph::sot::FeatureAbstract::errordotSOUT
SignalTimeDependent< dg::Vector, int > errordotSOUT
Derivative of the error with respect to time: .
Definition: feature-abstract.hh:186
dynamicgraph::sot::FeatureAbstract::getClassName
virtual const std::string & getClassName(void) const
Returns the name class.
Definition: feature-abstract.hh:82
dynamicgraph::sot::FeatureAbstract::errorSOUT
SignalTimeDependent< dg::Vector, int > errorSOUT
This signal returns the error between the desired value and the current value : .
Definition: feature-abstract.hh:182
dynamicgraph::sot::FeatureAbstract::getErrorDot
virtual SignalTimeDependent< dg::Vector, int > & getErrorDot()
Definition: feature-abstract.hh:199
dynamicgraph::sot::FeatureAbstract::unsetReference
virtual void unsetReference(void)
Definition: feature-abstract.hh:211
dynamicgraph::sot::FeatureAbstract
This class gives the abstract definition of a feature.
Definition: feature-abstract.hh:76
deprecated.hh
dynamicgraph::sot::FeatureReferenceHelper::setReference
void setReference(FeatureAbstract *sdes)
Definition: feature-abstract.hh:241
dynamicgraph::sot::FeatureAbstract::getDimension
unsigned int getDimension(int time)
Short method.
Definition: feature-abstract.hh:111
dynamicgraph::sot::FeatureReferenceHelper::FeatureReferenceHelper
FeatureReferenceHelper(void)
Definition: feature-abstract.hh:230
dynamicgraph::sot::FeatureAbstract::errordotSIN
SignalPtr< dg::Vector, int > errordotSIN
Derivative of the reference value.
Definition: feature-abstract.hh:173
api.hh
dynamicgraph::sot::FeatureReferenceHelper::unsetReference
void unsetReference(void)
Definition: feature-abstract.hh:234
dynamicgraph::sot::FeatureReferenceHelper::getReference
const FeatureSpecialized * getReference(void) const
Definition: feature-abstract.hh:237
flags.hh
pool.hh
dynamicgraph::sot::FeatureAbstract::selectionSIN
SignalPtr< Flags, int > selectionSIN
This vector specifies which dimension are used to perform the computation. For instance let us assume...
Definition: feature-abstract.hh:170
dynamicgraph::sot::FeatureAbstract::isReferenceSet
virtual bool isReferenceSet(void) const
Definition: feature-abstract.hh:214
dynamicgraph::sot::FeatureAbstract::dimensionSOUT
SignalTimeDependent< unsigned int, int > dimensionSOUT
Returns the dimension of the feature as an output signal.
Definition: feature-abstract.hh:193
dynamicgraph::sot::FeatureReferenceHelper::isReferenceSet
bool isReferenceSet(void) const
Definition: feature-abstract.hh:235