CARLA
CollisionStage.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include <memory>
5 
6 #if defined(__clang__)
7 # pragma clang diagnostic push
8 # pragma clang diagnostic ignored "-Wshadow"
9 #endif
10 #include "boost/geometry.hpp"
11 #include "boost/geometry/geometries/geometries.hpp"
12 #include "boost/geometry/geometries/point_xy.hpp"
13 #include "boost/geometry/geometries/polygon.hpp"
14 #if defined(__clang__)
15 # pragma clang diagnostic pop
16 #endif
17 
23 
24 namespace carla {
25 namespace traffic_manager {
26 
32 };
33 
34 struct CollisionLock {
38 };
39 using CollisionLockMap = std::unordered_map<ActorId, CollisionLock>;
40 
41 namespace cc = carla::client;
42 namespace bg = boost::geometry;
43 
44 using Buffer = std::deque<std::shared_ptr<SimpleWaypoint>>;
45 using BufferMap = std::unordered_map<carla::ActorId, Buffer>;
46 using LocationVector = std::vector<cg::Location>;
47 using GeodesicBoundaryMap = std::unordered_map<ActorId, LocationVector>;
48 using GeometryComparisonMap = std::unordered_map<uint64_t, GeometryComparison>;
49 using Polygon = bg::model::polygon<bg::model::d2::point_xy<double>>;
50 
51 /// This class has functionality to detect potential collision with a nearby actor.
53 private:
54  const std::vector<ActorId> &vehicle_id_list;
60  // Structure keeping track of blocking lead vehicles.
62  // Structures to cache geodesic boundaries of vehicle and
63  // comparision between vehicle boundaries
64  // to avoid repeated computation within a cycle.
68 
69  // Method to determine if a vehicle is on a collision path to another.
70  std::pair<bool, float> NegotiateCollision(const ActorId reference_vehicle_id,
71  const ActorId other_actor_id,
72  const uint64_t reference_junction_look_ahead_index);
73 
74  // Method to calculate bounding box extention length ahead of the vehicle.
75  float GetBoundingBoxExtention(const ActorId actor_id);
76 
77  // Method to calculate polygon points around the vehicle's bounding box.
78  LocationVector GetBoundary(const ActorId actor_id);
79 
80  // Method to construct polygon points around the path boundary of the vehicle.
81  LocationVector GetGeodesicBoundary(const ActorId actor_id);
82 
83  Polygon GetPolygon(const LocationVector &boundary);
84 
85  // Method to compare path boundaries, bounding boxes of vehicles
86  // and cache the results for reuse in current update cycle.
87  GeometryComparison GetGeometryBetweenActors(const ActorId reference_vehicle_id,
88  const ActorId other_actor_id);
89 
90  // Method to draw path boundary.
91  void DrawBoundary(const LocationVector &boundary);
92 
93 public:
94  CollisionStage(const std::vector<ActorId> &vehicle_id_list,
95  const SimulationState &simulation_state,
96  const BufferMap &buffer_map,
97  const TrackTraffic &track_traffic,
98  const Parameters &parameters,
99  CollisionFrame &output_array,
100  RandomGenerator &random_device);
101 
102  void Update (const unsigned long index) override;
103 
104  void RemoveActor(const ActorId actor_id) override;
105 
106  void Reset() override;
107 
108  // Method to flush cache for current update cycle.
109  void ClearCycleCache();
110 };
111 
112 } // namespace traffic_manager
113 } // namespace carla
std::vector< cg::Location > LocationVector
std::unordered_map< ActorId, LocationVector > GeodesicBoundaryMap
std::unordered_map< uint64_t, GeometryComparison > GeometryComparisonMap
This class holds the state of all the vehicles in the simlation.
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
std::unordered_map< ActorId, CollisionLock > CollisionLockMap
std::deque< std::shared_ptr< SimpleWaypoint > > Buffer
std::unordered_map< carla::ActorId, Buffer > BufferMap
carla::ActorId ActorId
const SimulationState & simulation_state
Stage type interface.
Definition: Stage.h:12
bg::model::polygon< bg::model::d2::point_xy< double > > Polygon
const std::vector< ActorId > & vehicle_id_list
This class has functionality to detect potential collision with a nearby actor.
std::vector< CollisionHazardData > CollisionFrame