GAMS  1.4.0
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 ReferenceFrameArena;
66 class ReferenceFrameIdentity;
67 class ReferenceFrameVersion;
68 struct ReferenceFrameType;
69 class Pose;
70 class Position;
71 class Orientation;
72 class ReferenceFrame;
73 
75  (x.transform_to(std::declval<ReferenceFrame>())));
76 
85 class GAMS_EXPORT FrameEvalSettings : public madara::knowledge::EvalSettings
86 {
87 public:
88  using Base = madara::knowledge::EvalSettings;
89 
90  static const FrameEvalSettings DEFAULT;
91 
95  FrameEvalSettings(Base base = Base{true}) : Base(std::move(base)) {}
96 
100  FrameEvalSettings(std::string prefix, Base base = Base{true})
101  : Base(std::move(base)),
102  prefix_(std::make_shared<std::string>(std::move(prefix))) {}
103 
108  FrameEvalSettings(std::nullptr_t, Base base = Base{true})
109  : FrameEvalSettings(std::move(base)) {}
110 
114  FrameEvalSettings(const char *prefix, Base base = Base{true})
115  : FrameEvalSettings(std::string(prefix), std::move(base)) {}
116 
121  static const std::string &default_prefix() {
122  std::lock_guard<std::mutex> guard(defaults_lock_);
123  return default_prefix_;
124  }
125 
131  static void set_default_prefix(std::string new_prefix) {
132  std::lock_guard<std::mutex> guard(defaults_lock_);
133  default_prefix_ = new_prefix;
134  }
135 
139  const std::string &prefix() const {
140  if (prefix_) {
141  return *prefix_;
142  } else {
143  return default_prefix();
144  }
145  }
146 
150  void prefix(std::string prefix) {
151  prefix_ = std::make_shared<std::string>(std::move(prefix));
152  }
153 
154 private:
155  static std::mutex defaults_lock_;
156  static std::string default_prefix_;
157 
158  std::shared_ptr<std::string> prefix_;
159 };
160 
199 {
200 private:
201  std::shared_ptr<ReferenceFrameVersion> impl_;
202 
203 public:
204  static const uint64_t ETERNAL = 0UL - 1;
205  static const uint64_t TEMP = 0UL - 2;
206 
214  ReferenceFrame() : impl_() {}
215 
224  ReferenceFrame(std::shared_ptr<ReferenceFrameVersion> impl) :
225  impl_(std::move(impl)) {}
226 
236  template<typename P,
237  typename std::enable_if<
238  supports_transform_to<P>::value, void*>::type = nullptr>
239  explicit ReferenceFrame(
240  P &&origin,
241  uint64_t timestamp = ETERNAL)
242  : impl_(std::make_shared<ReferenceFrameVersion>(
243  std::forward<P>(origin), timestamp)) {}
244 
256  template<typename P,
257  typename std::enable_if<
258  supports_transform_to<P>::value, void*>::type = nullptr>
260  const ReferenceFrameType *type,
261  P &&origin,
262  uint64_t timestamp = ETERNAL)
263  : impl_(std::make_shared<ReferenceFrameVersion>(
264  type, std::forward<P>(origin), timestamp)) {}
265 
276  template<typename P,
277  typename std::enable_if<
278  supports_transform_to<P>::value, void*>::type = nullptr>
280  std::string id,
281  P &&origin,
282  uint64_t timestamp = ETERNAL)
283  : impl_(std::make_shared<ReferenceFrameVersion>(
284  id, std::forward<P>(origin), timestamp)) {}
285 
297  template<typename P,
298  typename std::enable_if<
299  supports_transform_to<P>::value, void*>::type = nullptr>
301  const ReferenceFrameType *type,
302  std::string id,
303  P &&origin,
304  uint64_t timestamp = ETERNAL)
305  : impl_(std::make_shared<ReferenceFrameVersion>(
306  type, id, std::forward<P>(origin), timestamp)) {}
307 
314  bool valid() const { return (bool)impl_; }
315 
323  const Pose &origin() const;
324 
331  ReferenceFrame pose(const Pose &new_origin) const;
332 
339  ReferenceFrame move(const Position &new_origin) const;
340 
347  ReferenceFrame orient(const Orientation &new_origin) const;
348 
356  ReferenceFrame pose(const Pose &new_origin, uint64_t timestamp) const;
357 
365  ReferenceFrame move(const Position &new_origin, uint64_t timestamp) const;
366 
374  ReferenceFrame orient(const Orientation &new_origin, uint64_t timestamp) const;
375 
381 
389  bool operator==(const ReferenceFrame &other) const;
390 
398  bool operator!=(const ReferenceFrame &other) const;
399 
400  bool operator<(const ReferenceFrame &other) const
401  {
402  return impl_ < other.impl_;
403  }
404 
405  bool operator<=(const ReferenceFrame &other) const
406  {
407  return impl_ <= other.impl_;
408  }
409 
410  bool operator>(const ReferenceFrame &other) const
411  {
412  return impl_ > other.impl_;
413  }
414 
415  bool operator>=(const ReferenceFrame &other) const
416  {
417  return impl_ >= other.impl_;
418  }
419 
425  std::string name() const;
426 
431  const std::string &id() const;
432 
440  const ReferenceFrameType *type() const;
441 
447  uint64_t timestamp() const;
448 
454  ReferenceFrame timestamp(uint64_t) const;
455 
472  uint64_t expiry(uint64_t age = ETERNAL) const;
473 
475  uint64_t expiry() const;
476 
494  static uint64_t default_expiry(uint64_t age);
495 
497  static uint64_t default_expiry();
498 
501  static const std::string &default_prefix();
502 
509  bool interpolated() const;
510 
515  bool temp() const;
516 
525  void save(madara::knowledge::KnowledgeBase &kb,
526  const FrameEvalSettings &settings = FrameEvalSettings::DEFAULT) const;
527 
537  void save(madara::knowledge::KnowledgeBase &kb,
538  uint64_t expiry,
539  const FrameEvalSettings &settings = FrameEvalSettings::DEFAULT) const;
540 
553  madara::knowledge::KnowledgeBase &kb,
554  const std::string &id,
555  uint64_t timestamp = ETERNAL,
557 
574  template<typename InputIterator>
575  static std::vector<ReferenceFrame> load_tree(
576  madara::knowledge::KnowledgeBase &kb,
577  InputIterator begin,
578  InputIterator end,
579  uint64_t timestamp = ETERNAL,
581  ReferenceFrameArena *arena = nullptr);
582 
599  template<typename Container>
600  static std::vector<ReferenceFrame> load_tree(
601  madara::knowledge::KnowledgeBase &kb,
602  const Container &ids,
603  uint64_t timestamp = ETERNAL,
605  ReferenceFrameArena *arena = nullptr);
606 
620  static std::vector<ReferenceFrame> load_tree(
621  madara::knowledge::KnowledgeBase &kb,
622  const std::initializer_list<const char *> &ids,
623  uint64_t timestamp = ETERNAL,
625  ReferenceFrameArena *arena = nullptr);
626 
634  void save_as(
635  madara::knowledge::KnowledgeBase &kb,
636  const std::string &key,
637  const FrameEvalSettings &settings = FrameEvalSettings::DEFAULT) const;
638 
647  void save_as(madara::knowledge::KnowledgeBase &kb,
648  const std::string &key, uint64_t expiry,
649  const FrameEvalSettings &settings = FrameEvalSettings::DEFAULT) const;
650 
664  ReferenceFrame parent, uint64_t time) const;
665 
666  friend class ReferenceFrameVersion;
668  const ReferenceFrame *from, const ReferenceFrame *to,
669  std::vector<const ReferenceFrame *> *to_stack);
670 };
671 
682  int type_id;
683 
687  const char *name;
688 
689  void (*transform_linear_to_origin)(
690  const ReferenceFrameType *origin,
691  const ReferenceFrameType *self,
692  double ox, double oy, double oz,
693  double orx, double ory, double orz,
694  double &x, double &y, double &z,
695  bool fixed);
696 
697  void (*transform_linear_from_origin)(
698  const ReferenceFrameType *origin,
699  const ReferenceFrameType *self,
700  double ox, double oy, double oz,
701  double orx, double ory, double orz,
702  double &x, double &y, double &z,
703  bool fixed);
704 
705  void (*normalize_linear)(
706  const ReferenceFrameType *self,
707  double &x, double &y, double &z);
708 
709  double (*calc_distance)(
710  const ReferenceFrameType *self,
711  double x1, double y1, double z1,
712  double x2, double y2, double z2);
713 
715  const ReferenceFrameType *origin,
716  const ReferenceFrameType *self,
717  double orx, double ory, double orz,
718  double &rx, double &ry, double &rz);
719 
721  const ReferenceFrameType *origin,
722  const ReferenceFrameType *self,
723  double orx, double ory, double orz,
724  double &rx, double &ry, double &rz);
725 
726  void (*normalize_angular)(
727  const ReferenceFrameType *self,
728  double &rx, double &ry, double &rz);
729 
730  double (*calc_angle)(
731  const ReferenceFrameType *self,
732  double rx1, double ry1, double rz1,
733  double rx2, double ry2, double rz2);
734 
736  const ReferenceFrameType *origin,
737  const ReferenceFrameType *self,
738  double ox, double oy, double oz,
739  double orx, double ory, double orz,
740  double &x, double &y, double &z,
741  double &rx, double &ry, double &rz,
742  bool fixed);
743 
745  const ReferenceFrameType *origin,
746  const ReferenceFrameType *self,
747  double ox, double oy, double oz,
748  double orx, double ory, double orz,
749  double &x, double &y, double &z,
750  double &rx, double &ry, double &rz,
751  bool fixed);
752 
753  void (*normalize_pose)(
754  const ReferenceFrameType *self,
755  double &x, double &y, double &z,
756  double &rx, double &ry, double &rz);
757 };
758 
765 
766 } }
767 
768 #endif
#define GAMS_EXPORT
Definition: GamsExport.h:20
Settings class for saving/loading reference frames.
const std::string & prefix() const
Get prefix set for this settings object.
FrameEvalSettings(std::string prefix, Base base=Base{true})
Custom prefix constructor.
static std::string default_prefix_
static const FrameEvalSettings DEFAULT
void prefix(std::string prefix)
Set prefix set for this settings object.
std::shared_ptr< std::string > prefix_
FrameEvalSettings(Base base=Base{true})
Default constructor.
FrameEvalSettings(const char *prefix, Base base=Base{true})
Custom prefix constructor.
static void set_default_prefix(std::string new_prefix)
Set default prefix for all FrameEvalSettings that don't have another prefix set.
FrameEvalSettings(std::nullptr_t, Base base=Base{true})
Explicit default prefix constructor.
madara::knowledge::EvalSettings Base
static const std::string & default_prefix()
Get default prefix for all FrameEvalSettings that don't have another prefix set.
Provides Reference Frame (i.e., coordinate systemm) transforms.
ReferenceFrame orient(const Orientation &new_origin, uint64_t timestamp) const
Creates a new ReferenceFrame with modified origin and timestamp.
uint64_t timestamp() const
Get the timestamp assigned to this frame.
bool operator>(const ReferenceFrame &other) const
bool operator==(const ReferenceFrame &other) const
Equality operator.
ReferenceFrame(std::string id, P &&origin, uint64_t timestamp=ETERNAL)
Constructor from a id, an origin, and optional timestamp.
ReferenceFrame timestamp(uint64_t) const
Clone the this frame, but with new timestamp.
bool operator<(const ReferenceFrame &other) const
static ReferenceFrame load(madara::knowledge::KnowledgeBase &kb, const std::string &id, uint64_t timestamp=ETERNAL, const FrameEvalSettings &settings=FrameEvalSettings::DEFAULT)
Load a single ReferenceFrame, by ID.
void save(madara::knowledge::KnowledgeBase &kb, uint64_t expiry, const FrameEvalSettings &settings=FrameEvalSettings::DEFAULT) const
Save this ReferenceFrame to the knowledge base, The saved frames will be marked with their timestamp ...
bool operator>=(const ReferenceFrame &other) const
bool interpolated() const
Test if frame is interpolated.
uint64_t expiry() const
Return the current expiry for frames of this ID.
bool operator!=(const ReferenceFrame &other) const
Inequality operator.
ReferenceFrame(P &&origin, uint64_t timestamp=ETERNAL)
Constructor from an origin, and optional timestamp.
void save_as(madara::knowledge::KnowledgeBase &kb, const std::string &key, const FrameEvalSettings &settings=FrameEvalSettings::DEFAULT) const
Save this ReferenceFrame to the knowledge base, with a specific key value.
ReferenceFrame move(const Position &new_origin, uint64_t timestamp) const
Creates a new ReferenceFrame with modified origin and timestamp.
std::shared_ptr< ReferenceFrameVersion > impl_
ReferenceFrame move(const Position &new_origin) const
Creates a new ReferenceFrame with modified origin.
ReferenceFrame interpolate(const ReferenceFrame &other, ReferenceFrame parent, uint64_t time) const
Interpolate a frame between the given frame; use the given parent.
static std::vector< ReferenceFrame > load_tree(madara::knowledge::KnowledgeBase &kb, const std::initializer_list< const char * > &ids, uint64_t timestamp=ETERNAL, const FrameEvalSettings &settings=FrameEvalSettings::DEFAULT, ReferenceFrameArena *arena=nullptr)
Load ReferenceFrames, by ID, and their common ancestors.
bool valid() const
Test whether this frame is valid.
ReferenceFrame origin_frame() const
Gets the parent frame (the one the origin is within).
uint64_t expiry(uint64_t age=ETERNAL) const
Sets configuration for all frames of this frames ID.
ReferenceFrame pose(const Pose &new_origin, uint64_t timestamp) const
Creates a new ReferenceFrame with modified origin and timestamp.
ReferenceFrame orient(const Orientation &new_origin) const
Creates a new ReferenceFrame with modified origin.
void save(madara::knowledge::KnowledgeBase &kb, const FrameEvalSettings &settings=FrameEvalSettings::DEFAULT) const
Save this ReferenceFrame to the knowledge base, The saved frames will be marked with their timestamp ...
ReferenceFrame(const ReferenceFrameType *type, std::string id, P &&origin, uint64_t timestamp=ETERNAL)
Constructor from a type, id, an origin, and optional timestamp.
void save_as(madara::knowledge::KnowledgeBase &kb, const std::string &key, uint64_t expiry, const FrameEvalSettings &settings=FrameEvalSettings::DEFAULT) const
Save this ReferenceFrame to the knowledge base, with a specific key value.
static std::vector< ReferenceFrame > load_tree(madara::knowledge::KnowledgeBase &kb, InputIterator begin, InputIterator end, uint64_t timestamp=ETERNAL, const FrameEvalSettings &settings=FrameEvalSettings::DEFAULT, ReferenceFrameArena *arena=nullptr)
Load ReferenceFrames, by ID, and their common ancestors.
const std::string & id() const
Get the ID string of this frame.
bool operator<=(const ReferenceFrame &other) const
friend GAMS_EXPORT const ReferenceFrame * find_common_frame(const ReferenceFrame *from, const ReferenceFrame *to, std::vector< const ReferenceFrame * > *to_stack)
Helper function to find the common frame between two frames.
static const std::string & default_prefix()
Return the default prefix for load/save operations.
ReferenceFrame(std::shared_ptr< ReferenceFrameVersion > impl)
Construct from an existing ReferenceFrameVersion object.
ReferenceFrame()
Default constructor.
static uint64_t default_expiry(uint64_t age)
Set the default expiry value for new frames IDs.
const ReferenceFrameType * type() const
Retrieve the frame type object for this frame.
const Pose & origin() const
Gets the origin of this Frame.
static uint64_t default_expiry()
Return the default expiry for new frame IDs.
ReferenceFrame pose(const Pose &new_origin) const
Creates a new ReferenceFrame with modified origin.
bool temp() const
Returns true if this frame is a temporary; one invented to serve as root of a frame tree.
static std::vector< ReferenceFrame > load_tree(madara::knowledge::KnowledgeBase &kb, const Container &ids, uint64_t timestamp=ETERNAL, const FrameEvalSettings &settings=FrameEvalSettings::DEFAULT, ReferenceFrameArena *arena=nullptr)
Load ReferenceFrames, by ID, and their common ancestors.
ReferenceFrame(const ReferenceFrameType *type, P &&origin, uint64_t timestamp=ETERNAL)
Constructor from a type, an origin, and optional timestamp.
std::string name() const
Returns a human-readable name for the reference frame type.
BaseAlgorithm Base
double calc_angle(const ReferenceFrameType *self, double rx1, double ry1, double rz1, double rx2, double ry2, double rz2)
Calculates smallest angle between two AngularVectors.
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.
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.
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.
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...
GAMS_EXPORT const ReferenceFrame & default_frame(void)
Default frame.
MADARA_MAKE_VAL_SUPPORT_TEST(nano_timestamp, x,(x.nanos(), x.nanos(0UL)))
Type trait to detect stamped types.
gams::pose::Orientation Orientation
Represents a orientation or orientation within a reference frame.
Definition: Orientation.h:94
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
Contains all GAMS-related tools, classes and code.
const char * name
A human-readable name for reference frame types.