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