MRPT  1.9.9
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-2019, 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 const 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  /** Returns a human-readable textual representation of the object (eg: "[vx
84  * vy omega]", omega in deg/s)
85  * \sa fromString
86  */
87  void asString(std::string& s) const;
89  {
90  std::string s;
91  asString(s);
92  return s;
93  }
94 
95  /** Set the current object value from a string generated by 'asString' (eg:
96  * "[0.02 1.04 -45.0]" )
97  * \sa asString
98  * \exception std::exception On invalid format
99  */
100  void fromString(const std::string& s);
101 };
102 
107 
108 } // namespace mrpt::math
109 
110 namespace mrpt::typemeta
111 {
112 // Specialization must occur in the same namespace
114 
115 } // namespace mrpt::typemeta
void rotate(const double ang)
Transform the (vx,vy) components for a counterclockwise rotation of ang radians.
GLdouble s
Definition: glext.h:3682
2D twist: 2D velocity vector (vx,vy) + planar angular velocity (omega)
Definition: TTwist2D.h:19
std::string asString() const
Definition: TTwist2D.h:88
This base provides a set of functions for maths stuff.
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...
double vx
Velocity components: X,Y (m/s)
Definition: TTwist2D.h:26
constexpr const double & operator[](size_t i) const
Coordinate access using operator[].
Definition: TTwist2D.h:53
mrpt::math::TPose2D operator*(const double dt) const
Returns the pose increment of multiplying each twist component times "dt" seconds.
#define MRPT_DECLARE_TTYPENAME_NO_NAMESPACE(_TYPE, __NS)
Declares a typename to be "type" (without the NS prefix)
Definition: TTypeName.h:128
GLsizei const GLchar ** string
Definition: glext.h:4116
mrpt::serialization::CArchive & operator>>(mrpt::serialization::CArchive &in, CMatrixD::Ptr &pObj)
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
const GLdouble * v
Definition: glext.h:3684
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:53
Provided for STL and matrices/vectors compatibility.
Definition: TPoseOrPoint.h:54
mrpt::serialization::CArchive & operator<<(mrpt::serialization::CArchive &s, const CVectorFloat &a)
Definition: math.cpp:630
void asVector(std::vector< double > &v) const
Transformation into vector.
Definition: TTwist2D.h:68
GLuint in
Definition: glext.h:7391
Lightweight 2D pose.
Definition: TPose2D.h:22
TTwist2D()=default
Default fast constructor.
double omega
Angular velocity (rad/s)
Definition: TTwist2D.h:28
bool operator!=(const TTwist2D &o) const
bool operator==(const TTwist2D &o) const



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019