Implementation:CARLA simulator Carla WalkerAIController Class
| Knowledge Sources | |
|---|---|
| Domains | Client Library, Pedestrian AI, Navigation |
| Last Updated | 2026-02-15 05:00 GMT |
Overview
WalkerAIController is a client-side class that provides AI-driven navigation for pedestrian (walker) actors using the Recast & Detour navigation mesh system.
Description
The WalkerAIController class in the carla::client namespace extends Actor and manages the AI behavior of walker actors. It integrates with CARLA's navigation system for pathfinding on sidewalks and crosswalks.
Construction
The constructor takes an ActorInitializer and delegates to the Actor base class.
Start / Stop Lifecycle
- Start() -- Registers the AI controller with the episode and initializes navigation:
- Retrieves the parent walker actor.
- Adds the walker to the Recast & Detour navigation mesh at the walker's current location via
nav->AddWalker(walker_id, walker_location). - Disables physics simulation on the walker (
SetActorSimulatePhysics(false)) since the navigation system drives movement. - Disables collisions on the walker (
SetActorCollisions(false)) to allow navigation-driven movement.
- Stop() -- Unregisters the AI controller and removes the walker from the navigation mesh via
nav->RemoveWalker(walker_id).
Navigation Commands
- GetRandomLocation() -- Returns a random navigable location on the sidewalk network as
std::optional<geom::Location>. Returns an empty optional if navigation is not available.
- GoToLocation(destination) -- Commands the walker to navigate to the specified destination. Delegates to
nav->SetWalkerTarget(walker_id, destination). Logs warnings if the request fails or if the parent walker does not exist.
- SetMaxSpeed(max_speed) -- Sets the maximum walking speed for this walker via
nav->SetWalkerMaxSpeed(walker_id, max_speed). Logs warnings on failure.
All navigation methods safely check for null navigation system and null parent walker references before proceeding.
Usage
Spawn a walker actor, then spawn a WalkerAIController attached to it. Call Start() to begin AI-driven navigation, GoToLocation() to set destinations, and Stop() when finished.
Code Reference
Source Location
- Repository: CARLA
- Files:
LibCarla/source/carla/client/WalkerAIController.h(34 lines)LibCarla/source/carla/client/WalkerAIController.cpp(84 lines)
Signature
namespace carla {
namespace client {
class WalkerAIController : public Actor {
public:
explicit WalkerAIController(ActorInitializer init);
void Start();
void Stop();
std::optional<geom::Location> GetRandomLocation();
void GoToLocation(const carla::geom::Location &destination);
void SetMaxSpeed(const float max_speed);
};
} // namespace client
} // namespace carla
Import
#include "carla/client/WalkerAIController.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| init | ActorInitializer | Yes | Actor initialization data |
| destination | carla::geom::Location | Yes (for GoToLocation) | Target navigation destination |
| max_speed | float | Yes (for SetMaxSpeed) | Maximum walking speed in m/s |
Outputs
| Name | Type | Description |
|---|---|---|
| random_location | std::optional<geom::Location> | A random navigable location, or empty if unavailable |
Usage Examples
// Spawn a walker
auto walker_bp = blueprint_library->Find("walker.pedestrian.0001");
auto walker = world.SpawnActor(*walker_bp, spawn_point);
// Spawn the AI controller attached to the walker
auto controller_bp = blueprint_library->Find("controller.ai.walker");
auto controller_actor = world.SpawnActor(*controller_bp, carla::geom::Transform(), walker);
auto controller = std::static_pointer_cast<carla::client::WalkerAIController>(controller_actor);
// Start the AI controller
controller->Start();
// Navigate to a random location
auto random_loc = controller->GetRandomLocation();
if (random_loc.has_value()) {
controller->GoToLocation(*random_loc);
}
// Set walking speed
controller->SetMaxSpeed(1.4f); // Normal walking speed
// Stop when done
controller->Stop();
Related Pages
- Environment:CARLA_simulator_Carla_Simulation_Runtime
- CARLA_simulator_Carla_Actor_Class - Base Actor class
- CARLA_simulator_Carla_Vehicle_Class - Vehicle actors that share the road with walkers