Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:CARLA simulator Carla ALSM

From Leeroopedia
Knowledge Sources
Domains Traffic_Management, Autonomous_Driving
Last Updated 2026-02-15 05:00 GMT

Overview

The ALSM (Agent Lifecycle and State Management) class is responsible for updating the local cache of kinematic states and managing the memory and cleanup for a varying number of vehicles in the CARLA traffic manager simulation.

Description

ALSM stands for Agent Lifecycle and State Management and serves as the central bookkeeping component of the Traffic Manager pipeline. It performs the following core responsibilities:

  • Actor Discovery: Scans the simulation world each tick to identify newly spawned actors (vehicles, pedestrians) that are not yet tracked, and adds them to the unregistered_actors map.
  • Actor Destruction Detection: Compares the current world actor list against previously known registered and unregistered actors to detect which actors have been destroyed, then invokes RemoveActor to clean up associated data structures across all pipeline stages.
  • Hero Vehicle Tracking: Maintains a map of actors with the role_name attribute set to "hero", used by hybrid physics mode to determine which vehicles require full physics simulation.
  • State Updates: Calls UpdateRegisteredActorsData and UpdateUnregisteredActorsData each tick to refresh kinematic state (location, rotation, velocity) and static attributes for all tracked actors in the SimulationState cache.
  • Idle Vehicle Removal: Tracks how long registered vehicles remain stuck at a single location via IdleTimeMap. If a vehicle exceeds the maximum idle threshold and is not a hero actor, ALSM destroys it to prevent traffic deadlocks.
  • OSM Mode Cleanup: When Open Street Map mode is active, processes a list of actors marked_for_removal by other pipeline stages and destroys them.

The class holds references to all pipeline stages (LocalizationStage, CollisionStage, TrafficLightStage, MotionPlanStage, VehicleLightStage) so it can propagate actor addition and removal events to each stage.

Usage

ALSM is instantiated and owned by TrafficManagerLocal. It is invoked once per simulation tick via its Update() method before the pipeline stages execute. It should not be instantiated directly by user code; it is an internal component of the Traffic Manager architecture.

Code Reference

Source Location

  • Repository: CARLA
  • File: LibCarla/source/carla/trafficmanager/ALSM.cpp
  • Header: LibCarla/source/carla/trafficmanager/ALSM.h

Signature

class ALSM {
public:
  ALSM(AtomicActorSet &registered_vehicles,
       BufferMap &buffer_map,
       TrackTraffic &track_traffic,
       std::vector<ActorId>& marked_for_removal,
       const Parameters &parameters,
       const cc::World &world,
       const LocalMapPtr &local_map,
       SimulationState &simulation_state,
       LocalizationStage &localization_stage,
       CollisionStage &collision_stage,
       TrafficLightStage &traffic_light_stage,
       MotionPlanStage &motion_plan_stage,
       VehicleLightStage &vehicle_light_stage);

  void Update();
  void RemoveActor(const ActorId actor_id, const bool registered);
};

Import

#include "carla/trafficmanager/ALSM.h"

I/O Contract

Inputs

Name Type Required Description
registered_vehicles AtomicActorSet& Yes Set of vehicles registered with the Traffic Manager
buffer_map BufferMap& Yes Waypoint buffers for all tracked vehicles
track_traffic TrackTraffic& Yes Object tracking overlapping vehicle paths
marked_for_removal std::vector<ActorId>& Yes Actors flagged by pipeline stages for destruction
parameters const Parameters& Yes Traffic Manager configuration parameters
world const cc::World& Yes CARLA world object for querying actors and snapshots
local_map const LocalMapPtr& Yes Shared pointer to the in-memory map cache
simulation_state SimulationState& Yes Mutable cache of actor kinematic and static state
localization_stage LocalizationStage& Yes Reference to the localization pipeline stage
collision_stage CollisionStage& Yes Reference to the collision avoidance pipeline stage
traffic_light_stage TrafficLightStage& Yes Reference to the traffic light response stage
motion_plan_stage MotionPlanStage& Yes Reference to the motion planning pipeline stage
vehicle_light_stage VehicleLightStage& Yes Reference to the vehicle light management stage

Outputs

Name Type Description
simulation_state SimulationState& Updated kinematic state cache for all actors (modified in place)
buffer_map BufferMap& Cleaned up waypoint buffers with destroyed actors removed
registered_vehicles AtomicActorSet& Updated set with destroyed registered actors removed

Usage Examples

// ALSM is created and used internally by TrafficManagerLocal.
// During construction of TrafficManagerLocal:
alsm(ALSM(registered_vehicles,
          buffer_map,
          track_traffic,
          marked_for_removal,
          parameters,
          world,
          local_map,
          simulation_state,
          localization_stage,
          collision_stage,
          traffic_light_stage,
          motion_plan_stage,
          vehicle_light_stage));

// Called once per tick in the TrafficManagerLocal::Run() loop:
alsm.Update();

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment