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 */
19 
20 /* SOT */
22 #include <dynamic-graph/entity.h>
23 
24 #include <sot/core/flags.hh>
25 #include <sot/core/pool.hh>
26 
27 #include "sot/core/api.hh"
28 
29 /* STD */
30 #include <string>
31 
32 namespace dynamicgraph {
33 namespace sot {
34 
35 /* --------------------------------------------------------------------- */
36 /* --- CLASS ----------------------------------------------------------- */
37 /* --------------------------------------------------------------------- */
38 
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 dynamicgraph::Vector &computeError(dynamicgraph::Vector &res,
141  int time) = 0;
142 
148  virtual dynamicgraph::Matrix &computeJacobian(dynamicgraph::Matrix &res,
149  int time) = 0;
150 
155  virtual dynamicgraph::Vector &computeErrorDot(dynamicgraph::Vector &res,
156  int time);
157 
160  /* --- SIGNALS ------------------------------------------------------------ */
161  public:
174 
177 
186 
190 
194 
197 
200  virtual std::ostream &writeGraph(std::ostream &os) const;
201 
203  return errordotSOUT;
204  }
205 
208  /* --- REFERENCE VALUE S* ------------------------------------------------- */
209  public:
213  virtual void setReference(FeatureAbstract *sdes) = 0;
214  virtual void unsetReference(void) { setReference(NULL); }
215  virtual const FeatureAbstract *getReferenceAbstract(void) const = 0;
216  virtual FeatureAbstract *getReferenceAbstract(void) = 0;
217  virtual bool isReferenceSet(void) const { return false; }
218 
219  virtual void addDependenciesFromReference(void) = 0;
220  virtual void removeDependenciesFromReference(void) = 0;
221 
222  /* Commands for bindings. */
223  void setReferenceByName(const std::string &name);
224  std::string getReferenceByName(void) const;
226 };
227 
228 template <class FeatureSpecialized>
230  FeatureSpecialized *ptr;
232 
233  public:
234  FeatureReferenceHelper(void) : ptr(NULL) {}
235 
236  void setReference(FeatureAbstract *sdes);
237  // void setReferenceByName( const std::string & name );
238  void unsetReference(void) { setReference(NULL); }
239  bool isReferenceSet(void) const { return ptr != NULL; }
240  FeatureSpecialized *getReference(void) { return ptr; }
241  const FeatureSpecialized *getReference(void) const { return ptr; }
242 };
243 
244 template <class FeatureSpecialized>
246  FeatureAbstract *sdes) {
247  ptr = dynamic_cast<FeatureSpecialized *>(sdes);
248  ptrA = ptr;
249 }
250 
251 #define DECLARE_REFERENCE_FUNCTIONS(FeatureSpecialized) \
252  typedef FeatureReferenceHelper<FeatureSpecialized> SP; \
253  virtual void setReference(FeatureAbstract *sdes) { \
254  if (sdes == NULL) { \
255  /* UNSET */ \
256  if (SP::isReferenceSet()) removeDependenciesFromReference(); \
257  SP::unsetReference(); \
258  } else { \
259  /* SET */ \
260  SP::setReference(sdes); \
261  if (SP::isReferenceSet()) addDependenciesFromReference(); \
262  } \
263  } \
264  virtual const FeatureAbstract *getReferenceAbstract(void) const { \
265  return SP::getReference(); \
266  } \
267  virtual FeatureAbstract *getReferenceAbstract(void) { \
268  return (FeatureAbstract *)SP::getReference(); \
269  } \
270  bool isReferenceSet(void) const { return SP::isReferenceSet(); } \
271  virtual void addDependenciesFromReference(void); \
272  virtual void removeDependenciesFromReference(void)
273 /* END OF define DECLARE_REFERENCE_FUNCTIONS */
274 
275 #define DECLARE_NO_REFERENCE \
276  virtual void setReference(FeatureAbstract *) {} \
277  virtual const FeatureAbstract *getReferenceAbstract(void) const { \
278  return NULL; \
279  } \
280  virtual FeatureAbstract *getReferenceAbstract(void) { return NULL; } \
281  virtual void addDependenciesFromReference(void) {} \
282  virtual void removeDependenciesFromReference(void) {} \
283  /* To force a ; */ bool NO_REFERENCE
284 /* END OF define DECLARE_REFERENCE_FUNCTIONS */
285 
286 } // namespace sot
287 } // namespace dynamicgraph
288 
289 #endif // #ifndef __SOT_FEATURE_ABSTRACT_H__
SignalTimeDependent< dynamicgraph::Vector, int > errordotSOUT
Derivative of the error with respect to time: .
Eigen::VectorXd Vector
SignalPtr< Flags, int > selectionSIN
This vector specifies which dimension are used to perform the computation. For instance let us assume...
SignalTimeDependent< unsigned int, int > dimensionSOUT
Returns the dimension of the feature as an output signal.
unsigned int getDimension(int time)
Short method.
virtual bool isReferenceSet(void) const
static const std::string CLASS_NAME
Store the name of the class.
#define SOT_CORE_EXPORT
Definition: api.hh:20
SignalTimeDependent< dynamicgraph::Matrix, int > jacobianSOUT
Jacobian of the error wrt the robot state: .
unsigned int getDimension(void) const
Shortest method.
virtual ~FeatureAbstract(void)
Default destructor.
SignalPtr< dynamicgraph::Vector, int > errordotSIN
Derivative of the reference value.
void setReference(FeatureAbstract *sdes)
virtual const std::string & getClassName(void) const
Returns the name class.
const FeatureSpecialized * getReference(void) const
virtual SignalTimeDependent< dynamicgraph::Vector, int > & getErrorDot()
This class gives the abstract definition of a feature.
res
Eigen::MatrixXd Matrix
void writeGraph(const char *filename)
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