GAMS  1.2.2
ReferenceFrame.h
Go to the documentation of this file.
1 
54 #ifndef _GAMS_POSE_REFERENCE_FRAME_H_
55 #define _GAMS_POSE_REFERENCE_FRAME_H_
56 
57 #include "gams/GamsExport.h"
58 #include "gams/CPP11_compat.h"
59 #include <vector>
60 #include <string>
61 #include <cstring>
62 #include <sstream>
63 #include <utility>
64 #include <memory>
65 #include <stdexcept>
66 #include <mutex>
67 #include "ReferenceFrameFwd.h"
68 #include "CartesianFrame.h"
69 #include "Pose.h"
70 #include "Quaternion.h"
71 #include "madara/knowledge/EvalSettings.h"
72 
73 namespace gams { namespace pose {
74 
75 class ReferenceFrameVersion;
76 
84 {
85 private:
86  std::string id_;
87 
88  static std::map<std::string,
89  std::weak_ptr<ReferenceFrameIdentity>> idents_;
90 
91  static uint64_t default_expiry_;
92 
93  static std::mutex idents_lock_;
94 
95  mutable std::map<uint64_t, std::weak_ptr<ReferenceFrameVersion>>
97 
98  mutable uint64_t expiry_ = -1;
99 
100  mutable std::mutex versions_lock_;
101 
102 public:
104  ReferenceFrameIdentity(std::string id, uint64_t expiry)
105  : id_(std::move(id)), expiry_(expiry) {}
106 
107  static std::shared_ptr<ReferenceFrameIdentity> lookup(std::string id);
108 
109  static std::shared_ptr<ReferenceFrameIdentity> find(std::string id);
110 
111  static std::shared_ptr<ReferenceFrameIdentity> make_guid();
112 
113  void register_version(uint64_t timestamp,
114  std::shared_ptr<ReferenceFrameVersion> ver) const
115  {
116  std::lock_guard<std::mutex> guard(versions_lock_);
117 
118  std::weak_ptr<ReferenceFrameVersion> weak(std::move(ver));
119  versions_[timestamp] = ver;
120  }
121 
122  std::shared_ptr<ReferenceFrameVersion> get_version(uint64_t timestamp) const
123  {
124  std::lock_guard<std::mutex> guard(versions_lock_);
125 
126  auto find = versions_.find(timestamp);
127 
128  if (find == versions_.end()) {
129  return nullptr;
130  }
131 
132  return find->second.lock();
133  }
134 
135  const std::string &id() const { return id_; }
136 
154  static uint64_t default_expiry(uint64_t age) {
155  std::lock_guard<std::mutex> guard(idents_lock_);
156 
157  uint64_t ret = default_expiry_;
158  default_expiry_ = age;
159  return ret;
160  }
161 
163  static uint64_t default_expiry() {
164  std::lock_guard<std::mutex> guard(idents_lock_);
165  return default_expiry_;
166  }
167 
182  uint64_t expiry(uint64_t age) const {
183  std::lock_guard<std::mutex> guard(versions_lock_);
184 
185  uint64_t ret = expiry_;
186  expiry_ = age;
187  return ret;
188  }
189 
191  uint64_t expiry() const {
192  std::lock_guard<std::mutex> guard(versions_lock_);
193  return expiry_;
194  }
195 
196  void expire_older_than(madara::knowledge::KnowledgeBase &kb,
197  uint64_t time, const FrameEvalSettings &settings = FrameEvalSettings::DEFAULT) const;
198 
199  static const std::string &default_prefix() {
201  }
202 
207  static void gc();
208 };
209 
211 namespace impl {
212  inline static std::string &make_kb_key(
213  std::string &prefix,
214  const std::string &id)
215  {
216  prefix.reserve(prefix.capacity() + 1 + id.size());
217 
218  prefix += ".";
219  prefix += id;
220 
221  return prefix;
222  }
223 
224  inline static std::string &make_kb_key(
225  std::string &prefix, uint64_t timestamp)
226  {
227  if (timestamp == (uint64_t)-1) {
228  prefix += ".inf";
229  } else {
230  prefix += ".";
231 
232  std::ostringstream oss;
233  oss.fill('0');
234  oss.width(16);
235  oss << std::hex << timestamp;
236 
237  prefix += oss.str();
238  }
239 
240  return prefix;
241  }
242 
243  inline static std::string &make_kb_key(
244  std::string &prefix,
245  const std::string &id, uint64_t timestamp)
246  {
247  make_kb_key(prefix, id);
248  make_kb_key(prefix, timestamp);
249  return prefix;
250  }
251 }
252 
254 MADARA_MAKE_VAL_SUPPORT_TEST(nano_timestamp, x,
255  (x.nanos(), x.nanos(0UL)));
256 
258 inline uint64_t try_get_nano_time(uint64_t def)
259 {
260  return def;
261 }
262 
264 template<typename T, typename... Args>
265 inline auto try_get_nano_time(uint64_t, const T& v, Args&&...) ->
266  typename std::enable_if<supports_nano_timestamp<T>::value, uint64_t>::type
267 {
268  return v.nanos();
269 }
270 
272 template<typename T, typename... Args>
273 inline auto try_get_nano_time(uint64_t def, const T&, Args&&... args) ->
274  typename std::enable_if<!supports_nano_timestamp<T>::value, uint64_t>::type
275 {
276  return try_get_nano_time(def, std::forward<Args>(args)...);
277 }
278 
286  public std::enable_shared_from_this<ReferenceFrameVersion>
287 {
288 private:
289  mutable std::shared_ptr<ReferenceFrameIdentity> ident_;
291  uint64_t timestamp_ = -1;
293  mutable bool interpolated_ = false;
294 
295 private:
296  template<typename T>
297  static uint64_t init_timestamp(uint64_t given, const T &p)
298  {
299  if (given == (uint64_t)-1) {
300  return try_get_nano_time(-1, p);
301  } else {
302  return given;
303  }
304  }
305 
306 public:
316  template<typename P,
317  typename std::enable_if<
318  supports_transform_to<P>::value, void*>::type = nullptr>
320  P &&origin,
321  uint64_t timestamp = -1)
323  std::forward<P>(origin),
324  timestamp) {}
325 
337  template<typename P,
338  typename std::enable_if<
339  supports_transform_to<P>::value, void*>::type = nullptr>
341  const ReferenceFrameType *type,
342  P &&origin,
343  uint64_t timestamp = -1)
344  : ReferenceFrameVersion({}, type,
345  std::forward<P>(origin), timestamp) {}
346 
357  template<typename P,
358  typename std::enable_if<
359  supports_transform_to<P>::value, void*>::type = nullptr>
361  std::string name,
362  P &&origin,
363  uint64_t timestamp = -1)
365  ReferenceFrameIdentity::lookup(std::move(name)), Cartesian,
366  std::forward<P>(origin), timestamp) {}
367 
379  template<typename P,
380  typename std::enable_if<
381  supports_transform_to<P>::value, void*>::type = nullptr>
383  const ReferenceFrameType *type,
384  std::string name,
385  P &&origin,
386  uint64_t timestamp = -1)
388  ReferenceFrameIdentity::lookup(std::move(name)), type,
389  std::forward<P>(origin), timestamp) {}
390 
403  template<typename P,
404  typename std::enable_if<
405  supports_transform_to<P>::value, void*>::type = nullptr>
407  std::shared_ptr<ReferenceFrameIdentity> ident,
408  const ReferenceFrameType *type,
409  P &&origin,
410  uint64_t timestamp = -1)
411  : ident_(std::move(ident)),
412  type_(type),
413  timestamp_(init_timestamp(timestamp, origin)),
414  origin_(std::forward<P>(origin)) {}
415 
420  const ReferenceFrameIdentity &ident() const {
421  if (!ident_) {
423  }
424  return *ident_;
425  }
426 
434  const ReferenceFrameType *type() const { return type_; }
435 
443  const Pose &origin() const {
444  return origin_;
445  }
446 
455  return origin_;
456  }
457 
464  ReferenceFrame pose(Pose new_origin) const {
465  return pose(new_origin, timestamp_);
466  }
467 
474  ReferenceFrame move(Position new_origin) const {
475  return move(new_origin, timestamp_);
476  }
477 
484  ReferenceFrame orient(Orientation new_origin) const {
485  return orient(new_origin, timestamp_);
486  }
487 
495  ReferenceFrame pose(const Pose &new_origin, uint64_t timestamp) const {
496  return ReferenceFrame(std::make_shared<ReferenceFrameVersion>(
497  ident_, type(), new_origin, timestamp));
498  }
499 
507  ReferenceFrame move(const Position &new_origin,
508  uint64_t timestamp) const {
509  return pose(Pose(new_origin, Orientation(origin_)), timestamp);
510  }
511 
519  ReferenceFrame orient(const Orientation &new_origin,
520  uint64_t timestamp) const {
521  return pose(Pose(Position(origin_), new_origin), timestamp);
522  }
523 
529  return origin_.frame();
530  }
531 
539  bool operator==(const ReferenceFrame &other) const;
540 
548  bool operator!=(const ReferenceFrame &other) const;
549 
557  bool operator==(const ReferenceFrameVersion &other) const;
558 
566  bool operator!=(const ReferenceFrameVersion &other) const;
567 
573  const char *name() const {
574  return type()->name;
575  }
576 
582  const std::string &id() const {
583  return ident().id();
584  }
585 
594  bool has_id() const {
595  return (bool)ident_;
596  }
597 
605  const std::string *id_ptr() const {
606  return has_id() ? nullptr : &id();
607  }
608 
612  uint64_t timestamp() const {
613  return timestamp_;
614  }
615 
621  ReferenceFrame timestamp(uint64_t timestamp) const {
622  return ReferenceFrame(std::make_shared<ReferenceFrameVersion>(
623  ident_, type(), origin(), timestamp));
624  }
625 
631  bool interpolated() const {
632  return interpolated_;
633  }
634 
635  static const std::string &default_prefix() {
637  }
638 
642  std::string key(const FrameEvalSettings &settings = FrameEvalSettings::DEFAULT) const {
643  std::string prefix = settings.prefix();
644  impl::make_kb_key(prefix, id(), timestamp());
645  return prefix;
646  }
647 
657  void save(madara::knowledge::KnowledgeBase &kb,
658  uint64_t expiry,
659  const FrameEvalSettings &settings = FrameEvalSettings::DEFAULT) const {
660  std::string key = this->key(settings);
661  save_as(kb, std::move(key), expiry, settings);
662  }
663 
672  void save(madara::knowledge::KnowledgeBase &kb,
673  const FrameEvalSettings &settings = FrameEvalSettings::DEFAULT) const {
674  std::string key = this->key(settings);
675  save_as(kb, std::move(key), settings);
676  }
677 
692  static ReferenceFrame load_exact(
693  madara::knowledge::KnowledgeBase &kb,
694  const std::string &id,
695  uint64_t timestamp = -1,
696  uint64_t parent_timestamp = -1,
698 
711  static ReferenceFrame load(
712  madara::knowledge::KnowledgeBase &kb,
713  const std::string &id,
714  uint64_t timestamp = -1,
716 
727  static uint64_t latest_timestamp(
728  madara::knowledge::KnowledgeBase &kb,
729  const std::string &id,
731 
746  template<typename ForwardIterator>
747  static uint64_t latest_common_timestamp(
748  madara::knowledge::KnowledgeBase &kb,
749  ForwardIterator begin,
750  ForwardIterator end,
752  {
753  madara::knowledge::ContextGuard guard(kb);
754 
755  uint64_t timestamp = -1;
756  ForwardIterator cur = begin;
757  while (cur != end) {
758  uint64_t time = latest_timestamp(kb, *cur, settings);
759  if (time < timestamp) {
760  timestamp = time;
761  }
762  ++cur;
763  }
764  return timestamp;
765  }
766 
779  template<typename Container>
780  static uint64_t latest_common_timestamp(
781  madara::knowledge::KnowledgeBase &kb,
782  const Container &ids,
784  {
785  madara::knowledge::ContextGuard guard(kb);
786 
787  return latest_common_timestamp(kb, ids.cbegin(), ids.cend(), settings);
788  }
789 
806  template<typename ForwardIterator>
807  static std::vector<ReferenceFrame> load_tree(
808  madara::knowledge::KnowledgeBase &kb,
809  ForwardIterator begin,
810  ForwardIterator end,
811  uint64_t timestamp = -1,
813  {
814  std::vector<ReferenceFrame> ret;
815  if (std::is_same<typename ForwardIterator::iterator_category,
816  std::random_access_iterator_tag>::value) {
817  size_t count = std::distance(begin, end);
818  ret.reserve(count);
819  }
820 
821  madara::knowledge::ContextGuard guard(kb);
822 
823  if (timestamp == (uint64_t)-1) {
824  timestamp = latest_common_timestamp(kb, begin, end, settings);
825  }
826  while (begin != end) {
827  ReferenceFrame frame = load(kb, *begin, timestamp, settings);
828  if (!frame.valid()) {
829  return {};
830  }
831  ret.push_back(frame);
832  ++begin;
833  }
834  return ret;
835  }
836 
853  template<typename Container>
854  static std::vector<ReferenceFrame> load_tree(
855  madara::knowledge::KnowledgeBase &kb,
856  const Container &ids,
857  uint64_t timestamp = -1,
859  {
860  return load_tree(kb, ids.cbegin(), ids.cend(),
861  timestamp, std::move(settings));
862  }
863 
872  void save_as(madara::knowledge::KnowledgeBase &kb,
873  std::string key, uint64_t expiry,
874  const FrameEvalSettings &settings = FrameEvalSettings::DEFAULT) const;
882  void save_as(madara::knowledge::KnowledgeBase &kb,
883  std::string key,
884  const FrameEvalSettings &settings = FrameEvalSettings::DEFAULT) const
885  {
886  save_as(kb, key, ident().expiry(), settings);
887  }
888 
900  ReferenceFrame interpolate(const ReferenceFrame &other, ReferenceFrame parent, uint64_t time) const
901  {
902  //std::cerr << "Interpolate has_id: " << has_id() << std::endl;
903  if (has_id()) {
904  auto ret = ident().get_version(time);
905  if (ret) {
906  return ret;
907  }
908  }
909  double fraction = (time - timestamp()) / (double)(other.timestamp() - timestamp());
910 
911  Pose interp = origin();
912  const Pose &opose = other.origin();
913 
914  interp.frame(std::move(parent));
915 
916  interp.x((fraction * (opose.x() - interp.x())) + interp.x());
917  interp.y((fraction * (opose.y() - interp.y())) + interp.y());
918  interp.z((fraction * (opose.z() - interp.z())) + interp.z());
919 
920  Quaternion iq(origin().as_orientation_vec());
921  Quaternion oq(opose.as_orientation_vec());
922 
923  iq.slerp_this(oq, fraction);
925 
926  //std::cerr << "Interp " << fraction << " " << origin() << " " << interp << " " << opose << std::endl;
927 
928  auto ret = std::make_shared<ReferenceFrameVersion>(
929  ident_, type(), std::move(interp), time);
930 
931  if (has_id()) {
932  ident().register_version(time, ret);
933  }
934 
935  ret->interpolated_ = true;
936  return ret;
937  }
938 
939  template<typename CoordType>
940  friend class Coordinate;
941 
942 private:
943  bool check_consistent() const;
944 };
945 
953 private:
954  /*
955  * KnowledgeBase uses const to indicate not changing the underlying
956  * KnowledgeBaseImpl, as well as itself. We won't be changing the
957  * KnowledgeBase object itself, and will only call thread-safe methods.
958  */
959  mutable madara::knowledge::KnowledgeBase kb_;
960 
962  uint64_t expiry_;
963 
964 public:
972  FrameStore(madara::knowledge::KnowledgeBase kb,
973  FrameEvalSettings settings, uint64_t expiry)
974  : kb_(std::move(kb)), settings_(std::move(settings)), expiry_(expiry) {}
975 
983  FrameStore(madara::knowledge::KnowledgeBase kb, FrameEvalSettings settings)
984  : FrameStore(std::move(kb), std::move(settings),
985  ReferenceFrame::default_expiry()) {}
986 
994  FrameStore(madara::knowledge::KnowledgeBase kb, uint64_t expiry)
995  : FrameStore(std::move(kb), FrameEvalSettings::DEFAULT, expiry) {}
996 
997 
1005  FrameStore(madara::knowledge::KnowledgeBase kb)
1006  : FrameStore(std::move(kb), FrameEvalSettings::DEFAULT,
1007  ReferenceFrame::default_expiry()) {}
1008 
1011  uint64_t expiry() const { return expiry_; }
1012 
1014  const FrameEvalSettings &settings() const { return settings_; }
1015 
1017  const madara::knowledge::KnowledgeBase &kb() const { return kb_; }
1018 
1027  void save(const ReferenceFrame &frame) const {
1028  return frame.save(kb_, expiry_, settings_);
1029  }
1030 
1042  ReferenceFrame load(const std::string &id, uint64_t timestamp = -1) {
1043  return ReferenceFrame::load(kb_, id, timestamp, settings_);
1044  }
1045 
1062  template<typename InputIterator>
1063  std::vector<ReferenceFrame> load_tree(
1064  InputIterator begin,
1065  InputIterator end,
1066  uint64_t timestamp = -1) const {
1067  return ReferenceFrame::load_tree(kb_, begin, end, timestamp, settings_);
1068  }
1069 
1086  template<typename Container>
1087  std::vector<ReferenceFrame> load_tree(
1088  const Container &ids,
1089  uint64_t timestamp = -1) const {
1090  return ReferenceFrame::load_tree(kb_, ids, timestamp, settings_);
1091  }
1092 };
1093 
1103  const ReferenceFrame *from,
1104  const ReferenceFrame *to,
1105  std::vector<const ReferenceFrame *> *to_stack = nullptr);
1106 
1111 class unrelated_frames : public std::runtime_error
1112 {
1113 public:
1120  unrelated_frames(ReferenceFrame from_frame, ReferenceFrame to_frame);
1121  ~unrelated_frames() throw();
1122 
1125 };
1126 
1138 class undefined_transform : public std::runtime_error
1139 {
1140 public:
1152  const ReferenceFrameType *parent_frame,
1153  const ReferenceFrameType *child_frame,
1154  bool is_child_to_parent,
1155  bool unsupported_angular = false);
1156  ~undefined_transform() throw();
1157 
1162 };
1163 
1172 namespace simple_rotate {
1182  void orient_linear_vec(
1183  double &x, double &y, double &z,
1184  double rx, double ry, double rz,
1185  bool reverse = false);
1186 
1195  const ReferenceFrameType *origin,
1196  const ReferenceFrameType *self,
1197  double orx, double ory, double orz,
1198  double &rx, double &ry, double &rz);
1199 
1208  const ReferenceFrameType *origin,
1209  const ReferenceFrameType *self,
1210  double orx, double ory, double orz,
1211  double &rx, double &ry, double &rz);
1212 
1225  const ReferenceFrameType *origin,
1226  const ReferenceFrameType *self,
1227  double ox, double oy, double oz,
1228  double orx, double ory, double orz,
1229  double &x, double &y, double &z,
1230  double &rx, double &ry, double &rz,
1231  bool fixed);
1232 
1245  const ReferenceFrameType *origin,
1246  const ReferenceFrameType *self,
1247  double ox, double oy, double oz,
1248  double orx, double ory, double orz,
1249  double &x, double &y, double &z,
1250  double &rx, double &ry, double &rz,
1251  bool fixed);
1252 
1264  double calc_angle(
1265  const ReferenceFrameType *self,
1266  double rx1, double ry1, double rz1,
1267  double rx2, double ry2, double rz2);
1268 }
1269 
1271  const ReferenceFrameType *,
1272  double &, double &, double &) {}
1273 
1275  const ReferenceFrameType *,
1276  double &, double &, double &) {}
1277 
1279  const ReferenceFrameType *self,
1280  double &x, double &y, double &z,
1281  double &rx, double &ry, double &rz)
1282 {
1283  self->normalize_linear(self, x, y, z);
1284  self->normalize_angular(self, rx, ry, rz);
1285 }
1286 
1287 } }
1288 
1289 #include "ReferenceFrame.inl"
1290 
1291 #endif
ReferenceFrameIdentity(std::string id, uint64_t expiry)
Public by necessity. Use lookup instead.
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 ...
GAMS_EXPORT const ReferenceFrame * find_common_frame(const ReferenceFrame *from, const ReferenceFrame *to, std::vector< const ReferenceFrame * > *to_stack=nullptr)
Helper function to find the common frame between two frames.
uint64_t expiry() const
Return the current expiry.
static const FrameEvalSettings DEFAULT
static const std::string & default_prefix()
static std::vector< ReferenceFrame > load_tree(madara::knowledge::KnowledgeBase &kb, const Container &ids, uint64_t timestamp=-1, const FrameEvalSettings &settings=FrameEvalSettings::DEFAULT)
Load ReferenceFrames, by ID, and their common ancestors.
ReferenceFrameVersion(const ReferenceFrameType *type, std::string name, P &&origin, uint64_t timestamp=-1)
Constructor from a type, id, an origin, and optional timestamp.
void save(const ReferenceFrame &frame) const
Save a ReferenceFrame to the knowledge base, The saved frames will be marked with their timestamp for...
Pose & mut_origin()
Gets the origin of this Frame.
static std::string & make_kb_key(std::string &prefix, const std::string &id)
FrameStore(madara::knowledge::KnowledgeBase kb, uint64_t expiry)
Constructor for FrameStore Uses default FrameEvalSettings.
static std::string & make_kb_key(std::string &prefix, const std::string &id, uint64_t timestamp)
ReferenceFrame move(const Position &new_origin, uint64_t timestamp) const
Creates a new ReferenceFrame with modified origin and timestamp.
gams::pose::undefined_transform undefined_transform
Thrown when an attempt is made to transform between two frame types, and there&#39;s not transform define...
ReferenceFrame move(Position new_origin) const
Creates a new ReferenceFrame with modified origin.
void to_angular_vector(double &rx, double &ry, double &rz) const
Settings class for saving/loading reference frames.
std::vector< ReferenceFrame > load_tree(const Container &ids, uint64_t timestamp=-1) const
Load ReferenceFrames, by ID, and their common ancestors.
const ReferenceFrameType * child_frame
std::vector< ReferenceFrame > load_tree(InputIterator begin, InputIterator end, uint64_t timestamp=-1) const
Load ReferenceFrames, by ID, and their common ancestors.
STL namespace.
const FrameEvalSettings & settings() const
Return the current settings for frames saved/loaded with this FrameStore.
ReferenceFrame timestamp(uint64_t timestamp) const
Clone the this frame, but with new timestamp.
void save_as(madara::knowledge::KnowledgeBase &kb, std::string key, const FrameEvalSettings &settings=FrameEvalSettings::DEFAULT) const
Save this ReferenceFrame to the knowledge base, with a specific key value.
const ReferenceFrameIdentity & ident() const
Get the ReferenceFrameIdentity object associated with this frame, creating one with random ID if none...
const Pose & origin() const
Gets the origin of this Frame.
MADARA_MAKE_VAL_SUPPORT_TEST(nano_timestamp, x,(x.nanos(), x.nanos(0UL)))
Type trait to detect stamped types.
ReferenceFrameVersion(std::shared_ptr< ReferenceFrameIdentity > ident, const ReferenceFrameType *type, P &&origin, uint64_t timestamp=-1)
Constructor from an existing ReferenceFrameIdentity, an origin, and optional timestamp.
const madara::knowledge::KnowledgeBase & kb() const
Return the KnowledgeBase to load/save with this FrameStore.
ReferenceFrame load(const std::string &id, uint64_t timestamp=-1)
Load a single ReferenceFrame, by ID.
uint64_t expiry(uint64_t age) const
If a frame newer than this time is saved, expire saved frames of the same ID older than this duration...
Class for storing and loading frames in a given KnowledgeBase, using given settings, with a set expiry.
static ReferenceFrame load(madara::knowledge::KnowledgeBase &kb, const std::string &id, uint64_t timestamp=-1, const FrameEvalSettings &settings=FrameEvalSettings::DEFAULT)
Load a single ReferenceFrame, by ID.
void default_normalize_pose(const ReferenceFrameType *self, double &x, double &y, double &z, double &rx, double &ry, double &rz)
gams::pose::unrelated_frames unrelated_frames
Thrown when an an attempt is made to transform between frames that do not belong to the same frame tr...
Thrown when an attempt is made to transform between two frame types, and there&#39;s not transform define...
ReferenceFrameVersion(P &&origin, uint64_t timestamp=-1)
Constructor from an origin, and optional timestamp.
const ReferenceFrameType * type_
static uint64_t latest_common_timestamp(madara::knowledge::KnowledgeBase &kb, const Container &ids, const FrameEvalSettings &settings=FrameEvalSettings::DEFAULT)
Get the latest available timestamp in the knowledge base common to all the given ids.
const char * name() const
Returns a human-readable name for the reference frame type.
static std::vector< ReferenceFrame > load_tree(madara::knowledge::KnowledgeBase &kb, ForwardIterator begin, ForwardIterator end, uint64_t timestamp=-1, const FrameEvalSettings &settings=FrameEvalSettings::DEFAULT)
Load ReferenceFrames, by ID, and their common ancestors.
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 ...
void default_normalize_linear(const ReferenceFrameType *, double &, double &, double &)
const std::string & id() const
Get the ID string of this frame.
static std::vector< ReferenceFrame > load_tree(madara::knowledge::KnowledgeBase &kb, InputIterator begin, InputIterator end, uint64_t timestamp=-1, const FrameEvalSettings &settings=FrameEvalSettings::DEFAULT)
Load ReferenceFrames, by ID, and their common ancestors.
const ReferenceFrameType * parent_frame
static const std::string & default_prefix()
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...
bool interpolated() const
Returns true if this frame was interpolated from two stored frames.
OrientationVector & as_orientation_vec()
Gets a reference to this object&#39;s Orientation part.
Contains all GAMS-related tools, classes and code.
void default_normalize_angular(const ReferenceFrameType *, double &, double &, double &)
std::shared_ptr< ReferenceFrameIdentity > ident_
const Pose & origin() const
Gets the origin of this Frame.
gams::pose::Orientation Orientation
Represents a orientation or orientation within a reference frame.
Definition: Orientation.h:94
ReferenceFrame orient(Orientation new_origin) const
Creates a new ReferenceFrame with modified origin.
static uint64_t latest_common_timestamp(madara::knowledge::KnowledgeBase &kb, ForwardIterator begin, ForwardIterator end, const FrameEvalSettings &settings=FrameEvalSettings::DEFAULT)
Get the latest available timestamp in the knowledge base common to all the given ids.
#define GAMS_EXPORT
Definition: GamsExport.h:20
Used internally to implement angle operations.
Definition: Quaternion.h:74
ReferenceFrame orient(const Orientation &new_origin, uint64_t timestamp) const
Creates a new ReferenceFrame with modified origin and timestamp.
static uint64_t default_expiry()
Return the default expiry for new frame IDs.
const std::string * id_ptr() const
Get the ID string of this frame.
const std::string & id() const
FrameStore(madara::knowledge::KnowledgeBase kb, FrameEvalSettings settings, uint64_t expiry)
Primary constructor for FrameStore.
ReferenceFrame origin_frame() const
Gets the parent frame (the one the origin is within).
void slerp_this(const Quaternion &o, double t)
If *this and o are unit quaternions, interpolate a quaternion that is partially between them...
bool has_id() const
Does this frame have an ID? Frames gain an ID either at construction, or lazily as needed (by having ...
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 ...
Thrown when an an attempt is made to transform between frames that do not belong to the same frame tr...
ReferenceFrameVersion(const ReferenceFrameType *type, P &&origin, uint64_t timestamp=-1)
Constructor from a type, an origin, and optional timestamp.
void register_version(uint64_t timestamp, std::shared_ptr< ReferenceFrameVersion > ver) const
ReferenceFrame pose(const Pose &new_origin, uint64_t timestamp) const
Creates a new ReferenceFrame with modified origin and timestamp.
static uint64_t init_timestamp(uint64_t given, const T &p)
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.
ReferenceFrameVersion(std::string name, P &&origin, uint64_t timestamp=-1)
Constructor from a id, an origin, and optional timestamp.
void orient_linear_vec(double &x, double &y, double &z, double rx, double ry, double rz, bool reverse=false)
Rotates a LinearVector according to a AngularVector.
std::shared_ptr< ReferenceFrameVersion > get_version(uint64_t timestamp) const
bool operator!=(const BasicVector< LDerived, Units > &lhs, const BasicVector< RDerived, Units > &rhs)
Definition: Coordinate.h:956
ReferenceFrame pose(Pose new_origin) const
Creates a new ReferenceFrame with modified origin.
std::map< uint64_t, std::weak_ptr< ReferenceFrameVersion > > versions_
static std::map< std::string, std::weak_ptr< ReferenceFrameIdentity > > idents_
const ReferenceFrameType * Cartesian
ReferenceFrameType struct for Cartesian frames.
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.
static uint64_t default_expiry(uint64_t age)
Set the default expiry value for new frames IDs.
static std::shared_ptr< ReferenceFrameIdentity > make_guid()
FrameStore(madara::knowledge::KnowledgeBase kb, FrameEvalSettings settings)
Constructor for FrameStore Uses ReferenceFrame::default_expiry() for expiration.
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 ReferenceFrameType * type() const
Retrieve the frame type object for this frame.
uint64_t timestamp() const
Get the timestamp assigned to this frame.
madara::knowledge::KnowledgeBase kb_
uint64_t expiry() const
Return the current expiry for all frames saved with this FrameStore See ReferenceFrame::expiry(uint64...
ReferenceFrame interpolate(const ReferenceFrame &other, ReferenceFrame parent, uint64_t time) const
Interpolate a frame between the given frame; use the given parent.
uint64_t try_get_nano_time(uint64_t def)
Base case: return default.
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.
uint64_t timestamp() const
Get the timestamp assigned to this frame.
FrameStore(madara::knowledge::KnowledgeBase kb)
Constructor for FrameStore Uses default FrameEvalSettings Uses ReferenceFrame::default_expiry() for e...
bool operator==(const BasicVector< LDerived, Units > &lhs, const BasicVector< RDerived, Units > &rhs)
Definition: Coordinate.h:955
const ReferenceFrame & frame() const
Getter for the ReferenceFrame this Coordinate belongs to.
Definition: Framed.h:179
std::string key(const FrameEvalSettings &settings=FrameEvalSettings::DEFAULT) const
Returns the key that save() will use to store this frame.
static const std::string & default_prefix()
gams::pose::Coordinate< CoordType > Coordinate
New coordinate types which are frame-dependant can inherit from this class.
Definition: Coordinate.h:137