Trajectory.h
Go to the documentation of this file.
1 /**
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @author Fabian Reister ( fabian dot reister at kit dot edu )
17  * @author Christian R. G. Dreher ( c dot dreher at kit dot edu )
18  * @date 2021
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #pragma once
24 
25 #include <cstddef>
26 #include <memory>
27 
29 
31 
33 {
34 
36  {
38  float velocity; // [mm/s]
39  };
40 
41  using GlobalTrajectoryPoints = std::vector<GlobalTrajectoryPoint>;
42 
43  struct Projection
44  {
46 
49 
50  enum class Segment
51  {
52  FIRST,
54  FINAL
55  };
56 
58  };
59 
61  {
64  };
65 
66  using GlobalTrajectoryPtr = std::shared_ptr<class GlobalTrajectory>;
67 
69  {
70  public:
71  GlobalTrajectory() = default;
72 
73  GlobalTrajectory(const std::vector<GlobalTrajectoryPoint>& points) : pts(points)
74  {
75  }
76 
77  Projection getProjection(const Position& point,
78  const VelocityInterpolation& velocityInterpolation) const;
79 
80  /**
81  * @brief Project point onto the trajectory and return a new trajectory along the old one
82  * from that point for the specified distance.
83  * @return The subtrajectory and whether the subtrajectory ends at the same point,
84  * as this trajectory
85  */
86  std::pair<GlobalTrajectory, bool> getSubTrajectory(const Position& point,
87  const float distance) const;
88 
89  [[nodiscard]] std::vector<Position> positions() const noexcept;
90 
91  [[nodiscard]] std::vector<Pose> poses() const noexcept;
92 
93  //! Note: the velocity will not be set!
94  // currently, only 2D version
95  // y is pointing forward
96  static GlobalTrajectory FromPath(const Path& path, float velocity);
97  static GlobalTrajectory FromPath(const Path& path, const std::vector<float>& velocity);
98 
99  //! Note: the velocity will not be set!
100  // currently, only 2D version
101  // y is pointing forward
102  static GlobalTrajectory
103  FromPath(const Pose& start, const Positions& waypoints, const Pose& goal, float velocity);
104 
105 
106  static GlobalTrajectory
107  FromPath(const Pose& start, const Positions& waypoints, const Pose& goal, const std::vector<float>& velocity);
108 
109 
110  GlobalTrajectory resample(float eps) const;
111 
112  float length() const;
113 
114  void setMaxVelocity(float maxVelocity);
115 
116  bool hasMaxDistanceBetweenWaypoints(float maxDistance) const;
117 
118  const std::vector<GlobalTrajectoryPoint>& points() const;
119 
121 
122  float duration(core::VelocityInterpolation interpolation) const;
123 
124  bool isValid() const noexcept;
125 
126  using Indices = std::vector<std::size_t>;
127 
128  /**
129  * @brief get all points within a certain radius that are directly connected to idx
130  *
131  * @return the list without idx
132  *
133  */
134  Indices allConnectedPointsInRange(std::size_t idx, float radius) const;
135 
136  private:
137  struct InternalProjection
138  {
139  GlobalTrajectoryPoint projection;
140  size_t indexBefore;
141  };
142  InternalProjection
143  projectInternal(const Position& point,
144  const VelocityInterpolation& velocityInterpolation) const;
145 
146 
147  private:
148  std::vector<GlobalTrajectoryPoint> pts;
149  };
150 
151 
153  {
156  };
157 
158  using LocalTrajectoryPoints = std::vector<LocalTrajectoryPoint>;
159 
160  struct Evaluation
161  {
164  };
165 
166 
168  {
169  public:
170  LocalTrajectory() = default;
171 
172  LocalTrajectory(const std::vector<LocalTrajectoryPoint>& points) : pts(points)
173  {
174  }
175 
176  const std::vector<LocalTrajectoryPoint>& points() const;
177 
178  std::vector<LocalTrajectoryPoint>& mutablePoints();
179 
180  Evaluation evaluate(const DateTime& timestamp) const;
181 
182 
183  private:
184  std::vector<LocalTrajectoryPoint> pts;
185  };
186 
187 
188 } // namespace armarx::navigation::core
armarx::navigation::core::GlobalTrajectory
Definition: Trajectory.h:68
armarx::navigation::core::VelocityInterpolation
VelocityInterpolation
Definition: Trajectory.h:60
armarx::navigation::core::GlobalTrajectory::mutablePoints
std::vector< GlobalTrajectoryPoint > & mutablePoints()
Definition: Trajectory.cpp:738
armarx::navigation::core::Projection::Segment::INTERMEDIATE
@ INTERMEDIATE
armarx::navigation::core::LocalTrajectory::mutablePoints
std::vector< LocalTrajectoryPoint > & mutablePoints()
Definition: Trajectory.cpp:843
armarx::navigation::core::Projection::wayPointAfter
GlobalTrajectoryPoint wayPointAfter
Definition: Trajectory.h:48
armarx::navigation::core::Projection
Definition: Trajectory.h:43
armarx::navigation::core::GlobalTrajectory::isValid
bool isValid() const noexcept
Definition: Trajectory.cpp:779
armarx::navigation::core::VelocityInterpolation::LinearInterpolation
@ LinearInterpolation
armarx::navigation::core::GlobalTrajectory::GlobalTrajectory
GlobalTrajectory(const std::vector< GlobalTrajectoryPoint > &points)
Definition: Trajectory.h:73
armarx::navigation::core::GlobalTrajectory::Indices
std::vector< std::size_t > Indices
Definition: Trajectory.h:126
armarx::navigation::core::Pose
Eigen::Isometry3f Pose
Definition: basic_types.h:31
armarx::navigation::core::GlobalTrajectoryPoint::waypoint
Waypoint waypoint
Definition: Trajectory.h:37
basic_types.h
DateTime.h
armarx::navigation::core::GlobalTrajectoryPoint::velocity
float velocity
Definition: Trajectory.h:38
armarx::navigation::core::Projection::Segment::FIRST
@ FIRST
armarx::navigation::core::Projection::Segment
Segment
Definition: Trajectory.h:50
armarx::navigation::core::LocalTrajectoryPoint::timestamp
DateTime timestamp
Definition: Trajectory.h:154
armarx::navigation::core
This file is part of ArmarX.
Definition: aron_conversions.cpp:13
armarx::navigation::core::LocalTrajectoryPoints
std::vector< LocalTrajectoryPoint > LocalTrajectoryPoints
Definition: Trajectory.h:158
armarx::navigation::core::GlobalTrajectory::GlobalTrajectory
GlobalTrajectory()=default
armarx::navigation::core::GlobalTrajectoryPoints
std::vector< GlobalTrajectoryPoint > GlobalTrajectoryPoints
Definition: Trajectory.h:41
armarx::navigation::core::Projection::wayPointBefore
GlobalTrajectoryPoint wayPointBefore
Definition: Trajectory.h:47
armarx::navigation::core::GlobalTrajectoryPtr
std::shared_ptr< class GlobalTrajectory > GlobalTrajectoryPtr
Definition: Trajectory.h:66
armarx::navigation::core::Projection::Segment::FINAL
@ FINAL
armarx::navigation::core::GlobalTrajectoryPoint
Definition: Trajectory.h:35
armarx::navigation::core::LocalTrajectory::points
const std::vector< LocalTrajectoryPoint > & points() const
Definition: Trajectory.cpp:837
armarx::navigation::core::GlobalTrajectory::setMaxVelocity
void setMaxVelocity(float maxVelocity)
Definition: Trajectory.cpp:703
armarx::navigation::core::Twist
Definition: basic_types.h:53
armarx::navigation::core::LocalTrajectoryPoint
Definition: Trajectory.h:152
armarx::navigation::core::Evaluation::feedforwardTwist
core::Twist feedforwardTwist
Definition: Trajectory.h:163
armarx::navigation::core::GlobalTrajectory::getSubTrajectory
std::pair< GlobalTrajectory, bool > getSubTrajectory(const Position &point, const float distance) const
Project point onto the trajectory and return a new trajectory along the old one from that point for t...
Definition: Trajectory.cpp:287
armarx::navigation::core::Projection::projection
GlobalTrajectoryPoint projection
Definition: Trajectory.h:45
armarx::navigation::core::GlobalTrajectory::length
float length() const
Definition: Trajectory.cpp:682
armarx::navigation::core::Waypoint
Definition: basic_types.h:48
armarx::navigation::core::GlobalTrajectory::FromPath
static GlobalTrajectory FromPath(const Path &path, float velocity)
Note: the velocity will not be set!
Definition: Trajectory.cpp:359
armarx::navigation::core::LocalTrajectory
Definition: Trajectory.h:167
armarx::navigation::core::GlobalTrajectory::poses
std::vector< Pose > poses() const noexcept
Definition: Trajectory.cpp:344
armarx::navigation::core::LocalTrajectoryPoint::pose
core::Pose pose
Definition: Trajectory.h:155
armarx::navigation::core::LocalTrajectory::LocalTrajectory
LocalTrajectory()=default
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
armarx::navigation::core::GlobalTrajectory::duration
float duration(core::VelocityInterpolation interpolation) const
Definition: Trajectory.cpp:744
armarx::navigation::core::Positions
std::vector< Position > Positions
Definition: basic_types.h:37
armarx::navigation::core::Evaluation::pose
core::Pose pose
Definition: Trajectory.h:162
std
Definition: Application.h:66
armarx::navigation::core::Path
std::vector< Pose > Path
Definition: basic_types.h:46
armarx::navigation::core::LocalTrajectory::evaluate
Evaluation evaluate(const DateTime &timestamp) const
Definition: Trajectory.cpp:849
armarx::navigation::core::GlobalTrajectory::positions
std::vector< Position > positions() const noexcept
Definition: Trajectory.cpp:330
armarx::navigation::core::GlobalTrajectory::allConnectedPointsInRange
Indices allConnectedPointsInRange(std::size_t idx, float radius) const
get all points within a certain radius that are directly connected to idx
Definition: Trajectory.cpp:788
distance
double distance(const Point &a, const Point &b)
Definition: point.hpp:88
armarx::navigation::core::GlobalTrajectory::getProjection
Projection getProjection(const Position &point, const VelocityInterpolation &velocityInterpolation) const
Definition: Trajectory.cpp:243
armarx::navigation::core::Position
Eigen::Vector3f Position
Definition: basic_types.h:36
armarx::navigation::core::Evaluation
Definition: Trajectory.h:160
armarx::navigation::core::GlobalTrajectory::hasMaxDistanceBetweenWaypoints
bool hasMaxDistanceBetweenWaypoints(float maxDistance) const
Definition: Trajectory.cpp:714
armarx::navigation::core::Projection::segment
Segment segment
Definition: Trajectory.h:57
armarx::navigation::core::GlobalTrajectory::points
const std::vector< GlobalTrajectoryPoint > & points() const
Definition: Trajectory.cpp:732
armarx::navigation::core::GlobalTrajectory::resample
GlobalTrajectory resample(float eps) const
Definition: Trajectory.cpp:581
armarx::navigation::core::LocalTrajectory::LocalTrajectory
LocalTrajectory(const std::vector< LocalTrajectoryPoint > &points)
Definition: Trajectory.h:172
armarx::navigation::core::VelocityInterpolation::LastWaypoint
@ LastWaypoint