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;
39 const Junction junction = look_ahead_point->GetWaypoint()->GetJunction();
47 if (is_at_traffic_light &&
49 traffic_light_state != TLS::Off &&
52 traffic_light_hazard =
true;
58 if (!look_ahead_point->CheckJunction()) {
63 auto junction_id = junction->GetId();
66 if (std::find(exiting_vehicles.begin(), exiting_vehicles.end(), ego_actor_id) != exiting_vehicles.end()) {
68 traffic_light_hazard =
false;
77 else if (look_ahead_point->CheckJunction() &&
78 !is_at_traffic_light &&
83 traffic_light_hazard =
true;
91 auto junction_id = junction->GetId();
95 std::deque<ActorId> entry_deque;
96 std::deque<ActorId> exit_deque;
102 if (std::find(entering_vehicles.begin(), entering_vehicles.end(), ego_actor_id) == entering_vehicles.end()){
104 entering_vehicles.push_back(ego_actor_id);
117 bool traffic_light_hazard =
false;
118 auto junction_id = junction->GetId();
127 traffic_light_hazard =
true;
130 else if (entering_vehicles.front() == ego_actor_id) {
134 traffic_light_hazard =
true;
138 cg::Transform actor_transform = waypoint_buffer.front()->GetTransform();
144 entering_vehicles.pop_front();
152 traffic_light_hazard =
true;
154 return traffic_light_hazard;
162 auto ent_index = std::find(entering_vehicles.begin(), entering_vehicles.end(), actor_id);
163 if (ent_index != entering_vehicles.end()) {
164 entering_vehicles.erase(ent_index);
168 auto ext_index = std::find(exiting_vehicles.begin(), exiting_vehicles.end(), actor_id);
169 if (ext_index != exiting_vehicles.end()) {
170 exiting_vehicles.erase(ext_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
void AddActorToNonSignalisedJunction(const ActorId ego_actor_id, const Junction junction)
Initialized the vehicle to the non-signalized junction maps.
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
std::unordered_map< JunctionID, std::deque< ActorId > > exiting_vehicles_map
Map containing the vehicles exiting a specific junction.
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)
static auto Dot(const Vector3D &a, const Vector3D &b)
std::shared_ptr< SimpleWaypoint > SimpleWaypointPtr
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.
bool HandleNonSignalisedJunction(const ActorId ego_actor_id, const Junction junction, const Buffer &waypoint_buffer, cc::Timestamp timestamp)
This controls all vehicle's interactions at non signalized junctions.
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.
static const float JUNCTION_LOOK_AHEAD
carla::SharedPtr< carla::client::Junction > Junction