MRPT  1.9.9
CPose3DInterpolator.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 CPose3DInterpolator::serializeGetVersion() const { return 1; }
22 {
23  out << m_path; // v1: change container element CPose3D->TPose3D
24 }
27 {
28  switch (version)
29  {
30  case 0:
31  {
32  std::map<mrpt::Clock::time_point, mrpt::poses::CPose3D> old_path;
33  in >> old_path;
34  m_path.clear();
35  for (const auto& p : old_path)
36  {
37  m_path[p.first] = p.second.asTPose();
38  }
39  }
40  break;
41  case 1:
42  {
43  in >> m_path;
44  }
45  break;
46  default:
48  };
49 }
50 
51 namespace mrpt::poses
52 {
53 // Specialization for DIM=3
54 template <>
56  const TTimePosePair &p1, const TTimePosePair &p2,
57  const TTimePosePair &p3, const TTimePosePair &p4,
58  const TInterpolatorMethod method, const mrpt::Clock::time_point &t, pose_t& out_interp) const
59 {
60  using mrpt::math::TPose3D;
61  mrpt::math::CArrayDouble<4> X, Y, Z, yaw, pitch, roll;
63  using doubleDuration = std::chrono::duration<double>;
64  doubleDuration durationT = t.time_since_epoch();
65  double td = durationT.count();
66  ts[0] = std::chrono::duration_cast<doubleDuration>(p1.first.time_since_epoch()).count();
67  ts[1] = std::chrono::duration_cast<doubleDuration>(p2.first.time_since_epoch()).count();
68  ts[2] = std::chrono::duration_cast<doubleDuration>(p3.first.time_since_epoch()).count();
69  ts[3] = std::chrono::duration_cast<doubleDuration>(p4.first.time_since_epoch()).count();
70 
71 
72  X[0] = p1.second.x;
73  Y[0] = p1.second.y;
74  Z[0] = p1.second.z;
75  X[1] = p2.second.x;
76  Y[1] = p2.second.y;
77  Z[1] = p2.second.z;
78  X[2] = p3.second.x;
79  Y[2] = p3.second.y;
80  Z[2] = p3.second.z;
81  X[3] = p4.second.x;
82  Y[3] = p4.second.y;
83  Z[3] = p4.second.z;
84 
85  yaw[0] = p1.second.yaw;
86  pitch[0] = p1.second.pitch;
87  roll[0] = p1.second.roll;
88  yaw[1] = p2.second.yaw;
89  pitch[1] = p2.second.pitch;
90  roll[1] = p2.second.roll;
91  yaw[2] = p3.second.yaw;
92  pitch[2] = p3.second.pitch;
93  roll[2] = p3.second.roll;
94  yaw[3] = p4.second.yaw;
95  pitch[3] = p4.second.pitch;
96  roll[3] = p4.second.roll;
97 
98  unwrap2PiSequence(yaw);
101 
102  // Target interpolated values:
103  switch (method)
104  {
105  case imSpline:
106  {
107  // ---------------------------------------
108  // SPLINE INTERPOLATION
109  // ---------------------------------------
110  out_interp.x = math::spline(td, ts, X);
111  out_interp.y = math::spline(td, ts, Y);
112  out_interp.z = math::spline(td, ts, Z);
113  out_interp.yaw = math::spline(td, ts, yaw, true); // Wrap 2pi
114  out_interp.pitch = math::spline(td, ts, pitch, true);
115  out_interp.roll = math::spline(td, ts, roll, true);
116  }
117  break;
118 
119  case imLinear2Neig:
120  {
121  out_interp.x =
122  math::interpolate2points(td, ts[1], X[1], ts[2], X[2]);
123  out_interp.y =
124  math::interpolate2points(td, ts[1], Y[1], ts[2], Y[2]);
125  out_interp.z =
126  math::interpolate2points(td, ts[1], Z[1], ts[2], Z[2]);
127  out_interp.yaw = math::interpolate2points(
128  td, ts[1], yaw[1], ts[2], yaw[2], true); // Wrap 2pi
129  out_interp.pitch = math::interpolate2points(
130  td, ts[1], pitch[1], ts[2], pitch[2], true);
131  out_interp.roll = math::interpolate2points(
132  td, ts[1], roll[1], ts[2], roll[2], true);
133  }
134  break;
135 
136  case imLinear4Neig:
137  {
138  out_interp.x =
139  math::leastSquareLinearFit<double, decltype(ts), 4>(td, ts, X);
140  out_interp.y =
141  math::leastSquareLinearFit<double, decltype(ts), 4>(td, ts, Y);
142  out_interp.z =
143  math::leastSquareLinearFit<double, decltype(ts), 4>(td, ts, Z);
144  out_interp.yaw =
145  math::leastSquareLinearFit<double, decltype(ts), 4>(
146  td, ts, yaw, true); // Wrap 2pi
147  out_interp.pitch =
148  math::leastSquareLinearFit<double, decltype(ts), 4>(
149  td, ts, pitch, true);
150  out_interp.roll =
151  math::leastSquareLinearFit<double, decltype(ts), 4>(
152  td, ts, roll, true);
153  }
154  break;
155 
156  case imSSLLLL:
157  {
158  out_interp.x = math::spline(td, ts, X);
159  out_interp.y = math::spline(td, ts, Y);
160  out_interp.z =
161  math::leastSquareLinearFit<double, decltype(ts), 4>(td, ts, Z);
162  out_interp.yaw =
163  math::leastSquareLinearFit<double, decltype(ts), 4>(
164  td, ts, yaw, true); // Wrap 2pi
165  out_interp.pitch =
166  math::leastSquareLinearFit<double, decltype(ts), 4>(
167  td, ts, pitch, true);
168  out_interp.roll =
169  math::leastSquareLinearFit<double, decltype(ts), 4>(
170  td, ts, roll, true);
171  }
172  break;
173 
174  case imSSLSLL:
175  {
176  out_interp.x = math::spline(td, ts, X);
177  out_interp.y = math::spline(td, ts, Y);
178  out_interp.z =
179  math::leastSquareLinearFit<double, decltype(ts), 4>(td, ts, Z);
180  out_interp.yaw = math::spline(td, ts, yaw, true); // Wrap 2pi
181  out_interp.pitch =
182  math::leastSquareLinearFit<double, decltype(ts), 4>(
183  td, ts, pitch, true);
184  out_interp.roll =
185  math::leastSquareLinearFit<double, decltype(ts), 4>(
186  td, ts, roll, true);
187  }
188  break;
189 
190  case imLinearSlerp:
191  {
192  const double ratio = (td - ts[1]) / (ts[2] - ts[1]);
194  TPose3D(0, 0, 0, yaw[1], pitch[1], roll[1]),
195  TPose3D(0, 0, 0, yaw[2], pitch[2], roll[2]), ratio, out_interp);
196 
197  out_interp.x =
198  math::interpolate2points(td, ts[1], X[1], ts[2], X[2]);
199  out_interp.y =
200  math::interpolate2points(td, ts[1], Y[1], ts[2], Y[2]);
201  out_interp.z =
202  math::interpolate2points(td, ts[1], Z[1], ts[2], Z[2]);
203  }
204  break;
205 
206  case imSplineSlerp:
207  {
208  const double ratio = (td - ts[1]) / (ts[2] - ts[1]);
210  TPose3D(0, 0, 0, yaw[1], pitch[1], roll[1]),
211  TPose3D(0, 0, 0, yaw[2], pitch[2], roll[2]), ratio, out_interp);
212 
213  out_interp.x = math::spline(td, ts, X);
214  out_interp.y = math::spline(td, ts, Y);
215  out_interp.z = math::spline(td, ts, Z);
216  }
217  break;
218 
219  default:
220  THROW_EXCEPTION("Unknown value for interpolation method!");
221  }; // end switch
222 }
223 
224 // Explicit instantations:
225 template class CPoseInterpolatorBase<3>;
226 }
227 
GLuint GLuint GLsizei count
Definition: glext.h:3528
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
GLdouble GLdouble t
Definition: glext.h:3689
void slerp_ypr(const mrpt::math::TPose3D &q0, const mrpt::math::TPose3D &q1, const double t, mrpt::math::TPose3D &p)
Definition: slerp.cpp:32
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
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
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
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
Lightweight 3D pose (three spatial coordinates, plus three angular coordinates).
GLuint in
Definition: glext.h:7274
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
This class stores a time-stamped trajectory in SE(3) (CPose3D poses).
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
GLfloat GLfloat p
Definition: glext.h:6305
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
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