GAMS  1.4.0
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 
118 
126 
134  const OrientationVector &rot);
135 
140 
142  static constexpr bool positional() { return true; }
143 
145  static constexpr bool rotational() { return true; }
146 
147  Derived &self() { return static_cast<Derived&>(*this); }
148  const Derived &self() const { return static_cast<const Derived&>(*this); }
149 
150  template<typename Derived2>
152  {
153  return as_position_vec();
154  }
155 
156  template<typename Derived2>
158  {
159  return as_orientation_vec();
160  }
161 
167  explicit BasicPose(
168  const madara::knowledge::containers::DoubleVector &vec);
169 
175  explicit BasicPose(
176  const madara::knowledge::containers::NativeDoubleVector &vec);
177 
183  explicit BasicPose(
184  const madara::knowledge::containers::DoubleVector &vec_loc,
185  const madara::knowledge::containers::DoubleVector &vec_rot);
186 
192  explicit BasicPose(
193  const madara::knowledge::containers::NativeDoubleVector &vec_loc,
194  const madara::knowledge::containers::NativeDoubleVector &vec_rot);
195 
201  bool is_set() const;
202 
208  bool is_position_set() const;
209  bool is_location_set() const;
210 
216  bool is_orientation_set() const;
217 
223  bool is_position_zero() const;
224  bool is_location_zero() const;
225 
231  bool is_orientation_zero() const;
232 
239  bool is_zero() const;
240 
247  bool operator==(const BasicPose &rhs) const;
248 
254  static std::string name();
255 
261  int size() const;
262 
270  double get(int i) const;
271 
280  double set(int i, double val);
281 
283 
290 
296  const BaseType &as_vec() const;
297 
305 
313 
320 
327 
338  template<typename Derived2>
340  double epsilon) const
341  {
342  (void)other;(void)epsilon;
343  throw "unimplemented";
344  //return std::fabs(self().distance_to(other.self())) < epsilon;
345  return false;
346  }
347 
348  template<typename Derived2>
349  double distance_to(const BasicPose<Derived2> &target) const {
350  (void)target;
351  throw "unimplemented";
352  //return(target.vec() - vec()).norm();
353  return 0;
354  }
355 
362  std::string to_string(
363  const std::string & delimiter = ", ",
364  const std::string & unset_identifier = "<unset>") const;
365 
371  madara::knowledge::containers::NativeDoubleVector &container) const;
372 
378  const madara::knowledge::containers::NativeDoubleVector &container);
379 
385  const std::vector <double> &container);
386 };
387 
388 class PoseVector :
389  public BasicPose<PoseVector>
390 {
392  using Base::Base;
393 
394  static constexpr const char *type_name = "PoseVector";
395 };
396 
397 class Pose :
398  public Framed<BasicPose<Pose>>
399 {
400 public:
402  using Base::Base;
403 
404  static constexpr const char *type_name = "Pose";
405 
406  Pose() = default;
407 
408  Pose(const Position &pos)
409  : Base(pos.frame(), PositionVector(pos)) {}
410 
411  Pose(const StampedPosition &pos)
412  : Base(pos.frame(), PositionVector(pos)) {}
413 
414  Pose(const Orientation &ori)
415  : Base(ori.frame(), OrientationVector(ori)) {}
416 
418  : Base(ori.frame(), OrientationVector(ori)) {}
419 
420  Pose(const Position &pos, const Orientation &ori)
421  : Base(pos.frame(), PositionVector(pos), OrientationVector(ori)) {}
422 
423  Pose(const StampedPosition &pos, const StampedOrientation &ori)
424  : Base(pos.frame(), PositionVector(pos), OrientationVector(ori)) {}
425 
432  double angle_to(const Pose &target) const;
433 
440  double angle_to(const Orientation &target) const;
441 
448  template<typename U> double angle_to(const Pose &target, U u) const;
449 
456  template<typename U> double angle_to(const Orientation &target, U u) const;
457 
463  operator Position() const;
464 
470  operator Orientation() const;
471 };
472 
473 class StampedPose :
474  public Stamped<Framed<BasicPose<StampedPose>>>
475 {
477  using Base::Base;
478 
479  static constexpr const char *type_name = "StampedPose";
480 
481  StampedPose() = default;
482 
483  StampedPose(const Position &pos)
484  : Base(pos.frame(), PositionVector(pos)) {}
485 
487  : Base(pos.time(), pos.frame(), PositionVector(pos)) {}
488 
490  : Base(ori.frame(), OrientationVector(ori)) {}
491 
493  : Base(ori.time(), ori.frame(), OrientationVector(ori)) {}
494 
495  StampedPose(const Position &pos, const Orientation &ori)
496  : Base(pos.frame(), PositionVector(pos), OrientationVector(ori)) {}
497 
499  : Base(pos.time(), pos.frame(),
500  PositionVector(pos), OrientationVector(ori)) {}
501 
509  operator StampedPosition() const
510  {
511  return StampedPosition(time(), frame(), this->as_position_vec());
512  }
513 
520  operator StampedOrientation() const
521  {
522  return StampedOrientation(time(), frame(), this->as_orientation_vec());
523  }
524 };
525 
526 template<typename Derived>
527 inline std::ostream &operator<<(std::ostream &o, const BasicPose<Derived> &pose)
528 {
529  o << Derived::type_name << "(";
530  o << pose.pos_vec();
531  o << ";";
532  o << pose.ori_vec();
533  o << ")";
534  return o;
535 }
536 
537 } }
538 
539 #endif
540 
541 #ifndef GAMS_NO_INL
542 #include "Pose.inl"
543 #endif
Underlying template for all Pose types, including PoseVector, Pose, and StampedPose See PositionVecto...
Definition: Pose.h:74
double get(int i) const
Retrives i'th coordinate, 0-indexed, in order x, y, z, rx, ry, rz.
PositionVector & as_position_vec()
Gets a reference to this object's Position part.
Derived derived_type
Definition: Pose.h:76
BasicPose()
Default constructor.
BasicPose BaseType
Definition: Pose.h:282
void to_container(madara::knowledge::containers::NativeDoubleVector &container) const
Saves the pose to a MADARA container.
BasicPose(const madara::knowledge::containers::DoubleVector &vec_loc, const madara::knowledge::containers::DoubleVector &vec_rot)
Constructor from two MADARA DoubleVectors, for position and orientation.
static constexpr bool positional()
Is this coordinate a positional one?
Definition: Pose.h:142
BasicPose(const madara::knowledge::containers::DoubleVector &vec)
Constructor from MADARA DoubleVector.
PositionVector & as_location_vec()
double set(int i, double val)
Sets i'th coordinate, 0-indexed, in order x, y, z, rx, ry, rz.
double distance_to(const BasicPose< Derived2 > &target) const
Definition: Pose.h:349
bool operator==(const BasicPose &rhs) const
Tests for exact equality.
const OrientationVector & as_orientation_vec() const
Gets a const reference to this object's Orientation part.
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.
bool is_orientation_set() const
Tests if the orientation/orientation has been set.
bool is_location_set() const
const PositionVector & as_location_vec() const
void from_container(const std::vector< double > &container)
Imports the pose from a STL vector container.
const BaseType & as_vec() const
Gets a const reference to this object.
static std::string name()
Get the name of this coordinate type.
BasicPose(double x, double y)
Constructs a BasicPose from individual position values.
Definition: Pose.h:84
BaseType & as_vec()
Gets a reference to this object.
bool is_location_zero() const
bool is_set() const
Tests if this Pose is invalid; i.e., any values are INVAL_COORD.
BasicPose(double x, double y, double z, double rx, double ry, double rz)
Constructs a BasicPose from individual position and orientation values.
BasicPose(const madara::knowledge::containers::NativeDoubleVector &vec)
Constructor from MADARA NativeDoubleVector.
bool is_position_set() const
Tests if the position is set(valid).
bool is_zero() const
Tests if all pose information is zero.
BasicPose(const PositionVector &pos)
Construct a BasicPose from a PositionVector.
BasicPose(const madara::knowledge::containers::NativeDoubleVector &vec_loc, const madara::knowledge::containers::NativeDoubleVector &vec_rot)
Constructor from two MADARA NativeDoubleVector, for position/orientation.
bool approximately_equal(const BasicPose< Derived2 > &other, double epsilon) const
Tests if this Coordinate is within epsilon in distance(as defined by this Coordinate's reference fram...
Definition: Pose.h:339
int size() const
Get the number of values this coordinate type uses.
BasicPose(const OrientationVector &rot)
Construct a BasicPose from a OrientationVector.
static constexpr bool rotational()
Is this coordinate a rotational one?
Definition: Pose.h:145
OrientationVector & as_orientation_vec()
Gets a reference to this object's Orientation part.
bool is_orientation_zero() const
Tests if all orientation information is zero.
BasicPose(double x, double y, double z)
Constructs a BasicPose from individual position values.
Definition: Pose.h:94
BasicPose(const PositionVector &pos, const OrientationVector &rot)
Construct from individual PositionVector and OrientationVector.
const PositionVector & as_position_vec() const
Gets a const reference to this object's Position part.
void from_container(const madara::knowledge::containers::NativeDoubleVector &container)
Imports the pose from a MADARA container.
bool is_position_zero() const
Tests if all position information is zero.
For internal use. The underlying template for all coordinate types.
Definition: Coordinate.h:528
Internal class implementing coordinates bound to reference frame.
Definition: Framed.h:108
const ReferenceFrame & frame() const
Getter for the ReferenceFrame this Coordinate belongs to.
Definition: Framed.h:179
static constexpr const char * type_name
Definition: Pose.h:394
Pose(const Position &pos, const Orientation &ori)
Definition: Pose.h:420
double angle_to(const Orientation &target) const
Finds angle to the target; transforms target to this frame if needed.
double angle_to(const Pose &target, U u) const
Finds angle to the target; transforms target to this frame if needed.
Pose(const StampedOrientation &ori)
Definition: Pose.h:417
Pose(const Position &pos)
Definition: Pose.h:408
double angle_to(const Orientation &target, U u) const
Finds angle to the target; transforms target to this frame if needed.
static constexpr const char * type_name
Definition: Pose.h:404
double angle_to(const Pose &target) const
Finds angle to the target; transforms target to this frame if needed.
Pose(const Orientation &ori)
Definition: Pose.h:414
Pose(const StampedPosition &pos)
Definition: Pose.h:411
Pose(const StampedPosition &pos, const StampedOrientation &ori)
Definition: Pose.h:423
BasicVector< PositionVector, units::absolute< units::length > > Base
Definition: Coordinate.h:1220
StampedPose(const Position &pos)
Definition: Pose.h:483
StampedPose(const Orientation &ori)
Definition: Pose.h:489
StampedPose(const StampedOrientation &ori)
Definition: Pose.h:492
static constexpr const char * type_name
Definition: Pose.h:479
StampedPose(const StampedPosition &pos, const StampedOrientation &ori)
Definition: Pose.h:498
StampedPose(const Position &pos, const Orientation &ori)
Definition: Pose.h:495
StampedPose(const StampedPosition &pos)
Definition: Pose.h:486
Internal class implementing coordinates stamped with timestamp.
Definition: Stamped.h:103
TimeValue time() const
Get time as std::chrono based TimeValue.
Definition: Stamped.h:167
BaseAlgorithm Base
std::ostream & operator<<(std::ostream &o, const Eigen::Vector3d &v)
Definition: Coordinate.h:1266
gams::pose::Orientation Orientation
Represents a orientation or orientation within a reference frame.
Definition: Orientation.h:94
Contains all GAMS-related tools, classes and code.
Copyright (c) 2015 Carnegie Mellon University.
Copyright (c) 2015-2018 Carnegie Mellon University.
Copyright (c) 2015 Carnegie Mellon University.