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 
21 
22 namespace carla {
23 namespace traffic_manager {
24 
25 using namespace constants::HybridMode;
26 using namespace constants::VehicleRemoval;
27 
28 namespace chr = std::chrono;
29 namespace cg = carla::geom;
30 namespace cc = carla::client;
31 
33 using ActorMap = std::unordered_map<ActorId, ActorPtr>;
34 using IdleTimeMap = std::unordered_map<ActorId, double>;
35 using LocalMapPtr = std::shared_ptr<InMemoryMap>;
36 
37 /// ALSM: Agent Lifecycle and State Managerment
38 /// This class has functionality to update the local cache of kinematic states
39 /// and manage memory and cleanup for varying number of vehicles in the simulation.
40 class ALSM {
41 
42 private:
44  // Structure containing vehicles in the simulator not registered with the traffic manager.
47  // Structure keeping track of duration of vehicles stuck in a location.
49  // Structure containing vehicles with attribute role_name with value hero.
52  // Array of vehicles marked by stages for removal.
53  std::vector<ActorId>& marked_for_removal;
55  const cc::World &world;
62  // Time elapsed since last vehicle destruction due to being idle for too long.
63  double elapsed_last_actor_destruction {0.0};
65  // Random devices.
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,
87  ALSM::IdleInfo &max_idle_time, const Actor &vehicle,
88  const bool hero_actor_present, const float physics_radius_square);
89 
90  void UpdateUnregisteredActorsData();
91 
92 public:
93  ALSM(AtomicActorSet &registered_vehicles,
94  BufferMap &buffer_map,
95  TrackTraffic &track_traffic,
96  std::vector<ActorId>& marked_for_removal,
97  const Parameters &parameters,
98  const cc::World &world,
99  const LocalMapPtr &local_map,
100  SimulationState &simulation_state,
101  LocalizationStage &localization_stage,
102  CollisionStage &collision_stage,
103  TrafficLightStage &traffic_light_stage,
104  MotionPlanStage &motion_plan_stage,
105  RandomGeneratorMap &random_devices);
106 
107  void Update();
108 
109  // Removes an actor from traffic manager and performs clean up of associated data
110  // from various stages tracking the said vehicle.
111  void RemoveActor(const ActorId actor_id, const bool registered_actor);
112 
113  void Reset();
114 };
115 
116 } // namespace traffic_manager
117 } // namespace carla
std::pair< ActorId, double > IdleInfo
Definition: ALSM.h:83
MotionPlanStage & motion_plan_stage
Definition: ALSM.h:61
CollisionStage & collision_stage
Definition: ALSM.h:59
std::unordered_map< ActorId, double > IdleTimeMap
Definition: ALSM.h:34
std::pair< ActorIdSet, ActorIdSet > DestroyeddActors
Definition: ALSM.h:78
std::vector< ActorId > & marked_for_removal
Definition: ALSM.h:53
RandomGeneratorMap & random_devices
Definition: ALSM.h:66
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:35
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::rpc::ActorId, RandomGenerator > RandomGeneratorMap
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:40
IdleTimeMap idle_time
Definition: ALSM.h:48
LocalizationStage & localization_stage
Definition: ALSM.h:58
std::unordered_map< ActorId, bool > has_physics_enabled
Definition: ALSM.h:67
const Parameters & parameters
Definition: ALSM.h:54
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:46
AtomicActorSet & registered_vehicles
Definition: ALSM.h:43
const cc::World & world
Definition: ALSM.h:55
TrafficLightStage & traffic_light_stage
Definition: ALSM.h:60
SimulationState & simulation_state
Definition: ALSM.h:57
const LocalMapPtr & local_map
Definition: ALSM.h:56
std::unordered_map< ActorId, ActorPtr > ActorMap
Definition: ALSM.h:33
This class has functionality to maintain a horizon of waypoints ahead of the vehicle for it to follow...
ActorMap unregistered_actors
Definition: ALSM.h:45
TrackTraffic & track_traffic
Definition: ALSM.h:51
carla::SharedPtr< cc::ActorList > ActorList
Definition: ALSM.h:32
This class has functionality to detect potential collision with a nearby actor.
cc::Timestamp current_timestamp
Definition: ALSM.h:64