selfdriving
SE2_KinState.h
Go to the documentation of this file.
1 /* -------------------------------------------------------------------------
2  * SelfDriving C++ library based on PTGs and mrpt-nav
3  * Copyright (C) 2019-2022 Jose Luis Blanco, University of Almeria
4  * See LICENSE for license information.
5  * ------------------------------------------------------------------------- */
6 
7 #pragma once
8 
9 #include <mrpt/math/TPoint2D.h>
10 #include <mrpt/math/TPose2D.h>
11 #include <mrpt/math/TTwist2D.h>
12 
13 #include <variant>
14 
15 // Include the "_deg" literal from mrpt:
16 #include <mrpt/core/bits_math.h> // _deg literal
17 #include <mrpt/version.h>
18 
19 namespace mpp
20 {
21 #if MRPT_VERSION >= 0x258
22 using namespace mrpt::literals; // "_deg" literal
23 #else
24 using namespace mrpt; // backwards compat
25 #endif
26 
27 /** Variant wrapper holding a SE(2) pose, a R(2) (2D) point, or none (default).
28  * It is used to provide a goal or waypoint state, when the heading is not
29  * important and the user only wants to specify the (x,y) coordinates of the 2D
30  * point.
31  */
33 {
34  PoseOrPoint() = default;
35  ~PoseOrPoint() = default;
36 
37  /** Returns a point or a pose depending on the input string having the
38  * format `"[x y]"` or `"[x y phi_degrees]"`, respectively.
39  */
40  static PoseOrPoint FromString(const std::string& s);
41 
42  PoseOrPoint(const mrpt::math::TPoint2D& p) : data_(p) {}
43  PoseOrPoint(const mrpt::math::TPose2D& p) : data_(p) {}
44 
45  bool isEmpty() const { return data_.index() == 0; }
46  bool isPose() const { return data_.index() == 1; }
47  bool isPoint() const { return data_.index() == 2; }
48 
49  const mrpt::math::TPose2D& pose() const
50  {
51  return std::get<mrpt::math::TPose2D>(data_);
52  }
53  const mrpt::math::TPoint2D& point() const
54  {
55  return std::get<mrpt::math::TPoint2D>(data_);
56  }
57 
58  std::string asString() const;
59 
60  private:
61  std::variant<std::monostate, mrpt::math::TPose2D, mrpt::math::TPoint2D>
63 };
64 
66 {
67  SE2_KinState() = default;
68 
69  mrpt::math::TPose2D pose{0, 0, 0}; //!< global pose (x,y,phi)
70  mrpt::math::TTwist2D vel{0, 0, 0}; //!< global velocity (vx,vy,omega)
71 
72  std::string asString() const;
73 };
74 
76 {
77  SE2orR2_KinState() = default;
78 
79  PoseOrPoint state; //!< global pose (x,y,phi) or point(x,y)
80  mrpt::math::TTwist2D vel{0, 0, 0}; //!< global velocity (vx,vy,omega)
81 
82  /** Returns a SE2_KinState exact equivalent of this object, if state is a
83  pose, or transforms the point into a pose with phi=0 otherwise. */
84  SE2_KinState asSE2KinState() const;
85 
86  std::string asString() const;
87 };
88 
89 } // namespace mpp
PoseOrPoint(const mrpt::math::TPoint2D &p)
Definition: SE2_KinState.h:42
Definition: bestTrajectory.h:15
Definition: SE2_KinState.h:32
std::variant< std::monostate, mrpt::math::TPose2D, mrpt::math::TPoint2D > data_
Definition: SE2_KinState.h:62
Definition: SE2_KinState.h:65
const mrpt::math::TPose2D & pose() const
Definition: SE2_KinState.h:49
bool isPoint() const
Definition: SE2_KinState.h:47
bool isEmpty() const
Definition: SE2_KinState.h:45
const mrpt::math::TPoint2D & point() const
Definition: SE2_KinState.h:53
bool isPose() const
Definition: SE2_KinState.h:46
PoseOrPoint(const mrpt::math::TPose2D &p)
Definition: SE2_KinState.h:43
PoseOrPoint state
global pose (x,y,phi) or point(x,y)
Definition: SE2_KinState.h:79
Definition: SE2_KinState.h:75