GAMS  1.2.2
Pose.h
Go to the documentation of this file.
1 
54 #include "ReferenceFrame.h"
55 
56 #ifndef _GAMS_POSE_POSE_H_
57 #define _GAMS_POSE_POSE_H_
58 
59 #include <iostream>
60 #include <string>
61 
62 #include "gams/pose/Position.h"
63 #include "gams/pose/Orientation.h"
64 
65 namespace gams { namespace pose {
66 
72 template<typename Derived>
74 {
75 public:
76  using derived_type = Derived;
77 
84  BasicPose (double x, double y)
85  : BasicPose(x, y, 0, 0, 0, 0) {}
86 
94  BasicPose (double x, double y, double z)
95  : BasicPose(x, y, z, 0, 0, 0) {}
96 
97 
108  BasicPose (double x, double y, double z,
109  double rx, double ry, double rz);
110 
117  BasicPose (const PositionVector &pos);
118 
125  BasicPose (const OrientationVector &rot);
126 
133  BasicPose (const PositionVector &pos,
134  const OrientationVector &rot);
135 
139  BasicPose ();
140 
141  Derived &self() { return static_cast<Derived&>(*this); }
142  const Derived &self() const { return static_cast<const Derived&>(*this); }
143 
144  template<typename Derived2>
146  {
147  return as_position_vec();
148  }
149 
150  template<typename Derived2>
152  {
153  return as_orientation_vec();
154  }
155 
161  explicit BasicPose (
162  const madara::knowledge::containers::DoubleVector &vec);
163 
169  explicit BasicPose (
170  const madara::knowledge::containers::NativeDoubleVector &vec);
171 
177  explicit BasicPose (
178  const madara::knowledge::containers::DoubleVector &vec_loc,
179  const madara::knowledge::containers::DoubleVector &vec_rot);
180 
186  explicit BasicPose (
187  const madara::knowledge::containers::NativeDoubleVector &vec_loc,
188  const madara::knowledge::containers::NativeDoubleVector &vec_rot);
189 
195  bool is_set () const;
196 
202  bool is_position_set () const;
203  bool is_location_set () const;
204 
210  bool is_orientation_set () const;
211 
217  bool is_position_zero () const;
218  bool is_location_zero () const;
219 
225  bool is_orientation_zero () const;
226 
233  bool is_zero () const;
234 
241  bool operator== (const BasicPose &rhs) const;
242 
248  static std::string name ();
249 
255  int size () const;
256 
264  double get (int i) const;
265 
274  double set (int i, double val);
275 
277 
283  BaseType &as_vec ();
284 
290  const BaseType &as_vec () const;
291 
299 
305  const PositionVector &as_position_vec () const;
306  const PositionVector &as_location_vec () const;
307 
314 
320  const OrientationVector &as_orientation_vec () const;
321 
332  template<typename Derived2>
334  double epsilon) const
335  {
336  (void)other;(void)epsilon;
337  throw "unimplemented";
338  //return std::fabs(self().distance_to(other.self())) < epsilon;
339  return false;
340  }
341 
342  template<typename Derived2>
343  double distance_to(const BasicPose<Derived2> &target) const {
344  (void)target;
345  throw "unimplemented";
346  //return (target.vec() - vec()).norm();
347  return 0;
348  }
349 
356  std::string to_string (
357  const std::string & delimiter = ", ",
358  const std::string & unset_identifier = "<unset>") const;
359 
364  void to_container (
365  madara::knowledge::containers::NativeDoubleVector &container) const;
366 
371  void from_container (
372  const madara::knowledge::containers::NativeDoubleVector &container);
373 
378  void from_container (
379  const std::vector <double> &container);
380 };
381 
382 class PoseVector :
383  public BasicPose<PoseVector>
384 {
386  using Base::Base;
387 
388  static constexpr const char *type_name = "PoseVector";
389 };
390 
391 class Pose :
392  public Framed<BasicPose<Pose>>
393 {
394 public:
396  using Base::Base;
397 
398  static constexpr const char *type_name = "Pose";
399 
400  Pose() = default;
401 
402  Pose(const Position &pos)
403  : Base(pos.frame(), PositionVector(pos)) {}
404 
405  Pose(const StampedPosition &pos)
406  : Base(pos.frame(), PositionVector(pos)) {}
407 
408  Pose(const Orientation &ori)
409  : Base(ori.frame(), OrientationVector(ori)) {}
410 
412  : Base(ori.frame(), OrientationVector(ori)) {}
413 
414  Pose(const Position &pos, const Orientation &ori)
415  : Base(pos.frame(), PositionVector(pos), OrientationVector(ori)) {}
416 
417  Pose(const StampedPosition &pos, const StampedOrientation &ori)
418  : Base(pos.frame(), PositionVector(pos), OrientationVector(ori)) {}
419 
426  double angle_to (const Pose &target) const;
427 
434  double angle_to (const Orientation &target) const;
435 
442  template<typename U> double angle_to (const Pose &target, U u) const;
443 
450  template<typename U> double angle_to (const Orientation &target, U u) const;
451 
457  operator Position () const;
458 
464  operator Orientation () const;
465 };
466 
467 class StampedPose :
468  public Stamped<Framed<BasicPose<StampedPose>>>
469 {
471  using Base::Base;
472 
473  static constexpr const char *type_name = "StampedPose";
474 
475  StampedPose() = default;
476 
477  StampedPose(const Position &pos)
478  : Base(pos.frame(), PositionVector(pos)) {}
479 
481  : Base(pos.time(), pos.frame(), PositionVector(pos)) {}
482 
484  : Base(ori.frame(), OrientationVector(ori)) {}
485 
487  : Base(ori.time(), ori.frame(), OrientationVector(ori)) {}
488 
489  StampedPose(const Position &pos, const Orientation &ori)
490  : Base(pos.frame(), PositionVector(pos), OrientationVector(ori)) {}
491 
493  : Base(pos.time(), pos.frame(),
494  PositionVector(pos), OrientationVector(ori)) {}
495 
503  operator StampedPosition () const
504  {
505  return StampedPosition(time(), frame(), this->as_position_vec());
506  }
507 
514  operator StampedOrientation () const
515  {
516  return StampedOrientation(time(), frame(), this->as_orientation_vec());
517  }
518 };
519 
520 template<typename Derived>
521 inline std::ostream &operator<<(std::ostream &o, const BasicPose<Derived> &pose)
522 {
523  o << Derived::type_name << "(";
524  o << pose.pos_vec();
525  o << ";";
526  o << pose.ori_vec();
527  o << ")";
528  return o;
529 }
530 
531 } }
532 
533 #endif
534 
535 #ifndef GAMS_NO_INL
536 #include "Pose.inl"
537 #endif
PositionVector & as_position_vec()
Gets a reference to this object&#39;s Position part.
Internal class implementing coordinates stamped with timestamp.
Definition: Stamped.h:102
Pose(const StampedPosition &pos, const StampedOrientation &ori)
Definition: Pose.h:417
bool is_position_zero() const
Tests if all position information is zero.
bool is_zero() const
Tests if all pose information is zero.
BasicPose(double x, double y)
Constructs a BasicPose from individual position values.
Definition: Pose.h:84
static constexpr const char * type_name
Definition: Coordinate.h:1053
PositionVector & as_location_vec()
bool is_orientation_set() const
Tests if the orientation/orientation has been set.
BaseType & as_vec()
Gets a reference to this object.
void from_container(const madara::knowledge::containers::NativeDoubleVector &container)
Imports the pose from a MADARA container.
int size() const
Get the number of values this coordinate type uses.
Internal class implementing coordinates bound to reference frame.
Definition: Framed.h:107
StampedPose(const Orientation &ori)
Definition: Pose.h:483
bool is_position_set() const
Tests if the position is set (valid).
Pose(const Position &pos)
Definition: Pose.h:402
StampedPose(const Position &pos)
Definition: Pose.h:477
BasicPose(double x, double y, double z)
Constructs a BasicPose from individual position values.
Definition: Pose.h:94
BasicPose()
Default constructor.
BasicPose BaseType
Definition: Pose.h:276
bool is_location_set() const
std::string to_string(const std::string &delimiter=", ", const std::string &unset_identifier="<unset>") const
Returns a string of the values x, y, z, rx, ry, rz.
Pose(const StampedOrientation &ori)
Definition: Pose.h:411
bool is_location_zero() const
Pose(const StampedPosition &pos)
Definition: Pose.h:405
StampedPose(const Position &pos, const Orientation &ori)
Definition: Pose.h:489
OrientationVector & as_orientation_vec()
Gets a reference to this object&#39;s Orientation part.
Contains all GAMS-related tools, classes and code.
bool is_orientation_zero() const
Tests if all orientation information is zero.
gams::pose::Orientation Orientation
Represents a orientation or orientation within a reference frame.
Definition: Orientation.h:94
BaseAlgorithm Base
Underlying template for all Pose types, including PoseVector, Pose, and StampedPose See PositionVecto...
Definition: Pose.h:73
For internal use. The underlying template for all coordinate types.
Definition: Coordinate.h:516
StampedPose(const StampedOrientation &ori)
Definition: Pose.h:486
Pose(const Position &pos, const Orientation &ori)
Definition: Pose.h:414
bool operator==(const BasicPose &rhs) const
Tests for exact equality.
bool approximately_equal(const BasicPose< Derived2 > &other, double epsilon) const
Tests if this Coordinate is within epsilon in distance (as defined by this Coordinate&#39;s reference fra...
Definition: Pose.h:333
double distance_to(const BasicPose< Derived2 > &target) const
Definition: Pose.h:343
static std::string name()
Get the name of this coordinate type.
bool is_set() const
Tests if this Pose is invalid; i.e., any values are INVAL_COORD.
StampedPose(const StampedPosition &pos, const StampedOrientation &ori)
Definition: Pose.h:492
gams::pose::Pose Pose
Represents a combination of Location and Orientation within a single reference frame.
Definition: Pose.h:79
void to_container(madara::knowledge::containers::NativeDoubleVector &container) const
Saves the pose to a MADARA container.
StampedPose(const StampedPosition &pos)
Definition: Pose.h:480
Pose(const Orientation &ori)
Definition: Pose.h:408