CARLA
CollisionStage.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include <memory>
5 
6 #include "boost/geometry.hpp"
7 #include "boost/geometry/geometries/geometries.hpp"
8 #include "boost/geometry/geometries/point_xy.hpp"
9 #include "boost/geometry/geometries/polygon.hpp"
10 
16 
17 namespace carla {
18 namespace traffic_manager {
19 
25 };
26 
27 struct CollisionLock {
31 };
32 using CollisionLockMap = std::unordered_map<ActorId, CollisionLock>;
33 
34 namespace cc = carla::client;
35 namespace bg = boost::geometry;
36 
37 using Buffer = std::deque<std::shared_ptr<SimpleWaypoint>>;
38 using BufferMap = std::unordered_map<carla::ActorId, Buffer>;
39 using LocationVector = std::vector<cg::Location>;
40 using GeodesicBoundaryMap = std::unordered_map<ActorId, LocationVector>;
41 using GeometryComparisonMap = std::unordered_map<uint64_t, GeometryComparison>;
42 using Polygon = bg::model::polygon<bg::model::d2::point_xy<double>>;
43 
44 /// This class has functionality to detect potential collision with a nearby actor.
46 private:
47  const std::vector<ActorId> &vehicle_id_list;
53  // Structure keeping track of blocking lead vehicles.
55  // Structures to cache geodesic boundaries of vehicle and
56  // comparision between vehicle boundaries
57  // to avoid repeated computation within a cycle.
61 
62  // Method to determine if a vehicle is on a collision path to another.
63  std::pair<bool, float> NegotiateCollision(const ActorId reference_vehicle_id,
64  const ActorId other_actor_id,
65  const uint64_t reference_junction_look_ahead_index);
66 
67  // Method to calculate bounding box extention length ahead of the vehicle.
68  float GetBoundingBoxExtention(const ActorId actor_id);
69 
70  // Method to calculate polygon points around the vehicle's bounding box.
71  LocationVector GetBoundary(const ActorId actor_id);
72 
73  // Method to construct polygon points around the path boundary of the vehicle.
74  LocationVector GetGeodesicBoundary(const ActorId actor_id);
75 
76  Polygon GetPolygon(const LocationVector &boundary);
77 
78  // Method to compare path boundaries, bounding boxes of vehicles
79  // and cache the results for reuse in current update cycle.
80  GeometryComparison GetGeometryBetweenActors(const ActorId reference_vehicle_id,
81  const ActorId other_actor_id);
82 
83  // Method to draw path boundary.
84  void DrawBoundary(const LocationVector &boundary);
85 
86 public:
87  CollisionStage(const std::vector<ActorId> &vehicle_id_list,
88  const SimulationState &simulation_state,
89  const BufferMap &buffer_map,
90  const TrackTraffic &track_traffic,
91  const Parameters &parameters,
92  CollisionFrame &output_array,
93  RandomGeneratorMap &random_devices);
94 
95  void Update (const unsigned long index) override;
96 
97  void RemoveActor(const ActorId actor_id) override;
98 
99  void Reset() override;
100 
101  // Method to flush cache for current update cycle.
102  void ClearCycleCache();
103 };
104 
105 } // namespace traffic_manager
106 } // 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::unordered_map< carla::rpc::ActorId, RandomGenerator > RandomGeneratorMap
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