MIRA
Trajectory.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
47 #pragma once
48 
49 #include <vector>
50 
51 #include <transform/Pose.h>
52 #include <transform/Velocity.h>
53 #include <utils/Time.h>
54 
55 namespace mira { namespace robot {
56 
58 
63 template<int D>
65 {
66 public:
68 
69 public:
70 
72 
73  PoseTrajectorySample(const Time& iT, const Pose& iP) :
74  t(iT),p(iP) {}
75 
76  template<typename Reflector>
77  void reflect(Reflector& r)
78  {
79  r.member("Timestamp", t, "");
80  p.reflect(r);
81  }
82 
83 public:
86 };
87 
92 {
93 public:
94 
96 
97  PoseVelocityTrajectorySample(const Pose2& iP, const Velocity2& iV, float iDT) :
98  p(iP), v(iV), dt(iDT) {}
99 
100  template<typename Reflector>
101  void reflect(Reflector& r)
102  {
103  r.member("Pose", p, "");
104  r.member("Velocity", v, "");
105  r.member("DeltaTime", dt, "");
106  }
107 
108 public:
111  float dt;
112 };
113 
118 typedef std::vector<PoseVelocityTrajectorySample, Eigen::aligned_allocator<PoseVelocityTrajectorySample>> PoseVelocityTrajectory;
119 
124 template <int D>
125 class PoseTrajectory : public std::vector<PoseTrajectorySample<D>,Eigen::aligned_allocator<PoseTrajectorySample<D>>>
126 {
127 public:
128  typedef std::vector<PoseTrajectorySample<D>,Eigen::aligned_allocator<PoseTrajectorySample<D>>> Base;
129 
130  template<typename Reflector>
131  void reflect(Reflector& r) {
133  }
134 
138 
139  void push_back(const Time& t, const Pose& p) {
140  Base::push_back(Sample(t,p));
141  }
142 
143  // need to "inherit" the method explicitly, as we overloaded it above :(
144  void push_back(const Sample& s) {
145  Base::push_back(s);
146  }
147 
148  typedef typename Base::iterator iterator;
149  typedef typename Base::const_iterator const_iterator;
155  iterator find(const Time& t, iterator start) {
156  for(iterator it=start; it!=this->end(); ++it) {
157  if(it->t >= t)
158  return it;
159  }
160  return this->end(); // not found
161  }
162  iterator find(const Time& t) {
163  return find(t, this->begin());
164  }
165 };
166 
169 
171 
172 } } // namespace
float dt
Definition: Trajectory.h:111
void reflect(Reflector &r)
Definition: Trajectory.h:101
Time t
Definition: Trajectory.h:84
void reflect(Reflector &r)
Definition: Trajectory.h:77
std::vector< PoseVelocityTrajectorySample, Eigen::aligned_allocator< PoseVelocityTrajectorySample > > PoseVelocityTrajectory
A sampled trajectory, a collection of trajectory samples, each containing a pose and velocity at a de...
Definition: Trajectory.h:118
RigidTransform< float, D > Pose
Definition: Trajectory.h:67
A single sample of a sampled trajectory, containing a pose, velocity and a delta time.
Definition: Trajectory.h:91
PoseVelocityTrajectorySample(const Pose2 &iP, const Velocity2 &iV, float iDT)
Definition: Trajectory.h:97
#define MIRA_REFLECT_BASE(reflector, BaseClass)
PoseVelocityTrajectorySample()
Definition: Trajectory.h:95
Pose p
Definition: Trajectory.h:85
Pose2 p
Definition: Trajectory.h:109
iterator find(const Time &t)
Definition: Trajectory.h:162
Velocity2 v
Definition: Trajectory.h:110
std::vector< PoseTrajectorySample< D >, Eigen::aligned_allocator< PoseTrajectorySample< D > > > Base
Definition: Trajectory.h:128
void reflect(Reflector &r)
Definition: Trajectory.h:131
void push_back(const Sample &s)
Definition: Trajectory.h:144
PoseTrajectorySample< D > Sample
a single trajectory sample
Definition: Trajectory.h:136
RigidTransform< float, D > Pose
Definition: Trajectory.h:137
A sampled trajectory, a collection of trajectory samples, each containing a pose at a certain time...
Definition: Trajectory.h:125
iterator find(const Time &t, iterator start)
Finds the first item in the trajectory, whose timestamp is equal or older to the given timestamp...
Definition: Trajectory.h:155
PoseTrajectorySample(const Time &iT, const Pose &iP)
Definition: Trajectory.h:73
PoseTrajectory< 3 > PoseTrajectory3
Definition: Trajectory.h:168
Base::const_iterator const_iterator
Definition: Trajectory.h:149
PoseTrajectorySample()
Definition: Trajectory.h:71
Base::iterator iterator
Definition: Trajectory.h:148
void push_back(const Time &t, const Pose &p)
Definition: Trajectory.h:139
A single sample of a sampled trajectory, containing a pose and the time.
Definition: Trajectory.h:64
PoseTrajectory< 2 > PoseTrajectory2
Definition: Trajectory.h:167