8 namespace traffic_manager {
16 const std::vector<ActorId> &vehicle_id_list,
23 : vehicle_id_list(vehicle_id_list),
24 simulation_state(simulation_state),
25 buffer_map(buffer_map),
26 parameters(parameters),
28 output_array(output_array),
29 random_device(random_device) {}
32 bool traffic_light_hazard =
false;
50 if (is_at_traffic_light &&
52 traffic_light_state != TLS::Off &&
55 if (current_junction_id != -1) {
58 traffic_light_hazard =
true;
62 else if (current_junction_id != -1)
64 if ( affected_junction_id == -1 || affected_junction_id != current_junction_id ) {
71 else if (affected_junction_id != -1 &&
72 !is_at_traffic_light &&
77 traffic_light_hazard =
true;
87 std::deque<ActorId> entry_deque;
92 if (std::find(entering_vehicles.begin(), entering_vehicles.end(), ego_actor_id) == entering_vehicles.end()){
94 entering_vehicles.push_back(ego_actor_id);
107 bool traffic_light_hazard =
false;
116 traffic_light_hazard =
true;
119 else if (entering_vehicles.front() == ego_actor_id) {
123 traffic_light_hazard =
true;
127 traffic_light_hazard =
true;
129 return traffic_light_hazard;
135 const auto front_point = waypoint_buffer.front();
137 auto look_ahead_junction_id = look_ahead_point->GetJunctionId();
138 auto front_junction_id = front_point->GetJunctionId();
146 if (current_junction_id != -1) {
148 if (current_junction_id == look_ahead_junction_id) {
149 return look_ahead_junction_id;
151 if (look_ahead_junction_id != -1) {
153 return look_ahead_junction_id;
155 if (current_junction_id == front_junction_id) {
157 return front_junction_id;
165 return look_ahead_junction_id;
174 auto ent_index = std::find(entering_vehicles.begin(), entering_vehicles.end(), actor_id);
175 if (ent_index != entering_vehicles.end()) {
176 entering_vehicles.erase(ent_index);
float GetPercentageRunningLight(const ActorId &actor_id) const
Method to get % to run any traffic light.
TargetWPInfo GetTargetWaypoint(const Buffer &waypoint_buffer, const float &target_point_distance)
static const float EPSILON_RELATIVE_SPEED
const BufferMap & buffer_map
const Parameters & parameters
cc::Timestamp current_timestamp
std::vector< bool > TLFrame
TrafficLightState GetTLS(const ActorId actor_id) const
This class holds the state of all the vehicles in the simlation.
This file contains definitions of common data structures used in traffic manager. ...
std::deque< std::shared_ptr< SimpleWaypoint > > Buffer
void RemoveActor(const ActorId actor_id) override
RandomGenerator & random_device
std::unordered_map< carla::ActorId, Buffer > BufferMap
const SimulationState & simulation_state
void Update(const unsigned long index) override
const std::vector< ActorId > & vehicle_id_list
const Timestamp & GetTimestamp() const
Get timestamp of this snapshot.
bool IsDormant(const ActorId actor_id) const
carla::road::JuncId JunctionID
std::unordered_map< JunctionID, std::deque< ActorId > > entering_vehicles_map
Variables used to handle non signalized junctions.
float GetPercentageRunningSign(const ActorId &actor_id) const
Method to get % to run any traffic light.
TrafficLightStage(const std::vector< ActorId > &vehicle_id_list, const SimulationState &Simulation_state, const BufferMap &buffer_map, const Parameters ¶meters, const cc::World &world, TLFrame &output_array, RandomGenerator &random_device)
std::shared_ptr< SimpleWaypoint > SimpleWaypointPtr
bool HandleNonSignalisedJunction(const ActorId ego_actor_id, const JunctionID junction_id, cc::Timestamp timestamp)
This controls all vehicle'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...
cg::Vector3D GetVelocity(const ActorId actor_id) const
static const double EXIT_JUNCTION_THRESHOLD
WorldSnapshot GetSnapshot() const
Return a snapshot of the world at this moment.
static const double MINIMUM_STOP_TIME
double elapsed_seconds
Simulated seconds elapsed since the beginning of the current episode.
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.
static const float JUNCTION_LOOK_AHEAD
void AddActorToNonSignalisedJunction(const ActorId ego_actor_id, const JunctionID junction_id)
Initialized the vehicle to the non-signalized junction maps.