CARLA
ALSM.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include <memory>
5 
8 #include "carla/client/World.h"
9 #include "carla/Memory.h"
10 
22 
23 namespace carla {
24 namespace traffic_manager {
25 
26 using namespace constants::HybridMode;
27 using namespace constants::VehicleRemoval;
28 
29 namespace chr = std::chrono;
30 namespace cg = carla::geom;
31 namespace cc = carla::client;
32 
34 using ActorMap = std::unordered_map<ActorId, ActorPtr>;
35 using IdleTimeMap = std::unordered_map<ActorId, double>;
36 using LocalMapPtr = std::shared_ptr<InMemoryMap>;
37 
38 /// ALSM: Agent Lifecycle and State Managerment
39 /// This class has functionality to update the local cache of kinematic states
40 /// and manage memory and cleanup for varying number of vehicles in the simulation.
41 class ALSM {
42 
43 private:
45  // Structure containing vehicles in the simulator not registered with the traffic manager.
48  // Structure keeping track of duration of vehicles stuck in a location.
50  // Structure containing vehicles with attribute role_name with value hero.
53  // Array of vehicles marked by stages for removal.
54  std::vector<ActorId>& marked_for_removal;
56  const cc::World &world;
64  // Time elapsed since last vehicle destruction due to being idle for too long.
65  double elapsed_last_actor_destruction {0.0};
67  std::unordered_map<ActorId, bool> has_physics_enabled;
68 
69  // Updates the duration for which a registered vehicle is stuck at a location.
70  void UpdateIdleTime(std::pair<ActorId, double>& max_idle_time, const ActorId& actor_id);
71 
72  // Method to determine if a vehicle is stuck at a place for too long.
73  bool IsVehicleStuck(const ActorId& actor_id);
74 
75  // Method to identify actors newly spawned in the simulation since last tick.
76  void IdentifyNewActors(const ActorList &actor_list);
77 
78  using DestroyeddActors = std::pair<ActorIdSet, ActorIdSet>;
79  // Method to identify actors deleted in the last frame.
80  // Arrays of registered and unregistered actors are returned separately.
81  DestroyeddActors IdentifyDestroyedActors(const ActorList &actor_list);
82 
83  using IdleInfo = std::pair<ActorId, double>;
84  void UpdateRegisteredActorsData(const bool hybrid_physics_mode, IdleInfo &max_idle_time);
85 
86  void UpdateData(const bool hybrid_physics_mode, const Actor &vehicle,
87  const bool hero_actor_present, const float physics_radius_square);
88 
89  void UpdateUnregisteredActorsData();
90 
91 public:
92  ALSM(AtomicActorSet &registered_vehicles,
93  BufferMap &buffer_map,
94  TrackTraffic &track_traffic,
95  std::vector<ActorId>& marked_for_removal,
96  const Parameters &parameters,
97  const cc::World &world,
98  const LocalMapPtr &local_map,
99  SimulationState &simulation_state,
100  LocalizationStage &localization_stage,
101  CollisionStage &collision_stage,
102  TrafficLightStage &traffic_light_stage,
103  MotionPlanStage &motion_plan_stage,
104  VehicleLightStage &vehicle_light_stage);
105 
106  void Update();
107 
108  // Removes an actor from traffic manager and performs clean up of associated data
109  // from various stages tracking the said vehicle.
110  void RemoveActor(const ActorId actor_id, const bool registered_actor);
111 
112  void Reset();
113 };
114 
115 } // namespace traffic_manager
116 } // namespace carla
std::pair< ActorId, double > IdleInfo
Definition: ALSM.h:83
MotionPlanStage & motion_plan_stage
Definition: ALSM.h:62
CollisionStage & collision_stage
Definition: ALSM.h:60
std::unordered_map< ActorId, double > IdleTimeMap
Definition: ALSM.h:35
std::pair< ActorIdSet, ActorIdSet > DestroyeddActors
Definition: ALSM.h:78
std::vector< ActorId > & marked_for_removal
Definition: ALSM.h:54
boost::shared_ptr< T > SharedPtr
Use this SharedPtr (boost::shared_ptr) to keep compatibility with boost::python, but it would be nice...
Definition: Memory.h:20
std::shared_ptr< InMemoryMap > LocalMapPtr
Definition: ALSM.h:36
This class holds the state of all the vehicles in the simlation.
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
std::unordered_map< carla::ActorId, Buffer > BufferMap
ALSM: Agent Lifecycle and State Managerment This class has functionality to update the local cache of...
Definition: ALSM.h:41
IdleTimeMap idle_time
Definition: ALSM.h:49
VehicleLightStage & vehicle_light_stage
Definition: ALSM.h:63
LocalizationStage & localization_stage
Definition: ALSM.h:59
std::unordered_map< ActorId, bool > has_physics_enabled
Definition: ALSM.h:67
const Parameters & parameters
Definition: ALSM.h:55
carla::SharedPtr< cc::Actor > Actor
carla::ActorId ActorId
This class has functionality for responding to traffic lights and managing entry into non-signalized ...
BufferMap & buffer_map
Definition: ALSM.h:47
AtomicActorSet & registered_vehicles
Definition: ALSM.h:44
const cc::World & world
Definition: ALSM.h:56
TrafficLightStage & traffic_light_stage
Definition: ALSM.h:61
SimulationState & simulation_state
Definition: ALSM.h:58
const LocalMapPtr & local_map
Definition: ALSM.h:57
std::unordered_map< ActorId, ActorPtr > ActorMap
Definition: ALSM.h:34
This class has functionality to maintain a horizon of waypoints ahead of the vehicle for it to follow...
ActorMap unregistered_actors
Definition: ALSM.h:46
TrackTraffic & track_traffic
Definition: ALSM.h:52
carla::SharedPtr< cc::ActorList > ActorList
Definition: ALSM.h:33
This class has functionality for turning on/off the vehicle lights according to the current vehicle s...
This class has functionality to detect potential collision with a nearby actor.
cc::Timestamp current_timestamp
Definition: ALSM.h:66