MRPT  2.0.4
TTwist2D.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
11 #include <mrpt/math/TPoseOrPoint.h>
12 #include <vector>
13 
14 namespace mrpt::math
15 {
16 /** 2D twist: 2D velocity vector (vx,vy) + planar angular velocity (omega)
17  * \sa mrpt::math::TTwist3D, mrpt::math::TPose2D
18  */
19 struct TTwist2D : public internal::ProvideStaticResize<TTwist2D>
20 {
21  enum
22  {
24  };
25  /** Velocity components: X,Y (m/s) */
26  double vx{.0}, vy{.0};
27  /** Angular velocity (rad/s) */
28  double omega{.0};
29 
30  /** Constructor from components */
31  constexpr TTwist2D(double vx_, double vy_, double omega_)
32  : vx(vx_), vy(vy_), omega(omega_)
33  {
34  }
35  /** Default fast constructor. Initializes to zeros */
36  TTwist2D() = default;
37  /** Coordinate access using operator[]. Order: vx,vy,vphi */
38  double& operator[](size_t i)
39  {
40  switch (i)
41  {
42  case 0:
43  return vx;
44  case 1:
45  return vy;
46  case 2:
47  return omega;
48  default:
49  throw std::out_of_range("index out of range");
50  }
51  }
52  /** Coordinate access using operator[]. Order: vx,vy,vphi */
53  constexpr double operator[](size_t i) const
54  {
55  switch (i)
56  {
57  case 0:
58  return vx;
59  case 1:
60  return vy;
61  case 2:
62  return omega;
63  default:
64  throw std::out_of_range("index out of range");
65  }
66  }
67  /** Transformation into vector */
68  void asVector(std::vector<double>& v) const
69  {
70  v.resize(3);
71  v[0] = vx;
72  v[1] = vy;
73  v[2] = omega;
74  }
75  /** Transform the (vx,vy) components for a counterclockwise rotation of
76  * `ang` radians. */
77  void rotate(const double ang);
78  bool operator==(const TTwist2D& o) const;
79  bool operator!=(const TTwist2D& o) const;
80  /** Returns the pose increment of multiplying each twist component times
81  * "dt" seconds. */
82  mrpt::math::TPose2D operator*(const double dt) const;
83 
84  /** Scale factor */
85  void operator*=(const double k)
86  {
87  vx *= k;
88  vy *= k;
89  omega *= k;
90  }
91 
92  /** Returns a human-readable textual representation of the object (eg: "[vx
93  * vy omega]", omega in deg/s)
94  * \sa fromString
95  */
96  void asString(std::string& s) const;
97  std::string asString() const
98  {
99  std::string s;
100  asString(s);
101  return s;
102  }
103 
104  /** Set the current object value from a string generated by 'asString' (eg:
105  * "[0.02 1.04 -45.0]" )
106  * \sa asString
107  * \exception std::exception On invalid format
108  */
109  void fromString(const std::string& s);
110 
111  static TTwist2D FromString(const std::string& s)
112  {
113  TTwist2D o;
114  o.fromString(s);
115  return o;
116  }
117 };
118 
123 
124 } // namespace mrpt::math
125 
126 namespace mrpt::typemeta
127 {
128 // Specialization must occur in the same namespace
130 
131 } // namespace mrpt::typemeta
bool operator==(const TTwist2D &o) const
Definition: Twist2D.cpp:47
void rotate(const double ang)
Transform the (vx,vy) components for a counterclockwise rotation of ang radians.
Definition: Twist2D.cpp:40
constexpr double operator[](size_t i) const
Coordinate access using operator[].
Definition: TTwist2D.h:53
mrpt::serialization::CArchive & operator>>(mrpt::serialization::CArchive &in, CMatrixD::Ptr &pObj)
2D twist: 2D velocity vector (vx,vy) + planar angular velocity (omega)
Definition: TTwist2D.h:19
std::string asString() const
Definition: TTwist2D.h:97
This base provides a set of functions for maths stuff.
mrpt::math::TPose2D operator*(const double dt) const
Returns the pose increment of multiplying each twist component times "dt" seconds.
Definition: Twist2D.cpp:52
double vx
Velocity components: X,Y (m/s)
Definition: TTwist2D.h:26
static TTwist2D FromString(const std::string &s)
Definition: TTwist2D.h:111
void fromString(const std::string &s)
Set the current object value from a string generated by &#39;asString&#39; (eg: "[0.02 1.04 -45...
Definition: Twist2D.cpp:27
#define MRPT_DECLARE_TTYPENAME_NO_NAMESPACE(_TYPE, __NS)
Declares a typename to be "type" (without the NS prefix)
Definition: TTypeName.h:128
void operator*=(const double k)
Scale factor.
Definition: TTwist2D.h:85
constexpr TTwist2D(double vx_, double vy_, double omega_)
Constructor from components.
Definition: TTwist2D.h:31
double & operator[](size_t i)
Coordinate access using operator[].
Definition: TTwist2D.h:38
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:54
Provided for STL and matrices/vectors compatibility.
Definition: TPoseOrPoint.h:63
mrpt::vision::TStereoCalibResults out
mrpt::serialization::CArchive & operator<<(mrpt::serialization::CArchive &s, const CVectorFloat &a)
Definition: math.cpp:626
bool operator!=(const TTwist2D &o) const
Definition: Twist2D.cpp:51
void asVector(std::vector< double > &v) const
Transformation into vector.
Definition: TTwist2D.h:68
Lightweight 2D pose.
Definition: TPose2D.h:22
TTwist2D()=default
Default fast constructor.
double omega
Angular velocity (rad/s)
Definition: TTwist2D.h:28



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020