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 WalkerAIController Start

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

Overview

Concrete tool for activating pedestrian AI controllers and configuring their navigation behavior, provided by the CARLA simulator.

Description

The WalkerAIController class provides three key methods for controlling autonomous pedestrian behavior:

  • start() -- Initializes the AI controller and registers the attached walker as a crowd agent in the Detour navigation system. This must be called before any navigation commands.
  • go_to_location(destination) -- Commands the walker to navigate along the NavMesh from its current position to the specified destination. The pathfinding is computed automatically using Detour.
  • set_max_speed(speed) -- Sets the maximum walking speed in meters per second. The walker will not exceed this speed regardless of the path or crowd conditions.

These methods are called on a WalkerAIController actor that has been spawned and attached as a child of a walker actor. The controller must be started before setting destinations or speeds.

Usage

Use these methods after spawning walker actors and their associated AI controllers. The typical sequence is: spawn walker, spawn controller attached to walker, start controller, set destination, set speed.

Code Reference

Source Location

  • Repository: CARLA
  • File: LibCarla/source/carla/client/WalkerAIController.cpp
  • Lines: L18-81
  • Python Binding: PythonAPI/carla/src/Actor.cpp, L226-232

Signature

WalkerAIController.start() -> None
WalkerAIController.go_to_location(destination: carla.Location) -> None
WalkerAIController.set_max_speed(speed: float) -> None
WalkerAIController.stop() -> None

Import

import carla

I/O Contract

Inputs

Name Type Required Description
destination (go_to_location) carla.Location Yes The target 3D world position the walker should navigate to. Should be a point on or near the NavMesh surface. Typically obtained from World.get_random_location_from_navigation().
speed (set_max_speed) float Yes Maximum walking speed in meters per second. Typical values: 1.0 (slow walk), 1.4 (normal walk), 2.0 (brisk walk), 3.0 (jogging).

Outputs

Name Type Description
return (start) None No return value. Registers the walker with the crowd simulation system.
return (go_to_location) None No return value. Initiates asynchronous pathfinding and walking.
return (set_max_speed) None No return value. Speed change takes effect on the next simulation tick.

Usage Examples

Basic Example

import carla
import random

client = carla.Client('localhost', 2000)
client.set_timeout(10.0)
world = client.get_world()

# Spawn a pedestrian walker
walker_bp = random.choice(world.get_blueprint_library().filter('walker.pedestrian.*'))
spawn_location = world.get_random_location_from_navigation()
spawn_transform = carla.Transform(spawn_location)
walker = world.spawn_actor(walker_bp, spawn_transform)

# Spawn an AI controller attached to the walker
controller_bp = world.get_blueprint_library().find('controller.ai.walker')
controller = world.spawn_actor(controller_bp, carla.Transform(), walker)

# Activate the controller and set a destination
controller.start()
destination = world.get_random_location_from_navigation()
controller.go_to_location(destination)
controller.set_max_speed(1.4)  # Normal walking speed

Batch Spawning Walkers with AI Controllers

import carla
import random

client = carla.Client('localhost', 2000)
client.set_timeout(10.0)
world = client.get_world()

walker_blueprints = world.get_blueprint_library().filter('walker.pedestrian.*')
controller_bp = world.get_blueprint_library().find('controller.ai.walker')
number_of_walkers = 50
percentage_running = 0.2  # 20% of walkers will run

# Step 1: Batch-spawn walker bodies
walker_spawn_points = []
for _ in range(number_of_walkers):
    loc = world.get_random_location_from_navigation()
    if loc is not None:
        walker_spawn_points.append(carla.Transform(loc))

batch = []
for spawn_point in walker_spawn_points:
    bp = random.choice(walker_blueprints)
    if bp.has_attribute('is_invincible'):
        bp.set_attribute('is_invincible', 'false')
    batch.append(carla.command.SpawnActor(bp, spawn_point))

results = client.apply_batch_sync(batch, do_tick=True)
walker_ids = [r.actor_id for r in results if not r.error]

# Step 2: Batch-spawn AI controllers attached to each walker
batch = []
for walker_id in walker_ids:
    batch.append(carla.command.SpawnActor(controller_bp, carla.Transform(),
                                          walker_id))

results = client.apply_batch_sync(batch, do_tick=True)
controller_ids = [r.actor_id for r in results if not r.error]

# Step 3: Start controllers and set destinations/speeds
world.tick()  # Ensure controllers are registered
controllers = world.get_actors(controller_ids)

for controller in controllers:
    controller.start()
    destination = world.get_random_location_from_navigation()
    if destination is not None:
        controller.go_to_location(destination)

    # Randomly assign walking or running speed
    if random.random() < percentage_running:
        controller.set_max_speed(3.0)   # Running
    else:
        controller.set_max_speed(1.4 + random.uniform(-0.3, 0.3))  # Walking with variation

print(f"Activated {len(controller_ids)} pedestrian AI controllers")

Pedestrian with Continuous Destination Updates

import carla
import random
import time

client = carla.Client('localhost', 2000)
client.set_timeout(10.0)
world = client.get_world()

# Spawn walker and controller (as in basic example)
walker_bp = random.choice(world.get_blueprint_library().filter('walker.pedestrian.*'))
spawn_loc = world.get_random_location_from_navigation()
walker = world.spawn_actor(walker_bp, carla.Transform(spawn_loc))

controller_bp = world.get_blueprint_library().find('controller.ai.walker')
controller = world.spawn_actor(controller_bp, carla.Transform(), walker)

controller.start()
controller.set_max_speed(1.4)

# Continuously assign new destinations when the walker reaches its goal
try:
    while True:
        destination = world.get_random_location_from_navigation()
        if destination is not None:
            controller.go_to_location(destination)
        # Wait before checking/assigning a new destination
        time.sleep(15.0)
finally:
    controller.stop()
    controller.destroy()
    walker.destroy()

Related Pages

Implements Principle

Page Connections

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