8namespace 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 &&
51 traffic_light_state != TLS::Green &&
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 &&
73 traffic_light_state != TLS::Green &&
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) {
121 if (timestamp.
elapsed_seconds - entry_elapsed_seconds < MINIMUM_STOP_TIME) {
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);
double elapsed_seconds
Simulated seconds elapsed since the beginning of the current episode.
const Timestamp & GetTimestamp() const
Get timestamp of this snapshot.
WorldSnapshot GetSnapshot() const
Return a snapshot of the world at this moment.
float GetPercentageRunningSign(const ActorId &actor_id) const
Method to get % to run any traffic light.
float GetPercentageRunningLight(const ActorId &actor_id) const
Method to get % to run any traffic light.
This class holds the state of all the vehicles in the simlation.
cg::Vector3D GetVelocity(const ActorId actor_id) const
TrafficLightState GetTLS(const ActorId actor_id) const
bool IsDormant(const ActorId actor_id) const
const Parameters & parameters
void AddActorToNonSignalisedJunction(const ActorId ego_actor_id, const JunctionID junction_id)
Initialized the vehicle to the non-signalized junction maps
void Update(const unsigned long index) override
JunctionID GetAffectedJunctionId(const ActorId ego_actor_id)
Get current affected junction id for the vehicle
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.
void RemoveActor(const ActorId actor_id) override
const std::vector< ActorId > & vehicle_id_list
std::unordered_map< JunctionID, std::deque< ActorId > > entering_vehicles_map
Variables used to handle non signalized junctions
const BufferMap & buffer_map
cc::Timestamp current_timestamp
bool HandleNonSignalisedJunction(const ActorId ego_actor_id, const JunctionID junction_id, cc::Timestamp timestamp)
This controls all vehicle's interactions at non signalized junctions.
RandomGenerator & random_device
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)
const SimulationState & simulation_state
static const float EPSILON_RELATIVE_SPEED
static const double EXIT_JUNCTION_THRESHOLD
static const double MINIMUM_STOP_TIME
static const float JUNCTION_LOOK_AHEAD
std::vector< bool > TLFrame
std::deque< std::shared_ptr< SimpleWaypoint > > Buffer
carla::road::JuncId JunctionID
std::shared_ptr< SimpleWaypoint > SimpleWaypointPtr
TargetWPInfo GetTargetWaypoint(const Buffer &waypoint_buffer, const float &target_point_distance)
std::unordered_map< carla::ActorId, Buffer > BufferMap
This file contains definitions of common data structures used in traffic manager.