ad_rss
TrajectoryCommon.hpp
Go to the documentation of this file.
1 // ----------------- BEGIN LICENSE BLOCK ---------------------------------
2 //
3 // Copyright (C) 2020-2021 Intel Corporation
4 //
5 // SPDX-License-Identifier: LGPL-2.1-only
6 //
7 // ----------------- END LICENSE BLOCK -----------------------------------
12 #pragma once
13 
14 #include <ad/geometry/GeometryOperation.hpp>
15 #include <ad/geometry/Types.hpp>
16 #include <ad/physics/Angle.hpp>
17 #include <ad/physics/Dimension2D.hpp>
18 #include <ad/physics/Distance.hpp>
20 
24 namespace ad {
28 namespace rss {
32 namespace unstructured {
33 
37 enum class VehicleCorner
38 {
39  frontLeft,
40  frontRight,
41  backLeft,
42  backRight
43 };
44 
49 {
51  {
52  }
53 
54  enum class SpeedMode
55  {
56  Min,
57  Max
58  };
59 
60  explicit TrajectoryPoint(core::RelativeObjectState const &vehicleState, SpeedMode const speedMode)
61  {
62  position = ::ad::geometry::toPoint(vehicleState.unstructured_object_state.center_point);
63  angle = vehicleState.unstructured_object_state.yaw;
64  if (speedMode == SpeedMode::Min)
65  {
66  speed = vehicleState.unstructured_object_state.speed_range.minimum;
67  }
68  else
69  {
70  speed = vehicleState.unstructured_object_state.speed_range.maximum;
71  }
73  }
74 
75  TrajectoryPoint(::ad::geometry::Point const &inPoint,
76  physics::Angle const &inAngle,
77  physics::Speed const &inSpeed,
78  physics::AngularVelocity const &inYawRate)
79  : position(inPoint)
80  , speed(inSpeed)
81  , angle(inAngle)
82  , yaw_rate(inYawRate)
83  {
84  }
85 
89  bool operator==(const TrajectoryPoint &other) const
90  {
91  return (position == other.position) && (speed == other.speed) && (angle == other.angle)
92  && (yaw_rate == other.yaw_rate);
93  }
94 
98  bool operator!=(const TrajectoryPoint &other) const
99  {
100  return !operator==(other);
101  }
102 
106  ::ad::geometry::Point position;
107 
111  physics::Speed speed;
112 
116  physics::Angle angle;
117 
121  physics::AngularVelocity yaw_rate;
122 };
123 
125 {
127  {
128  }
129 
130  TrajectorySetStep(TrajectoryPoint const &inLeft, TrajectoryPoint const &inRight, TrajectoryPoint const &inCenter)
131  : center(inCenter)
132  {
133  left.push_back(inLeft);
134  right.push_back(inRight);
135  }
136 
140  bool operator==(const TrajectorySetStep &other) const
141  {
142  return (left == other.left) && (right == other.right) && (center == other.center);
143  }
144 
148  bool operator!=(const TrajectorySetStep &other) const
149  {
150  return !operator==(other);
151  }
152 
153  std::vector<TrajectoryPoint> left; // with positive yaw rate ratio
154  std::vector<TrajectoryPoint> right; // with negative yaw rate ratio
155  TrajectoryPoint center;
156 };
157 
167 ::ad::geometry::Point getVehicleCorner(TrajectoryPoint const &point,
168  core::RelativeObjectState const &vehicleState,
169  VehicleCorner const corner);
170 
172 {
174  {
175  }
176 
178  {
179  frontLeft = getVehicleCorner(pt, vehicleState, VehicleCorner::frontLeft);
180  frontRight = getVehicleCorner(pt, vehicleState, VehicleCorner::frontRight);
181  backLeft = getVehicleCorner(pt, vehicleState, VehicleCorner::backLeft);
182  backRight = getVehicleCorner(pt, vehicleState, VehicleCorner::backRight);
183  }
184 
185  ::ad::geometry::Polygon toPolygon() const
186  {
187  ::ad::geometry::Polygon vehiclePolygon;
188  boost::geometry::append(vehiclePolygon, frontRight);
189  boost::geometry::append(vehiclePolygon, frontLeft);
190  boost::geometry::append(vehiclePolygon, backLeft);
191  boost::geometry::append(vehiclePolygon, backRight);
192  boost::geometry::append(vehiclePolygon, frontRight);
193  return vehiclePolygon;
194  }
195  ::ad::geometry::MultiPoint toMultiPoint() const
196  {
197  ::ad::geometry::MultiPoint geometry;
198  boost::geometry::append(geometry, frontRight);
199  boost::geometry::append(geometry, frontLeft);
200  boost::geometry::append(geometry, backLeft);
201  boost::geometry::append(geometry, backRight);
202  boost::geometry::append(geometry, frontRight);
203  return geometry;
204  }
205 
206  bool operator==(TrafficParticipantLocation const &other) const
207  {
208  return (frontLeft == other.frontLeft) && (frontRight == other.frontRight) && (backLeft == other.backLeft)
209  && (backRight == other.backRight);
210  }
211  bool operator!=(TrafficParticipantLocation const &other) const
212  {
213  return !(*this == other);
214  }
215  ::ad::geometry::Point frontLeft;
216  ::ad::geometry::Point frontRight;
217  ::ad::geometry::Point backLeft;
218  ::ad::geometry::Point backRight;
219 };
220 
224 using Trajectory = std::vector<TrajectoryPoint>;
225 
227 {
231 
232  bool operator==(TrajectorySetStepVehicleLocation const &other) const
233  {
234  return (left == other.left) && (right == other.right) && (center == other.center);
235  }
236 
237  bool operator!=(TrajectorySetStepVehicleLocation const &other) const
238  {
239  return !(*this == other);
240  }
241 };
242 
253 bool calculateEstimationBetweenSteps(::ad::geometry::Polygon &polygon,
254  TrajectorySetStepVehicleLocation const &previousVehicleLocation,
255  TrajectorySetStepVehicleLocation const &currentVehicleLocation,
256  std::string const &debugNamespace);
269  TrajectorySetStep const &step,
270  std::string const &debugNamespace,
271  ::ad::geometry::Polygon &polygon,
272  TrajectorySetStepVehicleLocation &stepVehicleLocation);
273 
288  TrajectorySetStepVehicleLocation const &initialStepVehicleLocation,
289  std::vector<TrajectorySetStep> const &sideSteps,
290  TrajectorySetStep const &front,
291  std::string const &debugNamespace,
292  ::ad::geometry::Polygon &resultPolygon,
293  TrajectorySetStepVehicleLocation &frontSideStepVehicleLocation);
294 
307  TrajectorySetStepVehicleLocation const &initialStepVehicleLocation,
308  std::string const &debugNamespace,
309  ::ad::geometry::Polygon &resultPolygon);
310 } // namespace unstructured
311 } // namespace rss
312 } // namespace ad
VehicleCorner
corner of a vehicle
Definition: TrajectoryCommon.hpp:38
bool calculateEstimationBetweenSteps(::ad::geometry::Polygon &polygon, TrajectorySetStepVehicleLocation const &previousVehicleLocation, TrajectorySetStepVehicleLocation const &currentVehicleLocation, std::string const &debugNamespace)
Calculate a trajectory set estimation between two steps.
bool calculateStepPolygon(core::RelativeObjectState const &vehicleState, TrajectorySetStep const &step, std::string const &debugNamespace, ::ad::geometry::Polygon &polygon, TrajectorySetStepVehicleLocation &stepVehicleLocation)
Calculate a polygon for one step.
bool calculateResponseTimePolygon(core::RelativeObjectState const &vehicleState, TrajectorySetStepVehicleLocation const &initialStepVehicleLocation, std::string const &debugNamespace, ::ad::geometry::Polygon &resultPolygon)
Calculate a simple polygon spanning the current vehicle pose polygon and the provided initialStepVehi...
std::vector< TrajectoryPoint > Trajectory
Definition: TrajectoryCommon.hpp:224
bool calculateFrontAndSidePolygon(core::RelativeObjectState const &vehicleState, TrajectorySetStepVehicleLocation const &initialStepVehicleLocation, std::vector< TrajectorySetStep > const &sideSteps, TrajectorySetStep const &front, std::string const &debugNamespace, ::ad::geometry::Polygon &resultPolygon, TrajectorySetStepVehicleLocation &frontSideStepVehicleLocation)
Calculate the front and side polygon.
::ad::geometry::Point getVehicleCorner(TrajectoryPoint const &point, core::RelativeObjectState const &vehicleState, VehicleCorner const corner)
get the point describing the corner of a vehicle
namespace ad
Definition: LateralRelativePosition.hpp:28
DataType RelativeObjectState.
Definition: RelativeObjectState.hpp:48
::ad::rss::world::ObjectState unstructured_object_state
Definition: RelativeObjectState.hpp:136
Definition: TrajectoryCommon.hpp:172
a point of a trajectory
Definition: TrajectoryCommon.hpp:49
bool operator!=(const TrajectoryPoint &other) const
Definition: TrajectoryCommon.hpp:98
physics::Speed speed
Definition: TrajectoryCommon.hpp:111
bool operator==(const TrajectoryPoint &other) const
Definition: TrajectoryCommon.hpp:89
::ad::geometry::Point position
Definition: TrajectoryCommon.hpp:106
physics::AngularVelocity yaw_rate
Definition: TrajectoryCommon.hpp:121
physics::Angle angle
Definition: TrajectoryCommon.hpp:116
Definition: TrajectoryCommon.hpp:125
bool operator==(const TrajectorySetStep &other) const
Definition: TrajectoryCommon.hpp:140
bool operator!=(const TrajectorySetStep &other) const
Definition: TrajectoryCommon.hpp:148
::ad::physics::Angle yaw
Definition: ObjectState.hpp:130
::ad::physics::AngularVelocity yaw_rate
Definition: ObjectState.hpp:140
::ad::physics::Distance2D center_point
Definition: ObjectState.hpp:145
::ad::physics::SpeedRange speed_range
Definition: ObjectState.hpp:150