MRPT  1.9.9
CPose2DInterpolator.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "poses-precomp.h" // Precompiled headers
11 
13 #include "CPoseInterpolatorBase.hpp" // templ impl
15 
16 using namespace mrpt::poses;
17 
19 
20 uint8_t CPose2DInterpolator::serializeGetVersion() const { return 0; }
22 {
23  out << m_path;
24 }
27 {
28  switch (version)
29  {
30  case 0:
31  {
32  in >> m_path;
33  }
34  break;
35  default:
37  };
38 }
39 
40 namespace mrpt::poses
41 {
42 // Specialization for DIM=2
43 template <>
45  const TTimePosePair &p1, const TTimePosePair &p2,
46  const TTimePosePair &p3, const TTimePosePair &p4,
47  const TInterpolatorMethod method, const mrpt::Clock::time_point &t, pose_t& out_interp) const
48 {
49  using mrpt::math::TPose2D;
50  using doubleDuration = std::chrono::duration<double>;
51  doubleDuration durationT(t.time_since_epoch());
52  double td = durationT.count();
54  ts[0] = std::chrono::duration_cast<doubleDuration>(p1.first.time_since_epoch()).count();
55  ts[1] = std::chrono::duration_cast<doubleDuration>(p2.first.time_since_epoch()).count();
56  ts[2] = std::chrono::duration_cast<doubleDuration>(p3.first.time_since_epoch()).count();
57  ts[3] = std::chrono::duration_cast<doubleDuration>(p4.first.time_since_epoch()).count();
58 
60  X[0] = p1.second.x;
61  Y[0] = p1.second.y;
62  yaw[0] = p1.second.phi;
63  X[1] = p2.second.x;
64  Y[1] = p2.second.y;
65  yaw[1] = p2.second.phi;
66  X[2] = p3.second.x;
67  Y[2] = p3.second.y;
68  yaw[2] = p3.second.phi;
69  X[3] = p4.second.x;
70  Y[3] = p4.second.y;
71  yaw[3] = p4.second.phi;
72 
73  unwrap2PiSequence(yaw);
74 
75  // Target interpolated values:
76  switch (method)
77  {
78  case imSpline:
79  {
80  // ---------------------------------------
81  // SPLINE INTERPOLATION
82  // ---------------------------------------
83  out_interp.x = math::spline(td, ts, X);
84  out_interp.y = math::spline(td, ts, Y);
85  out_interp.phi = math::spline(td, ts, yaw, true); // Wrap 2pi
86  }
87  break;
88 
89  case imLinear2Neig:
90  {
91  out_interp.x =
92  math::interpolate2points(td, ts[1], X[1], ts[2], X[2]);
93  out_interp.y =
94  math::interpolate2points(td, ts[1], Y[1], ts[2], Y[2]);
95  out_interp.phi = math::interpolate2points(
96  td, ts[1], yaw[1], ts[2], yaw[2], true); // Wrap 2pi
97  }
98  break;
99 
100  case imLinear4Neig:
101  {
102  out_interp.x =
103  math::leastSquareLinearFit<double, decltype(ts), 4>(td, ts, X);
104  out_interp.y =
105  math::leastSquareLinearFit<double, decltype(ts), 4>(td, ts, Y);
106  out_interp.phi =
107  math::leastSquareLinearFit<double, decltype(ts), 4>(
108  td, ts, yaw, true); // Wrap 2pi
109  }
110  break;
111 
112  case imSSLLLL:
113  {
114  out_interp.x = math::spline(td, ts, X);
115  out_interp.y = math::spline(td, ts, Y);
116  out_interp.phi =
117  math::leastSquareLinearFit<double, decltype(ts), 4>(
118  td, ts, yaw, true); // Wrap 2pi
119  }
120  break;
121 
122  case imSSLSLL:
123  {
124  out_interp.x = math::spline(td, ts, X);
125  out_interp.y = math::spline(td, ts, Y);
126  out_interp.phi = math::spline(td, ts, yaw, true); // Wrap 2pi
127  }
128  break;
129 
130  case imLinearSlerp:
131  {
132  const double ratio = (td - ts[1]) / (ts[2] - ts[1]);
133  const double Aang = mrpt::math::angDistance(yaw[1], yaw[2]);
134  out_interp.phi = yaw[1] + ratio * Aang;
135 
136  out_interp.x =
137  math::interpolate2points(td, ts[1], X[1], ts[2], X[2]);
138  out_interp.y =
139  math::interpolate2points(td, ts[1], Y[1], ts[2], Y[2]);
140  }
141  break;
142 
143  case imSplineSlerp:
144  {
145  const double ratio = (td - ts[1]) / (ts[2] - ts[1]);
146  const double Aang = mrpt::math::angDistance(yaw[1], yaw[2]);
147  out_interp.phi = yaw[1] + ratio * Aang;
148 
149  out_interp.x = math::spline(td, ts, X);
150  out_interp.y = math::spline(td, ts, Y);
151  }
152  break;
153 
154  default:
155  THROW_EXCEPTION("Unknown value for interpolation method!");
156  }; // end switch
157 }
158 
159 // Explicit instantations:
160 template class CPoseInterpolatorBase<2>;
161 }
162 
GLuint GLuint GLsizei count
Definition: glext.h:3528
GLdouble GLdouble t
Definition: glext.h:3689
This class stores a time-stamped trajectory in SE(2) (mrpt::math::TPose2D poses). ...
std::chrono::time_point< Clock > time_point
Definition: Clock.h:26
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:41
std::pair< mrpt::Clock::time_point, pose_t > TTimePosePair
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
CArrayNumeric is an array for numeric types supporting several mathematical operations (actually...
Definition: CArrayNumeric.h:25
T angDistance(T from, T to)
Computes the shortest angular increment (or distance) between two planar orientations, such that it is constrained to [-pi,pi] and is correct for any combination of angles (e.g.
Definition: wrap2pi.h:96
typename mrpt::poses::SE_traits< DIM >::lightweight_pose_t pose_t
TPose2D or TPose3D.
unsigned char uint8_t
Definition: rptypes.h:41
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:90
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:52
void unwrap2PiSequence(VECTOR &x)
Modify a sequence of angle values such as no consecutive values have a jump larger than PI in absolut...
Definition: wrap2pi.h:72
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
NUMTYPE spline(const NUMTYPE t, const VECTORLIKE &x, const VECTORLIKE &y, bool wrap2pi=false)
Interpolates the value of a function in a point "t" given 4 SORTED points where "t" is between the tw...
Definition: interp_fit.hpp:34
GLuint in
Definition: glext.h:7274
Lightweight 2D pose.
void impl_interpolation(const TTimePosePair &p1, const TTimePosePair &p2, const TTimePosePair &p3, const TTimePosePair &p4, const TInterpolatorMethod method, const mrpt::Clock::time_point &td, pose_t &out_interp) const
double interpolate2points(const double x, const double x0, const double y0, const double x1, const double y1, bool wrap2pi=false)
Linear interpolation/extrapolation: evaluates at "x" the line (x0,y0)-(x1,y1).
Definition: math.cpp:436
TInterpolatorMethod
Type to select the interpolation method in CPoseInterpolatorBase derived classes. ...



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020