frame.h
Go to the documentation of this file.
1 
20 #ifndef __FRAME
21 
22 #define __FRAME
23 
24 #include <vector>
25 
26 #include "configuration.h"
27 #include "vecmath.h"
28 #include "datapairs.h"
29 #include "interfaces.h"
30 
31 namespace robotLibPbD {
32 
39 class CFrame : public CCopyInterface
40 {
41  protected:
42  enum {
50  };
51 
52  std::vector<double> dofs_min, dofs_max;
53  bool _isData;
54 
60  std::string name, baseName;
61  int baseType;
62  int frameType;
63  double time;
64 
65  std::vector<CFrame*> parents, childs;
66  public:
67  unsigned long int counter, baseCounter;
68 
69  enum
70  {
74  };
75 
76  enum
77  {
80  };
81 
82 
83  CFrame();
84  CFrame(char* name);
85  virtual ~CFrame();
86 
87  virtual CMatrix getRelativeToBase();
88  virtual void getRelativeToBase(CMatrix &mat);
89 
90  std::vector<CFrame*>& getParents() { return parents; };
91  void removeParent(CFrame *parent);
92  void addParent(CFrame *parent);
93  int getParentId(CFrame *parent) { for (unsigned int i=0; i<parents.size(); i++) if (parents[i] == parent) return (int)i; return -1; };
94 
95  bool isData() { return _isData; };
96  bool setData(bool value) { _isData = value; return value;};
97  bool isValid() { return _isValid; };
98  bool isUpdated() { return _isUpdated; };
99  void lock() { _isLocked = true; };
100  void unlock() { _isLocked = false; };
101 
102  virtual void setName(const char* str);
103  virtual char* getName() { return (char*) name.c_str(); };
104  virtual void setBaseName(const char* str) { baseName = str; };
105  virtual char* getBaseName() { return (char*) baseName.c_str(); };
106  virtual bool hasName(char* str);
107 
108  virtual void setBaseType(unsigned int type) { baseType = type; };
109  virtual unsigned int getBaseType() { return baseType; };
110 
111  virtual void setRelativePose(const CMatrix &value);
112 
113  virtual void setFrameType(unsigned int type) { frameType = type; };
114  virtual unsigned int getFrameType() { return frameType; };
115 
116  virtual CFrame* getBase();
117  virtual void setBase(CFrame* base);
118  virtual CMatrix getPose() { return pose; };
119  virtual void getPose(CMatrix &pose) { pose = this->pose; };
120  inline virtual void setPose(const CMatrix &pose) { this->pose = pose; invalidate(); };
121  inline virtual void setPoseNoInvalidation(const CMatrix &pose) { this->pose = pose;};
122 
123  virtual CFrame* getByName(char* str);
124  virtual void update();
125  virtual void invalidate();
126  virtual void invalidateAll();
127 
128  void getDofs(std::vector<unsigned int> &dofs);
129  void getDofs(std::vector<double> &dofs_min, std::vector<double> &dofs_max);
130  void setDofs(const std::vector<double> &dofs_min, const std::vector<double> &dofs_max);
131 
132 
133  virtual void setTime(double time) { this->time = time; };
134  virtual double getTime() { return time; };
135  virtual void* getCopy();
136 };
137 
139 {
140  protected:
142  public:
143  CFrameInterface() { frame = NULL; };
144  virtual void setFrame(CFrame* frame) { this->frame = frame; };
145  virtual CFrame* getFrame() { return this->frame; };
146  virtual void invalidate() { if (frame != NULL) frame->invalidate(); };
147  virtual void invalidateAll() { if (frame != NULL) frame->invalidateAll(); };
148  virtual std::string getFrameAsXml();
149 };
150 
151 
154 class CFrameReference : public CFrame
155 {
156  protected:
158  public:
159  CFrameReference(CFrame *reference);
160  CFrameReference();
161 
162  void setPose(const CMatrix &pose) { relativePose = this->pose = pose; };
165 };
166 
169 class CFrameCombination : public CFrame
170 {
171  protected:
173 
174  std::string baseOrientationName;
175  public:
176 
178  virtual ~CFrameCombination();
179 
182 
183  virtual void setBaseOrientationName(const char* str) { baseOrientationName = str; };
184  virtual char* getBaseOrientationName() { return (char*) baseOrientationName.c_str(); };
185 
186  virtual CFrame* getBaseOrientation();
187  virtual void setBaseOrientation(CFrame* base);
188 
189  virtual void invalidate();
190  virtual void invalidateAll();
191 
192  virtual void* getCopy();
193 };
194 
195 
197 {
198  public:
199  std::vector<CFrame*> frames;
200 
201  CFrameContainer() { frames.reserve(1000); };
202  virtual ~CFrameContainer() { clear(); };
203 
204  void clear();
205 
206  unsigned int size() { return frames.size(); };
207  int add(CFrame* newFrame);
208  bool getFrameByName(const char* name, CFrame* &frame);
209  int getFrameByName(const char* name, bool create = false);
210  bool setBase(char* frame, char* base);
213  void invalidate(bool time = false);
214  bool xmlToFrame(CFrame *frame, TiXmlElement* frameNode, bool create = false);
215  bool xmlToFrame(CFrame *frame, TiXmlElement* frameNode, DataPairs &additionalData, bool create = false);
216  bool xmlToFrameCombination(CFrameCombination *frame, TiXmlElement* frameNode, DataPairs &additionalData, bool create = false);
217 
218  void updateBaseLinks();
219  void updateBaseLinks(std::vector<CFrame*> &frames);
220  void updateBaseLinks(CFrame* frame);
221  void loadFromFile(const char* filename);
222  void loadFromFile(const char* filename, DataPairs &additionalData, CConfiguration &config, bool loadAll);
223 
224  CFrame* getFrame(unsigned int id) { if (id < frames.size()) return frames[id]; return NULL; };
225  CFrame* getFrame(const char* name) { int id = getFrameByName(name, false); if (id < 0) return NULL; return frames[id]; };
226 
227  std::vector<CFrame*> getFrames() { return frames; };
228  int compareBase(CFrame* first, CFrame* second);
229 
230  void checkBaseFrames();
231 
232  static bool isRelativeTo(CFrame* first, CFrame* relative);
233 
234  void resolve(std::vector<std::string> &in, std::vector<CFrame*> &out);
235 };
236 
237 
238 
241 class CDh
242 {
243  public:
244  std::string ivModel;
245  double speedFactor;
247  bool useAxis;
249  double rot_z;
250  double trans_z;
251  double rot_x;
252  double trans_x;
253  double angle;
254  double sgn;
255  int id;
256  CDh();
257  double min, max;
258  double getAngle();
259  void setAngle(double angle);
260  void set(double rot_z, double trans_z, double rot_x, double trans_x);
261 };
262 
263 
267 {
268  protected:
269  std::string name;
271  public:
272  void setName(std::string value) { this->name = value; };
273  std::string getName() { return this->name; };
275 
277 
279  int length;
280 
282 
283  CKinematicChain();
284  virtual ~CKinematicChain();
285 
288  void update();
289  CDh& getDhParameters(unsigned int id);
290  CFrame* getFrame(unsigned int id);
291 
292  CFrame* getLastFrame();
295  CFrame* getByName(char* str);
296 
299  //void getPose(CMatrix &result);
300 
303  void setLength(int len);
304  unsigned int getLength() { return (unsigned int) length; };
305 
308  void loadFromXml(CConfiguration &config, TiXmlElement* kinChainsNode, CFrameContainer &container);
309 
310  void invalidate();
311 };
312 
318 {
319  public:
320  int length;
321 
323 
324  unsigned int getLength() { return (unsigned int) length; };
325 
327  virtual ~CKinematicChainContainer();
328 
329  void update();
330  void loadFromXml(CConfiguration &config, TiXmlElement* kinChainsNode, CFrameContainer &container);
331 };
332 
334 {
335  if (_isValid || _isLocked)
336  {
337  return relativePose;
338  }
339  _isValid = true;
340  reference->getRelativeToBase(relativePose);
341  pose = relativePose;
342  return relativePose;
343 }
344 
346 {
347  if (_isValid || _isLocked)
348  {
349  mat = relativePose;
350  return;
351  }
352  _isValid = true;
353 
354  reference->getRelativeToBase(relativePose);
355  mat = pose = relativePose;
356 }
357 
358 
360 {
361  if (_isValid || _isLocked)
362  {
363  return relativePose;
364  }
365 
366  _isValid = true;
367 
368  if (getBaseOrientation() != NULL)
369  {
370  getBaseOrientation()->getRelativeToBase(relativePose);
371  relativePose.a[12] = 0.0;
372  relativePose.a[13] = 0.0;
373  relativePose.a[14] = 0.0;
374  }
375  else
377 
378  if (getBase() != NULL)
379  {
381  relativePose.a[12] = tmpMatrix.a[12];
382  relativePose.a[13] = tmpMatrix.a[13];
383  relativePose.a[14] = tmpMatrix.a[14];
384  }
385 
387 
388  return relativePose;
389 }
390 
392 {
393  if (_isValid || _isLocked)
394  {
395  mat = relativePose;
396  return;
397  }
398 
399  _isValid = true;
400 
401  if (getBaseOrientation() != NULL)
402  {
403  getBaseOrientation()->getRelativeToBase(relativePose);
404  relativePose.a[12] = 0.0;
405  relativePose.a[13] = 0.0;
406  relativePose.a[14] = 0.0;
407  }
408  else
410 
411  if (getBase() != NULL)
412  {
414 
415  relativePose.a[12] = tmpMatrix.a[12];
416  relativePose.a[13] = tmpMatrix.a[13];
417  relativePose.a[14] = tmpMatrix.a[14];
418  }
419 
421 
422  mat = relativePose;
423 }
424 
426 {
427  for (int i=0; i<length; i++)
428  chain[i].update();
429 }
430 
432 {
433  //for (int i=0; i<length; i++)
434  // frames[i]->invalidate();
435 
436  frames[0]->invalidate();
437  for (int i=0; i<length; i++)
438  {
439  tmpMatrix.setDh(dhParameters[i]);
440  frames[i]->setPoseNoInvalidation(tmpMatrix);
441  }
442 }
443 
444 
446 {
447  frames[0]->invalidate();
448  //for (int i=0; i<length; i++)
449  // frames[i]->invalidate();
450 }
451 
452 
454 {
455  for (unsigned int i=0; i<frames.size(); i++)
456  {
457  if (time)
458  {
459  frames[i]->unlock();
460  }
461  frames[i]->invalidate();
462  }
463 }
464 
465 
467 {
468  //_isUpdated = false;
469  _isValid = false;
470 
471  //printf("Frame: Invalidating %s\n", name.c_str());
472  /*
473  if (_isLocked)// || time >= 0)
474  return;
475 
476  _isValid = false; */
477  for (unsigned int i=0; i<parents.size(); i++)
478  parents[i]->invalidate();
479 }
480 
481 
483 {
484  return base;
485 }
486 
487 
489 {
490  if (_isValid || _isLocked)
491  {
492  mat = relativePose;
493  return;
494  }
495 
496  if (getBase() != NULL)
497  {
500  } else relativePose = pose;
501 
502  _isValid = true;
503 
504  mat = relativePose;
505 }
506 
507 
509  {
510 
511  if (_isValid || _isLocked)
512  {
513  return relativePose;
514  }
515 
516  if (getBase() != NULL)
517  {
520  } else relativePose = pose;
521 
522  _isValid = true;
523 
524  return relativePose;
525  }
526 };
527 
528 #endif
std::vector< double > dofs_max
Definition: frame.h:52
bool rotationalDof
Definition: frame.h:246
double trans_x
Translation offset along rotated x-axis.
Definition: frame.h:252
virtual void getPose(CMatrix &pose)
Definition: frame.h:119
int getParentId(CFrame *parent)
Definition: frame.h:93
virtual CFrame * getFrame()
Definition: frame.h:145
Denavit Hartenberg Link information.
Definition: frame.h:241
virtual bool hasName(char *str)
Definition: frame.cpp:605
CFrame * getFrame(const char *name)
Definition: frame.h:225
CFrame ** frames
Array of frames associated with every link in the chain.
Definition: frame.h:278
virtual void setBase(CFrame *base)
Definition: frame.cpp:587
std::string baseName
Name associated with frame.
Definition: frame.h:60
unsigned long int counter
Definition: frame.h:67
int id
Index of servo motor associated with the frame.
Definition: frame.h:255
void invalidate(bool time=false)
Transforms a <FRAME> (xml object) into a frame.
Definition: frame.h:453
void setDh(const robotLibPbD::CDh &dh)
Creates Denavit Hartenberg matrix.
Definition: vecmath.cpp:156
virtual void update()
Updates the frames.
Definition: frame.cpp:615
void mul(const CMatrix &first, const CMatrix &second)
Assigns product of two matrices to matrix.
Definition: vecmath.h:380
Frame in cartesian space.
Definition: frame.h:169
void setName(std::string value)
Definition: frame.h:272
void update()
Updates denavit hartenberg matrices of all chains.
Definition: frame.h:425
virtual CFrame * getByName(char *str)
Returns frame associated with /a str.
Definition: frame.cpp:393
double sgn
Direction of rotation (+1.0 clockwise, -1.0 counterclockwise)
Definition: frame.h:254
void getDofs(std::vector< unsigned int > &dofs)
Definition: frame.cpp:501
Kinematic chain.
Definition: frame.h:266
CKinematicChain * chain
Array of kinematic chains.
Definition: frame.h:322
PRECISION a[16]
Definition: vecmath.h:190
std::string ivModel
Definition: frame.h:244
virtual CMatrix getRelativeToBase()
Returns pose in the base (frame with no predecessor) frame.
Definition: frame.h:508
Frame in cartesian space.
Definition: frame.h:154
CFrame * baseOrientation
(Relative) base frame (f.e. the static robot frame or the frame of the previous link in a kinematic c...
Definition: frame.h:172
int length
Number of kinematic chains.
Definition: frame.h:320
void mulNoAlloc(const CMatrix &first, const CMatrix &second)
Definition: vecmath.h:405
virtual ~CFrame()
Definition: frame.cpp:551
virtual void setBaseOrientationName(const char *str)
Definition: frame.h:183
std::vector< CFrame * > getFrames()
Definition: frame.h:227
CMatrix getRelativeToBase()
Returns pose in the base (frame with no predecessor) frame.
Definition: frame.h:333
virtual void setRelativePose(const CMatrix &value)
Definition: frame.cpp:576
double rot_x
Rotation offset around rotated x-axis.
Definition: frame.h:251
Data Storage Class (Attribute-Value Pairs)
Definition: datapairs.h:33
bool setData(bool value)
Definition: frame.h:96
virtual void setPoseNoInvalidation(const CMatrix &pose)
Definition: frame.h:121
virtual unsigned int getFrameType()
Definition: frame.h:114
CMatrix pose
Translation and rotation relative to base frame (f.e. denavit hartenberg matrix)
Definition: frame.h:58
unsigned int getLength()
Definition: frame.h:304
double rot_z
Rotation offset around z-axis.
Definition: frame.h:249
std::string name
Definition: frame.h:60
Homogenous vector.
Definition: vecmath.h:57
virtual void setFrame(CFrame *frame)
Definition: frame.h:144
bool isData()
Definition: frame.h:95
virtual void setBaseName(const char *str)
Definition: frame.h:104
std::vector< CFrame * > frames
Definition: frame.h:199
virtual void setTime(double time)
Definition: frame.h:133
std::vector< CFrame * > childs
Definition: frame.h:65
virtual char * getBaseName()
Definition: frame.h:105
CDh * dhParameters
Array of denavit hartenberg parameters.
Definition: frame.h:276
double speedFactor
Definition: frame.h:245
Homogenous matrix.
Definition: vecmath.h:187
bool useAxis
Definition: frame.h:247
std::string baseOrientationName
Name associated with frame.
Definition: frame.h:174
virtual void * getCopy()
Definition: frame.cpp:451
void setPose(const CMatrix &pose)
Definition: frame.h:162
double angle
Current angle of rotation aroung z-axis (changes with the real servo position)
Definition: frame.h:253
virtual void invalidateAll()
Definition: frame.cpp:528
CMatrix tmpMatrix
Definition: frame.h:55
virtual void invalidate()
Definition: frame.h:466
virtual void setBaseType(unsigned int type)
Definition: frame.h:108
double trans_z
Translation offset along z-axis.
Definition: frame.h:250
virtual char * getName()
Definition: frame.h:103
std::vector< CFrame * > parents
Definition: frame.h:65
virtual void setPose(const CMatrix &pose)
Definition: frame.h:120
Robot types with implemented inverse kinematics.
Definition: frame.h:39
std::vector< CFrame * > & getParents()
Definition: frame.h:90
virtual CFrame * getBase()
Definition: frame.h:482
unsigned long int baseCounter
Definition: frame.h:67
virtual CMatrix getPose()
Definition: frame.h:118
CMatrix relativePose
Definition: frame.h:59
unsigned int size()
Definition: frame.h:206
void addParent(CFrame *parent)
Definition: frame.cpp:426
CFrame * getFrame(unsigned int id)
Definition: frame.h:224
double min
Definition: frame.h:257
bool isUpdated()
Definition: frame.h:98
virtual void invalidate()
Definition: frame.cpp:1292
virtual void setName(const char *str)
Definition: frame.cpp:610
std::vector< double > dofs_min
Definition: frame.h:52
virtual void invalidate()
Definition: frame.h:146
virtual void setFrameType(unsigned int type)
Definition: frame.h:113
Kinematic Robot Model.
Definition: frame.h:317
void setDofs(const std::vector< double > &dofs_min, const std::vector< double > &dofs_max)
Definition: frame.cpp:84
virtual ~CFrameContainer()
Definition: frame.h:202
Configuration file wrapper.
Definition: configuration.h:34
virtual void invalidateAll()
Definition: frame.h:147
CFrame * base
(Relative) base frame (f.e. the static robot frame or the frame of the previous link in a kinematic c...
Definition: frame.h:57
CMatrix getRelativeToBase()
Returns pose in the base (frame with no predecessor) frame.
Definition: frame.h:359
virtual char * getBaseOrientationName()
Definition: frame.h:184
bool isValid()
Definition: frame.h:97
int length
Number of links in the chain.
Definition: frame.h:279
virtual unsigned int getBaseType()
Definition: frame.h:109
virtual double getTime()
Definition: frame.h:134
void removeParent(CFrame *parent)
Definition: frame.cpp:402
void update()
Updates denavit hartenberg matrices.
Definition: frame.h:431


asr_kinematic_chain_optimizer
Author(s): Aumann Florian, Heller Florian, Jäkel Rainer, Wittenbeck Valerij
autogenerated on Mon Jun 10 2019 12:35:36