CARLA
TrafficLightStage.h
Go to the documentation of this file.
1 
2 #pragma once
3 
9 
10 namespace carla {
11 namespace traffic_manager {
12 
13 /// This class has functionality for responding to traffic lights
14 /// and managing entry into non-signalized junctions.
16 private:
17  const std::vector<ActorId> &vehicle_id_list;
21  const cc::World &world;
22 
23  /// Variables used to handle non signalized junctions
24 
25  /// Map containing the vehicles entering a specific junction, ordered by time of arrival.
26  std::unordered_map<JunctionID, std::deque<ActorId>> entering_vehicles_map;
27  /// Map linking the vehicles with their current junction. Used for easy access to the previous two maps.
28  std::unordered_map<ActorId, JunctionID> vehicle_last_junction;
29  /// Map containing the timestamp at which the actor first stopped at a stop sign.
30  std::unordered_map<ActorId, cc::Timestamp> vehicle_stop_time;
34 
35  /// This controls all vehicle's interactions at non signalized junctions. Priorities are done by order of arrival
36  /// and no two vehicle will enter the junction at the same time. Only once it is exiting can the next one enter.
37  /// Additionally, all vehicles will always brake at the stop sign for a set amount of time.
38  bool HandleNonSignalisedJunction(const ActorId ego_actor_id, const JunctionID junction_id,
39  cc::Timestamp timestamp);
40 
41  /// Initialized the vehicle to the non-signalized junction maps
42  void AddActorToNonSignalisedJunction(const ActorId ego_actor_id, const JunctionID junction_id);
43 
44  /// Get current affected junction id for the vehicle
45  JunctionID GetAffectedJunctionId(const ActorId ego_actor_id);
46 
47 public:
48  TrafficLightStage(const std::vector<ActorId> &vehicle_id_list,
49  const SimulationState &Simulation_state,
50  const BufferMap &buffer_map,
51  const Parameters &parameters,
52  const cc::World &world,
53  TLFrame &output_array,
54  RandomGenerator &random_device);
55 
56  void Update(const unsigned long index) override;
57 
58  void RemoveActor(const ActorId actor_id) override;
59 
60  void Reset() override;
61 };
62 
63 } // namespace traffic_manager
64 } // namespace carla
std::vector< bool > TLFrame
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
void RemoveActor(const ActorId actor_id) override
std::unordered_map< carla::ActorId, Buffer > BufferMap
void Update(const unsigned long index) override
const std::vector< ActorId > & vehicle_id_list
carla::road::JuncId JunctionID
carla::ActorId ActorId
std::unordered_map< JunctionID, std::deque< ActorId > > entering_vehicles_map
Variables used to handle non signalized junctions.
This class has functionality for responding to traffic lights and managing entry into non-signalized ...
TrafficLightStage(const std::vector< ActorId > &vehicle_id_list, const SimulationState &Simulation_state, const BufferMap &buffer_map, const Parameters &parameters, const cc::World &world, TLFrame &output_array, RandomGenerator &random_device)
Stage type interface.
Definition: Stage.h:12
bool HandleNonSignalisedJunction(const ActorId ego_actor_id, const JunctionID junction_id, cc::Timestamp timestamp)
This controls all vehicle&#39;s interactions at non signalized junctions.
std::unordered_map< ActorId, JunctionID > vehicle_last_junction
Map linking the vehicles with their current junction. Used for easy access to the previous two maps...
std::unordered_map< ActorId, cc::Timestamp > vehicle_stop_time
Map containing the timestamp at which the actor first stopped at a stop sign.
JunctionID GetAffectedJunctionId(const ActorId ego_actor_id)
Get current affected junction id for the vehicle.
void AddActorToNonSignalisedJunction(const ActorId ego_actor_id, const JunctionID junction_id)
Initialized the vehicle to the non-signalized junction maps.