sot-core  4.11.8
Hierarchical task solver plug-in for dynamic-graph.
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 
20 /* SOT */
21 #include <dynamic-graph/all-signals.h>
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 
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 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:
173  SignalPtr<Flags, int> selectionSIN;
174 
176  SignalPtr<dynamicgraph::Vector, int> errordotSIN;
177 
185  SignalTimeDependent<dynamicgraph::Vector, int> errorSOUT;
186 
189  SignalTimeDependent<dynamicgraph::Vector, int> errordotSOUT;
190 
193  SignalTimeDependent<dynamicgraph::Matrix, int> jacobianSOUT;
194 
196  SignalTimeDependent<unsigned int, int> dimensionSOUT;
197 
200  virtual std::ostream &writeGraph(std::ostream &os) const;
201 
202  virtual SignalTimeDependent<dynamicgraph::Vector, int> &getErrorDot() {
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;
231  FeatureAbstract *ptrA;
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__
dynamicgraph::sot::FeatureAbstract::getDimension
unsigned int getDimension(void) const
Shortest method.
Definition: feature-abstract.hh:121
SOT_CORE_EXPORT
#define SOT_CORE_EXPORT
Definition: api.hh:20
dynamicgraph::sot::FeatureAbstract::jacobianSOUT
SignalTimeDependent< dynamicgraph::Matrix, int > jacobianSOUT
Jacobian of the error wrt the robot state: .
Definition: feature-abstract.hh:193
dynamicgraph::sot::FeatureAbstract::errorSOUT
SignalTimeDependent< dynamicgraph::Vector, int > errorSOUT
This signal returns the error between the desired value and the current value : .
Definition: feature-abstract.hh:185
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:229
dynamicgraph
Definition: abstract-sot-external-interface.hh:17
dynamicgraph::sot::FeatureAbstract::errordotSIN
SignalPtr< dynamicgraph::Vector, int > errordotSIN
Derivative of the reference value.
Definition: feature-abstract.hh:176
dynamicgraph::sot::FeatureReferenceHelper::getReference
FeatureSpecialized * getReference(void)
Definition: feature-abstract.hh:240
dynamicgraph::sot::FeatureAbstract::getClassName
virtual const std::string & getClassName(void) const
Returns the name class.
Definition: feature-abstract.hh:82
dynamicgraph::sot::FeatureAbstract::unsetReference
virtual void unsetReference(void)
Definition: feature-abstract.hh:214
dynamicgraph::sot::FeatureAbstract
This class gives the abstract definition of a feature.
Definition: feature-abstract.hh:76
dynamicgraph::sot::FeatureAbstract::errordotSOUT
SignalTimeDependent< dynamicgraph::Vector, int > errordotSOUT
Derivative of the error with respect to time: .
Definition: feature-abstract.hh:189
dynamicgraph::sot::FeatureReferenceHelper::setReference
void setReference(FeatureAbstract *sdes)
Definition: feature-abstract.hh:245
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:234
api.hh
dynamicgraph::sot::FeatureReferenceHelper::unsetReference
void unsetReference(void)
Definition: feature-abstract.hh:238
dynamicgraph::sot::FeatureReferenceHelper::getReference
const FeatureSpecialized * getReference(void) const
Definition: feature-abstract.hh:241
flags.hh
pool.hh
dynamicgraph::sot::FeatureAbstract::getErrorDot
virtual SignalTimeDependent< dynamicgraph::Vector, int > & getErrorDot()
Definition: feature-abstract.hh:202
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:173
dynamicgraph::sot::FeatureAbstract::isReferenceSet
virtual bool isReferenceSet(void) const
Definition: feature-abstract.hh:217
dynamicgraph::sot::FeatureAbstract::dimensionSOUT
SignalTimeDependent< unsigned int, int > dimensionSOUT
Returns the dimension of the feature as an output signal.
Definition: feature-abstract.hh:196
dynamicgraph::sot::FeatureReferenceHelper::isReferenceSet
bool isReferenceSet(void) const
Definition: feature-abstract.hh:239