Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:CARLA simulator Carla WalkerManager

From Leeroopedia
Revision as of 12:15, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/CARLA_simulator_Carla_WalkerManager.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Pedestrian Simulation, AI, Traffic
Last Updated 2026-02-15 05:00 GMT

Overview

WalkerManager manages high-level pedestrian route planning and event-driven behavior for walkers in the CARLA navigation system, including traffic light awareness and crosswalk handling.

Description

The WalkerManager class works as a companion to the Navigation class, handling the higher-level route logic that sits above Detour's low-level crowd pathfinding. While Navigation manages the crowd simulation and raw pathfinding, WalkerManager is responsible for:

  • Route Management: Each walker is tracked via a WalkerInfo struct containing the walker's origin, destination, current route index, state, and a vector of WalkerRoutePoint entries. Each route point pairs a WalkerEvent with a carla::geom::Location and an area type.
  • State Machine: Walkers follow a four-state lifecycle defined by the WalkerState enum:
    • WALKER_IDLE - The walker has no active navigation target
    • WALKER_WALKING - The walker is moving toward the next route point; distance is checked each tick and transitions to WALKER_IN_EVENT when within range
    • WALKER_IN_EVENT - The walker is executing an event (e.g., waiting at a traffic light or crossing a road); the ExecuteEvent() method returns Continue, End, or TimeOut
    • WALKER_STOP - The walker has been stopped and will return to idle
  • Traffic Light Integration: GetAllTrafficLightWaypoints() queries the simulator for all traffic lights and caches their waypoint locations. GetTrafficLightAffecting() returns the traffic light affecting a given position. During crosswalk events, walkers check traffic light state and wait for green.
  • Route Construction: SetWalkerRoute() obtains a path from Navigation::GetAgentRoute(), then constructs a sequence of WalkerRoutePoint entries that include events at area transitions (e.g., a WalkerEventStopAndCheck when entering a crosswalk from a sidewalk).
  • Update Loop: Update(double delta) iterates over all registered walkers, advances their state machines, executes events, and requests new routes when timeouts occur.

Usage

WalkerManager is used internally by the Navigation class and should not typically be accessed directly. The Navigation class creates and manages a WalkerManager instance, calling SetNav() to establish the bidirectional reference. Route-level walker control (SetWalkerTarget) in Navigation delegates to WalkerManager::SetWalkerRoute() for event-aware pathfinding.

Code Reference

Source Location

  • Repository: CARLA
  • File: LibCarla/source/carla/nav/WalkerManager.cpp
  • Lines: 1-328

Signature

namespace carla {
namespace nav {

  class WalkerManager : private NonCopyable {
  public:
    WalkerManager();
    ~WalkerManager();

    void SetNav(Navigation *nav);
    void SetSimulator(std::weak_ptr<carla::client::detail::Simulator> simulator);
    bool AddWalker(ActorId id);
    bool RemoveWalker(ActorId id);
    bool Update(double delta);
    bool SetWalkerRoute(ActorId id);
    bool SetWalkerRoute(ActorId id, carla::geom::Location to);
    bool SetWalkerNextPoint(ActorId id);
    bool GetWalkerNextPoint(ActorId id, carla::geom::Location &location);
    bool GetWalkerCrosswalkEnd(ActorId id, carla::geom::Location &location);
    Navigation *GetNavigation();
    SharedPtr<carla::client::TrafficLight> GetTrafficLightAffecting(
        carla::geom::Location UnrealPos, float max_distance = -1.0f);

  private:
    void GetAllTrafficLightWaypoints();
    EventResult ExecuteEvent(ActorId id, WalkerInfo &info, double delta);

    std::unordered_map<ActorId, WalkerInfo> _walkers;
    std::vector<std::pair<SharedPtr<carla::client::TrafficLight>,
                          carla::geom::Location>> _traffic_lights;
    Navigation *_nav { nullptr };
    std::weak_ptr<carla::client::detail::Simulator> _simulator;
  };

} // namespace nav
} // namespace carla

Import

#include "carla/nav/WalkerManager.h"

I/O Contract

Inputs

Name Type Required Description
id ActorId Yes Unique actor identifier for the walker
to carla::geom::Location No Target destination for route computation; if omitted, a random location is chosen
delta double Yes Time elapsed since last update in seconds, used for event timing
nav Navigation * Yes Pointer to the parent Navigation module for pathfinding access
simulator std::weak_ptr<Simulator> Yes Weak reference to the simulator for traffic light and world queries

Outputs

Name Type Description
location carla::geom::Location The next target point or crosswalk end location for a walker
return value bool Success or failure of the operation
TrafficLight SharedPtr<carla::client::TrafficLight> The traffic light affecting a given position, or nullptr

Usage Examples

Internal Usage within Navigation

// WalkerManager is typically used internally by Navigation
// In Navigation constructor:
Navigation::Navigation() {
    _walker_manager.SetNav(this);
}

// When setting a walker target with events:
void Navigation::SetWalkerTarget(ActorId id, carla::geom::Location to) {
    _walker_manager.SetWalkerRoute(id, to);
}

Walker State Machine Flow

// The Update loop processes each walker's state
// WALKER_IDLE -> (SetWalkerRoute) -> WALKER_WALKING
// WALKER_WALKING -> (reach target point) -> WALKER_IN_EVENT
// WALKER_IN_EVENT -> (event ends) -> SetWalkerNextPoint -> WALKER_WALKING
// WALKER_IN_EVENT -> (timeout) -> SetWalkerRoute (new route)

Related Pages

Page Connections

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