MIRA
PathFollowTask.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 #ifndef _MIRA_PATHFOLLOWTASK_H_
48 #define _MIRA_PATHFOLLOWTASK_H_
49 
50 #include <geometry/Point.h>
51 #include <navigation/Task.h>
52 #include <transform/Pose.h>
53 
54 namespace mira { namespace navigation {
55 
57 
59 {
60 public:
61 
67  precision(0.1f),
70  {}
71 
77  PathFollowBaseTaskCommon(float iPrecision, float iGoalTransTolerance, Anglef iGoalOrientTolerance) :
78  precision(iPrecision),
79  goalTranslationTolerance(iGoalTransTolerance),
80  goalOrientationTolerance(iGoalOrientTolerance)
81  {}
82 
83  // keep using Angle for serialization compatibility
84  template<typename Reflector>
85  void reflectTolerance(Reflector& r) {
86  if (Reflector::isReadOnly::value) {
88  r.property("GoalOrientationTolerance", a,
89  "The orientation tolerance for reaching the goal point [deg]",
91  } else {
92  Anglef a;
93  r.property("GoalOrientationTolerance", a,
94  "The orientation tolerance for reaching the goal point [deg]",
95  Degreef(10.0f),
98  }
99  }
100 
102  r.property("GoalOrientationTolerance",
105  "The orientation tolerance for reaching the goal point [deg]",
106  10.f, PropertyHints::minimum(0.f));
107  }
108 
109 
111  template<typename Reflector>
112  void reflect(Reflector& r)
113  {
115  r.property("Precision", precision,
116  "The precision for following the path (max. distance from path) [m]", 0.25f);
117  r.property("GoalTranslationTolerance", goalTranslationTolerance,
118  "The position tolerance for reaching the goal point [m]", 0.1f);
119  reflectTolerance(r);
120  r.property("FrameID", frame,
121  "The coordinate frame of the points", "/GlobalFrame");
122  }
123 
124 public:
126  float precision;
127 
130 
133 
135  std::string frame;
136 };
137 
139 
140 template <typename T>
142 {
143 public:
144 
150  {}
151 
157  PathFollowBaseTask(float iPrecision, float iGoalTransTolerance, Anglef iGoalOrientTolerance) :
158  PathFollowBaseTaskCommon(iPrecision, iGoalTransTolerance, iGoalOrientTolerance)
159  {}
160 
162  template<typename Reflector>
163  void reflect(Reflector& r)
164  {
166  r.property("Points", points,
167  "Control points of the spline [m]");
168  }
169 
170  virtual bool reachedPosition(const typename T::value_type& pos) const { return true; }
171  virtual bool reachedOrientation(const typename T::value_type& pos) const { return true; }
172  virtual bool reached(const typename T::value_type& pos) const
173  {
174  return reachedPosition(pos) && reachedOrientation(pos);
175  }
176 
177 public:
180 };
181 
183 
187 class PathFollowTask : public PathFollowBaseTask<std::vector<Pose2>>
188 {
189  MIRA_OBJECT(PathFollowTask);
190 public:
191 
193 
195 
196  PathFollowTask(float iPrecision, float iGoalTransTolerance, Anglef iGoalOrientTolerance) :
197  Base(iPrecision, iGoalTransTolerance, iGoalOrientTolerance)
198  {}
199 
200  bool reachedPosition(const Pose2& pos) const
201  {
202  return reached(pos.t);
203  }
204 
205  bool reached(const Point2f& pos) const
206  {
207  if (points.empty())
208  return true;
209 
210  return (pos - points.back().t).norm() <= goalTranslationTolerance;
211  }
212 
213  bool reachedOrientation(const Pose2& pos) const
214  {
215  return reached(pos.phi());
216  }
217 
218  bool reached(float orientation) const
219  {
220  if (points.empty())
221  return true;
222 
223  return std::abs(smallestAngleDifference(orientation, points.back().phi())) <= goalOrientationTolerance;
224  }
225 };
226 
228 {
229 public:
231  VelocityWaypoint(const Point2f& p, float v) :
232  pos(p), vT(v) {}
233 
234  template<typename Reflector>
235  void reflect(Reflector& r)
236  {
237  r.member("Pos", pos, "Position");
238  r.member("vT", vT, "Velocity");
239  }
240 
242  float vT;
243 };
244 
246 
247 class VelocityWaypointTask : public PathFollowBaseTask<std::vector<VelocityWaypoint>>
248 {
249  MIRA_OBJECT(VelocityWaypointTask);
250 public:
252 
254 
255  VelocityWaypointTask(float iGoalTransTolerance) :
256  Base(0.0f, iGoalTransTolerance, Anglef(0.0f))
257  {}
258 
259  bool reachedPosition(const VelocityWaypoint& pos) const
260  {
261  return reached(pos.pos);
262  }
263 
264  bool reached(const Point2f& pos) const
265  {
266  if (points.empty())
267  return true;
268 
269  return (pos - points.back().pos).norm() <= goalTranslationTolerance;
270  }
271 
272 };
273 
275 
276 }} // namespace
277 
278 #endif
REFLECT_CTRLFLAG_TEMP_TRACKING
void reflect(Reflector &r)
Definition: PathFollowTask.h:235
void reflect(Reflector &r)
The reflect method.
Definition: PathFollowTask.h:112
PathFollowBaseTask< std::vector< VelocityWaypoint > > Base
Definition: PathFollowTask.h:251
PathFollowTask()
Definition: PathFollowTask.h:194
float vT
Definition: PathFollowTask.h:242
Definition: PathFollowTask.h:58
Getter< T > rad2degGetter(const T &cref)
virtual bool reachedOrientation(const typename T::value_type &pos) const
Definition: PathFollowTask.h:171
float goalOrientationTolerance
The tolerance for reaching the goal point [rad].
Definition: PathFollowTask.h:132
PathFollowBaseTask< std::vector< Pose2 > > Base
Definition: PathFollowTask.h:192
Task for precise following a predefined path, that is given as control points.
Definition: PathFollowTask.h:187
#define MIRA_REFLECT_BASE(reflector, BaseClass)
bool reached(const Point2f &pos) const
Definition: PathFollowTask.h:205
PathFollowBaseTaskCommon(float iPrecision, float iGoalTransTolerance, Anglef iGoalOrientTolerance)
Creates a task with given precision and a tolerance.
Definition: PathFollowTask.h:77
bool reachedPosition(const Pose2 &pos) const
Definition: PathFollowTask.h:200
PathFollowBaseTaskCommon()
Creates a path follow task with precision = goalTolerance = 0.1m and rotation tolerance 10 degrees...
Definition: PathFollowTask.h:66
PathFollowTask(float iPrecision, float iGoalTransTolerance, Anglef iGoalOrientTolerance)
Definition: PathFollowTask.h:196
Definition: PathFollowTask.h:141
T points
The control points of the path (the last point is the goal point).
Definition: PathFollowTask.h:179
Setter< T > deg2radSetter(T &ref)
Duration abs(const Duration &duration)
Definition: PathFollowTask.h:227
bool reachedPosition(const VelocityWaypoint &pos) const
Definition: PathFollowTask.h:259
Degree< float > Degreef
VelocityWaypoint(const Point2f &p, float v)
Definition: PathFollowTask.h:231
PathFollowBaseTask()
Creates a path follow task with precision = goalTolerance = 0.1m and rotation tolerance 10 degrees...
Definition: PathFollowTask.h:149
bool reachedOrientation(const Pose2 &pos) const
Definition: PathFollowTask.h:213
constexpr Deg2RadNonNegativeType Deg2RadNonNegative
Point2f pos
Definition: PathFollowTask.h:241
PropertyHint minimum(const T &min)
virtual bool reached(const typename T::value_type &pos) const
Definition: PathFollowTask.h:172
bool reached(const Point2f &pos) const
Definition: PathFollowTask.h:264
void reflect(Reflector &r)
The reflect method.
Definition: PathFollowTask.h:163
T rad() const
T smallestAngleDifference(const T &a, const T &b)
void reflectTolerance(Reflector &r)
Definition: PathFollowTask.h:85
Interface for sub tasks to be added to a navigation task.
Definition: Task.h:63
Base classes and interfaces for navigation tasks.
void reflectTolerance(PropertySerializer &r)
Definition: PathFollowTask.h:101
virtual bool reachedPosition(const typename T::value_type &pos) const
Definition: PathFollowTask.h:170
Definition: PathFollowTask.h:247
float precision
The precision for following the path (max. distance from path) [m].
Definition: PathFollowTask.h:126
float goalTranslationTolerance
The tolerance in for reaching the goal point [m].
Definition: PathFollowTask.h:129
VelocityWaypointTask(float iGoalTransTolerance)
Definition: PathFollowTask.h:255
PathFollowBaseTask(float iPrecision, float iGoalTransTolerance, Anglef iGoalOrientTolerance)
Creates a task with given precision and a tolerance.
Definition: PathFollowTask.h:157
std::string frame
The coordinate frame, the points are specified in.
Definition: PathFollowTask.h:135
void property(const char *name, T &member, const char *comment, PropertyHint &&hint=PropertyHint(), ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
VelocityWaypointTask()
Definition: PathFollowTask.h:253
bool reached(float orientation) const
Definition: PathFollowTask.h:218
VelocityWaypoint()
Definition: PathFollowTask.h:230