CARLA
TrackTraffic.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "carla/road/RoadTypes.h"
5 #include "carla/rpc/ActorId.h"
6 
8 
9 namespace carla {
10 namespace traffic_manager {
11 
12 using ActorId = carla::ActorId;
13 using ActorIdSet = std::unordered_set<ActorId>;
14 using SimpleWaypointPtr = std::shared_ptr<SimpleWaypoint>;
15 using Buffer = std::deque<SimpleWaypointPtr>;
17 
18 // This class is used to track the waypoint occupancy of all the actors.
19 class TrackTraffic {
20 
21 private:
22  /// Structure to keep track of overlapping waypoints between vehicles.
23  using WaypointOverlap = std::unordered_map<uint64_t, ActorIdSet>;
25 
26  /// Structure to keep track of waypoints occupied by vehicles;
27  using WaypointIdSet = std::unordered_set<uint64_t>;
28  using WaypointOccupancyMap = std::unordered_map<ActorId, WaypointIdSet>;
30 
31  /// Geodesic grids occupied by actors's paths.
32  std::unordered_map<ActorId, std::unordered_set<GeoGridId>> actor_to_grids;
33  /// Actors currently passing through grids.
34  std::unordered_map<GeoGridId, ActorIdSet> grid_to_actors;
35  /// Current hero location.
37 
38 
39 public:
40  TrackTraffic();
41 
42  /// Methods to update, remove and retrieve vehicles passing through a waypoint.
43  void UpdatePassingVehicle(uint64_t waypoint_id, ActorId actor_id);
44  void RemovePassingVehicle(uint64_t waypoint_id, ActorId actor_id);
45  ActorIdSet GetPassingVehicles(uint64_t waypoint_id) const;
46 
47  void UpdateGridPosition(const ActorId actor_id, const Buffer &buffer);
48  void UpdateUnregisteredGridPosition(const ActorId actor_id,
49  const std::vector<SimpleWaypointPtr> waypoints);
50 
52  bool IsGeoGridFree(const GeoGridId geogrid_id) const;
53  void AddTakenGrid(const GeoGridId geogrid_id, const ActorId actor_id);
54 
55  void SetHeroLocation(const cg::Location location);
57 
58 
59  /// Method to delete actor data from tracking.
60  void DeleteActor(ActorId actor_id);
61 
62  void Clear();
63 };
64 
65 } // namespace traffic_manager
66 } // namespace carla
std::unordered_map< uint64_t, ActorIdSet > WaypointOverlap
Structure to keep track of overlapping waypoints between vehicles.
Definition: TrackTraffic.h:23
cg::Location hero_location
Current hero location.
Definition: TrackTraffic.h:36
std::unordered_set< uint64_t > WaypointIdSet
Structure to keep track of waypoints occupied by vehicles;.
Definition: TrackTraffic.h:27
void SetHeroLocation(const cg::Location location)
rpc::ActorId ActorId
Definition: ActorId.h:18
void UpdatePassingVehicle(uint64_t waypoint_id, ActorId actor_id)
Methods to update, remove and retrieve vehicles passing through a waypoint.
void UpdateGridPosition(const ActorId actor_id, const Buffer &buffer)
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
std::unordered_set< ActorId > ActorIdSet
std::deque< std::shared_ptr< SimpleWaypoint > > Buffer
int32_t JuncId
Definition: RoadTypes.h:17
void RemovePassingVehicle(uint64_t waypoint_id, ActorId actor_id)
std::unordered_map< GeoGridId, ActorIdSet > grid_to_actors
Actors currently passing through grids.
Definition: TrackTraffic.h:34
geom::Location Location
Definition: rpc/Location.h:14
void UpdateUnregisteredGridPosition(const ActorId actor_id, const std::vector< SimpleWaypointPtr > waypoints)
carla::ActorId ActorId
ActorIdSet GetOverlappingVehicles(ActorId actor_id) const
crd::JuncId GeoGridId
Definition: InMemoryMap.h:48
void DeleteActor(ActorId actor_id)
Method to delete actor data from tracking.
WaypointOccupancyMap waypoint_occupied
Definition: TrackTraffic.h:29
std::shared_ptr< SimpleWaypoint > SimpleWaypointPtr
void AddTakenGrid(const GeoGridId geogrid_id, const ActorId actor_id)
cg::Location GetHeroLocation() const
bool IsGeoGridFree(const GeoGridId geogrid_id) const
ActorIdSet GetPassingVehicles(uint64_t waypoint_id) const
std::unordered_map< ActorId, std::unordered_set< GeoGridId > > actor_to_grids
Geodesic grids occupied by actors&#39;s paths.
Definition: TrackTraffic.h:32
std::unordered_map< ActorId, WaypointIdSet > WaypointOccupancyMap
Definition: TrackTraffic.h:28