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 
12 
18 
19 namespace carla {
20 namespace traffic_manager {
21 
27 };
28 
29 struct CollisionLock {
33 };
34 using CollisionLockMap = std::unordered_map<ActorId, CollisionLock>;
35 
36 namespace cc = carla::client;
37 namespace bg = boost::geometry;
38 
39 using Buffer = std::deque<std::shared_ptr<SimpleWaypoint>>;
40 using BufferMap = std::unordered_map<carla::ActorId, Buffer>;
41 using LocationVector = std::vector<cg::Location>;
42 using GeodesicBoundaryMap = std::unordered_map<ActorId, LocationVector>;
43 using GeometryComparisonMap = std::unordered_map<uint64_t, GeometryComparison>;
44 using Polygon = bg::model::polygon<bg::model::d2::point_xy<double>>;
45 
46 /// This class has functionality to detect potential collision with a nearby actor.
48 private:
49  const std::vector<ActorId> &vehicle_id_list;
56  // Structure keeping track of blocking lead vehicles.
58  // Structures to cache geodesic boundaries of vehicle and
59  // comparision between vehicle boundaries
60  // to avoid repeated computation within a cycle.
64 
65  // Method to determine if a vehicle is on a collision path to another.
66  std::pair<bool, float> NegotiateCollision(const ActorId reference_vehicle_id,
67  const ActorId other_actor_id,
68  const uint64_t reference_junction_look_ahead_index);
69 
70  // Method to calculate bounding box extention length ahead of the vehicle.
71  float GetBoundingBoxExtention(const ActorId actor_id);
72 
73  // Method to calculate polygon points around the vehicle's bounding box.
74  LocationVector GetBoundary(const ActorId actor_id);
75 
76  // Method to construct polygon points around the path boundary of the vehicle.
77  LocationVector GetGeodesicBoundary(const ActorId actor_id);
78 
79  Polygon GetPolygon(const LocationVector &boundary);
80 
81  // Method to compare path boundaries, bounding boxes of vehicles
82  // and cache the results for reuse in current update cycle.
83  GeometryComparison GetGeometryBetweenActors(const ActorId reference_vehicle_id,
84  const ActorId other_actor_id);
85 
86  // Method to draw path boundary.
87  void DrawBoundary(const LocationVector &boundary);
88 
89 public:
90  CollisionStage(const std::vector<ActorId> &vehicle_id_list,
91  const SimulationState &simulation_state,
92  const BufferMap &buffer_map,
93  const TrackTraffic &track_traffic,
94  const Parameters &parameters,
95  CollisionFrame &output_array,
96  cc::DebugHelper& debug_helper,
97  RandomGeneratorMap &random_devices);
98 
99  void Update (const unsigned long index) override;
100 
101  void RemoveActor(const ActorId actor_id) override;
102 
103  void Reset() override;
104 
105  // Method to flush cache for current update cycle.
106  void ClearCycleCache();
107 };
108 
109 } // namespace traffic_manager
110 } // 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:99
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