6#include "boost/pointer_cast.hpp"
28 const cc::World &
world,
56 std::set<ActorId> world_vehicle_ids;
57 std::set<ActorId> world_pedestrian_ids;
58 std::vector<ActorId> unregistered_list_to_be_deleted;
66 const ActorIdSet &destroyed_registered = destroyed_actors.first;
67 for (
const auto &deletion_id: destroyed_registered) {
71 const ActorIdSet &destroyed_unregistered = destroyed_actors.second;
72 for (
auto deletion_id : destroyed_unregistered) {
80 if (destroyed_unregistered.find(hero_actor_info.first) != destroyed_unregistered.end()) {
81 hero_actors_to_delete.insert(hero_actor_info.first);
83 if (destroyed_registered.find(hero_actor_info.first) != destroyed_registered.end()) {
84 hero_actors_to_delete.insert(hero_actor_info.first);
88 for (
auto &deletion_id: hero_actors_to_delete) {
123 for (
auto iter = actor_list->begin(); iter != actor_list->end(); ++iter) {
125 ActorId actor_id = actor->GetId();
127 if (actor->GetTypeId().front() ==
'v') {
129 for (
auto&& attribute: actor->GetAttributes()) {
130 if (attribute.GetId() ==
"role_name" && attribute.GetValue() ==
"hero") {
147 ActorIdSet &deleted_registered = destroyed_actors.first;
148 ActorIdSet &deleted_unregistered = destroyed_actors.second;
152 for (
auto iter = actor_list->begin(); iter != actor_list->end(); ++iter) {
153 current_actors.insert((*iter)->GetId());
158 for (
const ActorId &actor_id : registered_ids) {
159 if (current_actors.find(actor_id) == current_actors.end()) {
160 deleted_registered.insert(actor_id);
166 const ActorId &actor_id = actor_info.first;
167 if (current_actors.find(actor_id) == current_actors.end()
169 deleted_unregistered.insert(actor_id);
173 return destroyed_actors;
179 bool hero_actor_present =
hero_actors.size() != 0u;
181 float physics_radius_square =
SQUARE(physics_radius);
183 std::vector<ActorId> vanished_heroes;
184 std::vector<ActorId> vanished_vehicles;
188 UpdateData(hybrid_physics_mode, hero_actor_info.second, hero_actor_present, physics_radius_square);
189 }
catch (
const std::exception &e) {
190 log_debug(
"Traffic Manager: dropping hero vehicle", hero_actor_info.first,
":", e.what());
191 vanished_heroes.push_back(hero_actor_info.first);
195 for (
const Actor &vehicle : vehicle_list) {
196 ActorId actor_id = vehicle->GetId();
199 UpdateData(hybrid_physics_mode, vehicle, hero_actor_present, physics_radius_square);
200 }
catch (
const std::exception &e) {
201 log_debug(
"Traffic Manager: dropping vehicle", actor_id,
":", e.what());
202 vanished_vehicles.push_back(actor_id);
208 for (
const ActorId actor_id : vanished_heroes) {
211 for (
const ActorId actor_id : vanished_vehicles) {
217 const bool hero_actor_present,
const float physics_radius_square) {
219 ActorId actor_id = vehicle->GetId();
232 bool in_range_of_hero_actor =
false;
233 if (hero_actor_present && hybrid_physics_mode) {
235 const ActorId &hero_actor_id = hero_actor_info.first;
239 in_range_of_hero_actor =
true;
246 bool enable_physics = hybrid_physics_mode ? in_range_of_hero_actor :
true;
249 vehicle->SetSimulatePhysics(enable_physics);
251 if (enable_physics ==
true && state_entry_present) {
263 cg::Vector3D displacement = (previous_end_location - previous_location);
264 vehicle_velocity = displacement * INV_HYBRID_DT;
268 auto vehicle_ptr = std::static_pointer_cast<cc::Vehicle>(vehicle);
269 KinematicState kinematic_state{vehicle_location, vehicle_rotation,
270 vehicle_velocity, vehicle_ptr->GetSpeedLimit(),
274 TrafficLightState tl_state = {vehicle_ptr->GetTrafficLightState(), vehicle_ptr->IsAtTrafficLight()};
277 if (state_entry_present) {
282 cg::Vector3D dimensions = vehicle_ptr->GetBoundingBox().extent;
289 const auto physics_control = vehicle_ptr->GetPhysicsControl();
290 float max_steer_angle = 0.0f;
291 for (
const auto &wheel : physics_control.wheels) {
292 max_steer_angle = std::max(max_steer_angle, wheel.max_steer_angle);
294 if (max_steer_angle > 1.0f) {
297 }
catch (
const std::exception &) {}
307 const ActorId actor_id = actor_info.first;
308 const ActorPtr actor_ptr = actor_info.second;
309 const std::string type_id = actor_ptr->GetTypeId();
311 const cg::Transform actor_transform = actor_ptr->GetTransform();
314 const cg::Vector3D actor_velocity = actor_ptr->GetVelocity();
320 std::vector<SimpleWaypointPtr> nearest_waypoints;
323 if (type_id.front() ==
'v') {
324 auto vehicle_ptr = std::static_pointer_cast<cc::Vehicle>(actor_ptr);
325 kinematic_state.
speed_limit = vehicle_ptr->GetSpeedLimit();
327 tl_state = {vehicle_ptr->GetTrafficLightState(), vehicle_ptr->IsAtTrafficLight()};
329 if (state_entry_not_present) {
330 dimensions = vehicle_ptr->GetBoundingBox().extent;
341 cg::Vector3D extent = vehicle_ptr->GetBoundingBox().extent;
342 cg::Vector3D heading_vector = vehicle_ptr->GetTransform().GetForwardVector();
343 std::vector<cg::Location> corners = {actor_location +
cg::Location(extent.
x * heading_vector),
348 if (nearest_waypoint !=
nullptr) {
349 nearest_waypoints.push_back(nearest_waypoint);
353 else if (type_id.front() ==
'w') {
354 auto walker_ptr = std::static_pointer_cast<cc::Walker>(actor_ptr);
356 if (state_entry_not_present) {
357 dimensions = walker_ptr->GetBoundingBox().extent;
368 if (nearest_waypoint !=
nullptr) {
369 nearest_waypoints.push_back(nearest_waypoint);
379 double &idle_duration =
idle_time.at(actor_id);
385 if (max_idle_time.first == 0u || max_idle_time.second > idle_duration) {
386 max_idle_time = std::make_pair(actor_id, idle_duration);
395 if ((delta_idle_time >= RED_TL_BLOCKED_TIME_THRESHOLD)
396 || (delta_idle_time >= BLOCKED_TIME_THRESHOLD && tl_state.
tl_state != TLS::Red))
405 const ActorId actor_id = actor->GetId();
406 for (
auto &&attribute : actor->GetAttributes()) {
407 if (attribute.GetId() !=
"base_type") {
410 std::string value = attribute.GetValue();
415 [](
unsigned char c) { return std::tolower(c); });
416 const std::string_view value_view{value};
417 const auto match = std::find(
431 if (registered_actor) {
#define SQUARE(a)
This file contains various constants used in traffic manager arranged into sensible namespaces for re...
static constexpr auto DistanceSquared(const Vector3D &a, const Vector3D &b)
Euler angles of a rotation in CARLA's / Unreal's left-handed frame: x forward, y right,...
void AddActor(const Actor actor)
void IdentifyNewActors(const ActorList &actor_list)
void RemoveActor(const ActorId actor_id, const bool registered_actor)
AtomicActorSet & registered_vehicles
static constexpr std::array< std::string_view, 2 > large_vehicle_types
std::unordered_map< ActorId, std::pair< float, bool > > & large_vehicles
LocalizationStage & localization_stage
const LocalMapPtr & local_map
std::unordered_map< ActorId, bool > has_physics_enabled
VehicleLightStage & vehicle_light_stage
std::pair< ActorId, double > IdleInfo
bool IsVehicleStuck(const ActorId &actor_id)
MotionPlanStage & motion_plan_stage
std::pair< ActorIdSet, ActorIdSet > DestroyeddActors
CollisionStage & collision_stage
void UpdateData(const bool hybrid_physics_mode, const Actor &vehicle, const bool hero_actor_present, const float physics_radius_square)
void UpdateUnregisteredActorsData()
ActorMap unregistered_actors
cc::Timestamp current_timestamp
const Parameters & parameters
std::vector< ActorId > & marked_for_removal
SimulationState & simulation_state
void UpdateRegisteredActorsData(const bool hybrid_physics_mode, IdleInfo &max_idle_time)
ALSM(AtomicActorSet ®istered_vehicles, BufferMap &buffer_map, TrackTraffic &track_traffic, std::vector< ActorId > &marked_for_removal, const Parameters ¶meters, const cc::World &world, const LocalMapPtr &local_map, SimulationState &simulation_state, std::unordered_map< ActorId, std::pair< float, bool > > &large_vehicles, LocalizationStage &localization_stage, CollisionStage &collision_stage, TrafficLightStage &traffic_light_stage, MotionPlanStage &motion_plan_stage, VehicleLightStage &vehicle_light_stage)
TrafficLightStage & traffic_light_stage
void UpdateIdleTime(std::pair< ActorId, double > &max_idle_time, const ActorId &actor_id)
TrackTraffic & track_traffic
DestroyeddActors IdentifyDestroyedActors(const ActorList &actor_list)
double elapsed_last_actor_destruction
void Destroy(ActorId actor_id)
void Remove(std::vector< ActorId > actor_id_list)
std::vector< ActorId > GetIDList()
std::vector< ActorPtr > GetList()
bool Contains(ActorId id)
This class has functionality to detect potential collision with a nearby actor.
void RemoveActor(const ActorId actor_id) override
This class has functionality to maintain a horizon of waypoints ahead of the vehicle for it to follow...
void RemoveActor(const ActorId actor_id) override
void RemoveActor(const ActorId actor_id)
bool GetOSMMode() const
Method to get Open Street Map mode.
float GetHybridPhysicsRadius() const
Method to retrieve hybrid physics radius.
bool GetHybridPhysicsMode() const
Method to retrieve hybrid physics mode.
This class holds the state of all the vehicles in the simlation.
bool ContainsActor(ActorId actor_id) const
cg::Location GetLocation(const ActorId actor_id) const
cg::Location GetHybridEndLocation(const ActorId actor_id) const
void UpdateKinematicState(ActorId actor_id, KinematicState state)
void AddActor(ActorId actor_id, KinematicState kinematic_state, StaticAttributes attributes, TrafficLightState tl_state)
void UpdateTrafficLightState(ActorId actor_id, TrafficLightState state)
cg::Vector3D GetVelocity(const ActorId actor_id) const
bool IsPhysicsEnabled(const ActorId actor_id) const
void RemoveActor(ActorId actor_id)
TrafficLightState GetTLS(const ActorId actor_id) const
void UpdateUnregisteredGridPosition(const ActorId actor_id, const std::vector< SimpleWaypointPtr > waypoints)
void DeleteActor(ActorId actor_id)
Method to delete actor data from tracking.
This class has functionality for responding to traffic lights and managing entry into non-signalized ...
void RemoveActor(const ActorId actor_id) override
This class has functionality for turning on/off the vehicle lights according to the current vehicle s...
void RemoveActor(const ActorId actor_id) override
carla::SharedPtr< cc::Actor > ActorPtr
carla::SharedPtr< cc::Actor > Actor
carla::SharedPtr< cc::ActorList > ActorList
std::shared_ptr< InMemoryMap > LocalMapPtr
std::shared_ptr< SimpleWaypoint > SimpleWaypointPtr
std::unordered_set< ActorId > ActorIdSet
std::unordered_map< carla::ActorId, Buffer > BufferMap
This file contains definitions of common data structures used in traffic manager.
constexpr float SquaredLength() const