10using constants::TrafficLight::EXIT_JUNCTION_THRESHOLD;
11using constants::TrafficLight::MINIMUM_STOP_TIME;
12using constants::WaypointSelection::JUNCTION_LOOK_AHEAD;
13using constants::MotionPlan::EPSILON_RELATIVE_SPEED;
20 const cc::World &
world,
32 bool traffic_light_hazard =
false;
49 if (is_at_traffic_light &&
50 traffic_light_state != TLS::Green &&
51 traffic_light_state != TLS::Off &&
54 if (current_junction_id != -1) {
57 traffic_light_hazard =
true;
61 else if (current_junction_id != -1)
63 if ( affected_junction_id == -1 || affected_junction_id != current_junction_id ) {
70 else if (affected_junction_id != -1 &&
71 !is_at_traffic_light &&
72 traffic_light_state != TLS::Green &&
76 traffic_light_hazard =
true;
85 std::deque<ActorId> entry_deque;
90 if (std::find(entering_vehicles.begin(), entering_vehicles.end(), ego_actor_id) == entering_vehicles.end()){
92 entering_vehicles.push_back(ego_actor_id);
103 cc::Timestamp timestamp) {
105 bool traffic_light_hazard =
false;
114 traffic_light_hazard =
true;
117 else if (entering_vehicles.front() == ego_actor_id) {
119 if (timestamp.elapsed_seconds - entry_elapsed_seconds < MINIMUM_STOP_TIME) {
121 traffic_light_hazard =
true;
125 traffic_light_hazard =
true;
127 return traffic_light_hazard;
133 const auto front_point = waypoint_buffer.front();
135 auto look_ahead_junction_id = look_ahead_point->GetJunctionId();
136 auto front_junction_id = front_point->GetJunctionId();
144 if (current_junction_id != -1) {
146 if (current_junction_id == look_ahead_junction_id) {
147 return look_ahead_junction_id;
149 if (look_ahead_junction_id != -1) {
151 return look_ahead_junction_id;
153 if (current_junction_id == front_junction_id) {
155 return front_junction_id;
163 return look_ahead_junction_id;
172 auto ent_index = std::find(entering_vehicles.begin(), entering_vehicles.end(), actor_id);
173 if (ent_index != entering_vehicles.end()) {
174 entering_vehicles.erase(ent_index);
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
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
carla::rpc::TrafficLightState TLS
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.