GAMS  1.2.2
ReferenceFrameFwd.h
Go to the documentation of this file.
1 
54 #ifndef _GAMS_POSE_REFERENCE_FRAME_FWD_H_
55 #define _GAMS_POSE_REFERENCE_FRAME_FWD_H_
56 
57 #include "gams/GamsExport.h"
58 #include "gams/CPP11_compat.h"
59 #include "madara/knowledge/KnowledgeBase.h"
60 #include <stdexcept>
61 #include <sstream>
62 
63 namespace gams { namespace pose {
64 
65 class ReferenceFrameIdentity;
66 class ReferenceFrameVersion;
67 struct ReferenceFrameType;
68 class Pose;
69 class Position;
70 class Orientation;
71 class ReferenceFrame;
72 
73 MADARA_MAKE_VAL_SUPPORT_TEST(transform_to, x,
74  (x.transform_to(std::declval<ReferenceFrame>())));
75 
84 class GAMS_EXPORT FrameEvalSettings : public madara::knowledge::EvalSettings
85 {
86 public:
87  using Base = madara::knowledge::EvalSettings;
88 
89  static const FrameEvalSettings DEFAULT;
90 
91  FrameEvalSettings(Base base = Base{true}) : Base(std::move(base)) {}
92 
93  FrameEvalSettings(std::string prefix, Base base = Base{true})
94  : Base(std::move(base)),
95  prefix_(std::make_shared<std::string>(std::move(prefix))) {}
96 
97  FrameEvalSettings(std::nullptr_t, Base base = Base{true})
98  : FrameEvalSettings(std::move(base)) {}
99 
100  FrameEvalSettings(const char *prefix, Base base = Base{true})
101  : FrameEvalSettings(std::string(prefix), std::move(base)) {}
102 
103  static const std::string &default_prefix() {
104  return default_prefix_;
105  }
106 
107  const std::string &prefix() const {
108  if (prefix_) {
109  return *prefix_;
110  } else {
111  return default_prefix();
112  }
113  }
114 
115  void prefix(std::string prefix) {
116  prefix_ = std::make_shared<std::string>(std::move(prefix));
117  }
118 
119 private:
120  static const std::string default_prefix_;
121 
122  std::shared_ptr<std::string> prefix_;
123 };
124 
163 {
164 private:
165  std::shared_ptr<ReferenceFrameVersion> impl_;
166 
167 public:
175  ReferenceFrame() : impl_() {}
176 
185  ReferenceFrame(std::shared_ptr<ReferenceFrameVersion> impl) :
186  impl_(std::move(impl)) {}
187 
197  template<typename P,
198  typename std::enable_if<
199  supports_transform_to<P>::value, void*>::type = nullptr>
200  explicit ReferenceFrame(
201  P &&origin,
202  uint64_t timestamp = -1)
203  : impl_(std::make_shared<ReferenceFrameVersion>(
204  std::forward<P>(origin), timestamp)) {}
205 
217  template<typename P,
218  typename std::enable_if<
219  supports_transform_to<P>::value, void*>::type = nullptr>
221  const ReferenceFrameType *type,
222  P &&origin,
223  uint64_t timestamp = -1)
224  : impl_(std::make_shared<ReferenceFrameVersion>(
225  type, std::forward<P>(origin), timestamp)) {}
226 
237  template<typename P,
238  typename std::enable_if<
239  supports_transform_to<P>::value, void*>::type = nullptr>
241  std::string id,
242  P &&origin,
243  uint64_t timestamp = -1)
244  : impl_(std::make_shared<ReferenceFrameVersion>(
245  id, std::forward<P>(origin), timestamp)) {}
246 
258  template<typename P,
259  typename std::enable_if<
260  supports_transform_to<P>::value, void*>::type = nullptr>
262  const ReferenceFrameType *type,
263  std::string id,
264  P &&origin,
265  uint64_t timestamp = -1)
266  : impl_(std::make_shared<ReferenceFrameVersion>(
267  type, id, std::forward<P>(origin), timestamp)) {}
268 
275  bool valid() const { return (bool)impl_; }
276 
284  const Pose &origin() const;
285 
292  ReferenceFrame pose(const Pose &new_origin) const;
293 
300  ReferenceFrame move(const Position &new_origin) const;
301 
308  ReferenceFrame orient(const Orientation &new_origin) const;
309 
317  ReferenceFrame pose(const Pose &new_origin, uint64_t timestamp) const;
318 
326  ReferenceFrame move(const Position &new_origin, uint64_t timestamp) const;
327 
335  ReferenceFrame orient(const Orientation &new_origin, uint64_t timestamp) const;
336 
341  ReferenceFrame origin_frame() const;
342 
350  bool operator==(const ReferenceFrame &other) const;
351 
359  bool operator!=(const ReferenceFrame &other) const;
360 
361  bool operator<(const ReferenceFrame &other) const
362  {
363  return impl_ < other.impl_;
364  }
365 
366  bool operator<=(const ReferenceFrame &other) const
367  {
368  return impl_ <= other.impl_;
369  }
370 
371  bool operator>(const ReferenceFrame &other) const
372  {
373  return impl_ > other.impl_;
374  }
375 
376  bool operator>=(const ReferenceFrame &other) const
377  {
378  return impl_ >= other.impl_;
379  }
380 
386  std::string name() const;
387 
392  const std::string &id() const;
393 
401  const ReferenceFrameType *type() const;
402 
408  uint64_t timestamp() const;
409 
415  ReferenceFrame timestamp(uint64_t) const;
416 
433  uint64_t expiry(uint64_t age = -1) const;
434 
436  uint64_t expiry() const;
437 
455  static uint64_t default_expiry(uint64_t age);
456 
458  static uint64_t default_expiry();
459 
462  static const std::string &default_prefix();
463 
470  bool interpolated() const;
471 
480  void save(madara::knowledge::KnowledgeBase &kb,
481  const FrameEvalSettings &settings = FrameEvalSettings::DEFAULT) const;
482 
492  void save(madara::knowledge::KnowledgeBase &kb,
493  uint64_t expiry,
494  const FrameEvalSettings &settings = FrameEvalSettings::DEFAULT) const;
495 
507  static ReferenceFrame load(
508  madara::knowledge::KnowledgeBase &kb,
509  const std::string &id,
510  uint64_t timestamp = -1,
512 
529  template<typename InputIterator>
530  static std::vector<ReferenceFrame> load_tree(
531  madara::knowledge::KnowledgeBase &kb,
532  InputIterator begin,
533  InputIterator end,
534  uint64_t timestamp = -1,
536 
553  template<typename Container>
554  static std::vector<ReferenceFrame> load_tree(
555  madara::knowledge::KnowledgeBase &kb,
556  const Container &ids,
557  uint64_t timestamp = -1,
559 
567  void save_as(
568  madara::knowledge::KnowledgeBase &kb,
569  const std::string &key,
570  const FrameEvalSettings &settings = FrameEvalSettings::DEFAULT) const;
571 
580  void save_as(madara::knowledge::KnowledgeBase &kb,
581  const std::string &key, uint64_t expiry,
582  const FrameEvalSettings &settings = FrameEvalSettings::DEFAULT) const;
583 
596  ReferenceFrame interpolate(const ReferenceFrame &other,
597  ReferenceFrame parent, uint64_t time) const;
598 
599  friend class ReferenceFrameVersion;
600 };
601 
612  int type_id;
613 
617  const char *name;
618 
619  void (*transform_linear_to_origin)(
620  const ReferenceFrameType *origin,
621  const ReferenceFrameType *self,
622  double ox, double oy, double oz,
623  double orx, double ory, double orz,
624  double &x, double &y, double &z,
625  bool fixed);
626 
627  void (*transform_linear_from_origin)(
628  const ReferenceFrameType *origin,
629  const ReferenceFrameType *self,
630  double ox, double oy, double oz,
631  double orx, double ory, double orz,
632  double &x, double &y, double &z,
633  bool fixed);
634 
635  void (*normalize_linear)(
636  const ReferenceFrameType *self,
637  double &x, double &y, double &z);
638 
639  double (*calc_distance)(
640  const ReferenceFrameType *self,
641  double x1, double y1, double z1,
642  double x2, double y2, double z2);
643 
645  const ReferenceFrameType *origin,
646  const ReferenceFrameType *self,
647  double orx, double ory, double orz,
648  double &rx, double &ry, double &rz);
649 
651  const ReferenceFrameType *origin,
652  const ReferenceFrameType *self,
653  double orx, double ory, double orz,
654  double &rx, double &ry, double &rz);
655 
656  void (*normalize_angular)(
657  const ReferenceFrameType *self,
658  double &rx, double &ry, double &rz);
659 
660  double (*calc_angle)(
661  const ReferenceFrameType *self,
662  double rx1, double ry1, double rz1,
663  double rx2, double ry2, double rz2);
664 
666  const ReferenceFrameType *origin,
667  const ReferenceFrameType *self,
668  double ox, double oy, double oz,
669  double orx, double ory, double orz,
670  double &x, double &y, double &z,
671  double &rx, double &ry, double &rz,
672  bool fixed);
673 
675  const ReferenceFrameType *origin,
676  const ReferenceFrameType *self,
677  double ox, double oy, double oz,
678  double orx, double ory, double orz,
679  double &x, double &y, double &z,
680  double &rx, double &ry, double &rz,
681  bool fixed);
682 
683  void (*normalize_pose)(
684  const ReferenceFrameType *self,
685  double &x, double &y, double &z,
686  double &rx, double &ry, double &rz);
687 };
688 
695 
696 } }
697 
698 #endif
void prefix(std::string prefix)
bool operator<(const ReferenceFrame &other) const
std::shared_ptr< ReferenceFrameVersion > impl_
static const FrameEvalSettings DEFAULT
bool operator<=(const ReferenceFrame &other) const
bool operator>=(const ReferenceFrame &other) const
Settings class for saving/loading reference frames.
STL namespace.
MADARA_MAKE_VAL_SUPPORT_TEST(nano_timestamp, x,(x.nanos(), x.nanos(0UL)))
Type trait to detect stamped types.
ReferenceFrame(P &&origin, uint64_t timestamp=-1)
Constructor from an origin, and optional timestamp.
ReferenceFrame(const ReferenceFrameType *type, P &&origin, uint64_t timestamp=-1)
Constructor from a type, an origin, and optional timestamp.
madara::knowledge::EvalSettings Base
int type_id
The type&#39;s ID.
FrameEvalSettings(const char *prefix, Base base=Base{true})
void transform_pose_from_origin(const ReferenceFrameType *origin, const ReferenceFrameType *self, double ox, double oy, double oz, double orx, double ory, double orz, double &x, double &y, double &z, double &rx, double &ry, double &rz, bool fixed)
Transform pose in-place from its origin frame Simply applies linear and angular transforms independan...
Contains all GAMS-related tools, classes and code.
gams::pose::Orientation Orientation
Represents a orientation or orientation within a reference frame.
Definition: Orientation.h:94
BaseAlgorithm Base
static const std::string default_prefix_
#define GAMS_EXPORT
Definition: GamsExport.h:20
GAMS_EXPORT const ReferenceFrame & default_frame(void)
Default frame.
bool operator>(const ReferenceFrame &other) const
FrameEvalSettings(std::nullptr_t, Base base=Base{true})
std::shared_ptr< std::string > prefix_
void transform_pose_to_origin(const ReferenceFrameType *origin, const ReferenceFrameType *self, double ox, double oy, double oz, double orx, double ory, double orz, double &x, double &y, double &z, double &rx, double &ry, double &rz, bool fixed)
Transform pose in-place into its origin frame from this frame.
ReferenceFrame(std::string id, P &&origin, uint64_t timestamp=-1)
Constructor from a id, an origin, and optional timestamp.
ReferenceFrame(const ReferenceFrameType *type, std::string id, P &&origin, uint64_t timestamp=-1)
Constructor from a type, id, an origin, and optional timestamp.
bool operator!=(const BasicVector< LDerived, Units > &lhs, const BasicVector< RDerived, Units > &rhs)
Definition: Coordinate.h:956
gams::pose::ReferenceFrame ReferenceFrame
Base class for Reference Frames.
gams::pose::Pose Pose
Represents a combination of Location and Orientation within a single reference frame.
Definition: Pose.h:79
void transform_angular_from_origin(const ReferenceFrameType *origin, const ReferenceFrameType *self, double orx, double ory, double orz, double &rx, double &ry, double &rz)
Transform AngularVector in-place from its origin frame.
Provides Reference Frame (i.e., coordinate systemm) transforms.
ReferenceFrame(std::shared_ptr< ReferenceFrameVersion > impl)
Construct from an existing ReferenceFrameVersion object.
double calc_angle(const ReferenceFrameType *self, double rx1, double ry1, double rz1, double rx2, double ry2, double rz2)
Calculates smallest angle between two AngularVectors.
bool valid() const
Test whether this frame is valid.
const std::string & prefix() const
const char * name
A human-readable name for reference frame types.
FrameEvalSettings(Base base=Base{true})
void transform_angular_to_origin(const ReferenceFrameType *origin, const ReferenceFrameType *self, double orx, double ory, double orz, double &rx, double &ry, double &rz)
Transform AngularVector in-place into its origin frame from this frame.
ReferenceFrame()
Default constructor.
bool operator==(const BasicVector< LDerived, Units > &lhs, const BasicVector< RDerived, Units > &rhs)
Definition: Coordinate.h:955
FrameEvalSettings(std::string prefix, Base base=Base{true})
static const std::string & default_prefix()