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 BasicAgent Done

From Leeroopedia
Revision as of 12:12, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/CARLA_simulator_Carla_BasicAgent_Done.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Motion Planning, Route Tracking, Autonomous Driving
Last Updated 2026-02-15 00:00 GMT

Overview

Concrete tool for checking whether the navigation agent has reached its destination provided by the CARLA simulator agents library. The BasicAgent.done() method returns a boolean indicating route completion by querying whether the local planner's internal waypoint queue has been fully consumed.

Description

The done() method is a thin delegation to the local planner:

  1. Calls self._local_planner.done()
  2. The local planner checks whether its internal waypoint deque is empty
  3. Returns True if the queue is empty (all waypoints consumed, destination reached)
  4. Returns False if waypoints remain in the queue

This method is designed to be called at every iteration of the navigation loop to determine when to stop issuing control commands or when to set a new destination.

Usage

Use done() as the termination condition in your autonomous driving loop. It is the standard way to detect arrival at the destination set via set_destination().

Code Reference

Source Location

  • Repository: CARLA
  • File: PythonAPI/carla/agents/navigation/basic_agent.py
  • Lines: L216-218

Signature

def done(self):
    """Check whether the agent has reached its destination."""
    return self._local_planner.done()

Import

from agents.navigation.basic_agent import BasicAgent
# Method accessed as agent.done()

I/O Contract

Inputs

Name Type Required Description
(none) -- -- This method takes no parameters. It reads the internal state of the local planner's waypoint queue.

Outputs

Name Type Description
is_done bool True if the local planner's waypoint queue is empty (destination reached). False if waypoints remain to be traversed.

Usage Examples

Basic Example

import carla
from agents.navigation.basic_agent import BasicAgent

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

# Spawn vehicle
bp = world.get_blueprint_library().find('vehicle.tesla.model3')
spawn_points = world.get_map().get_spawn_points()
vehicle = world.spawn_actor(bp, spawn_points[0])

# Initialize agent and set destination
agent = BasicAgent(vehicle, target_speed=30)
agent.set_destination(spawn_points[50].location)

# Standard navigation loop with done() as termination condition
while True:
    if agent.done():
        print("Destination reached!")
        break

    control = agent.run_step()
    vehicle.apply_control(control)
    world.tick()

# Clean up
vehicle.destroy()

Multi-Destination Route

import carla
from agents.navigation.basic_agent import BasicAgent

client = carla.Client('localhost', 2000)
world = client.get_world()
spawn_points = world.get_map().get_spawn_points()

bp = world.get_blueprint_library().find('vehicle.tesla.model3')
vehicle = world.spawn_actor(bp, spawn_points[0])

agent = BasicAgent(vehicle, target_speed=25)

# Define a sequence of destinations
destinations = [
    spawn_points[20].location,
    spawn_points[50].location,
    spawn_points[80].location,
]

for i, dest in enumerate(destinations):
    agent.set_destination(dest)
    print(f"Navigating to destination {i + 1}/{len(destinations)}...")

    while not agent.done():
        control = agent.run_step()
        vehicle.apply_control(control)
        world.tick()

    print(f"Reached destination {i + 1}!")

print("All destinations visited.")
vehicle.destroy()

Timeout-Protected Navigation

import time
import carla
from agents.navigation.basic_agent import BasicAgent

client = carla.Client('localhost', 2000)
world = client.get_world()
spawn_points = world.get_map().get_spawn_points()

bp = world.get_blueprint_library().find('vehicle.tesla.model3')
vehicle = world.spawn_actor(bp, spawn_points[0])

agent = BasicAgent(vehicle, target_speed=30)
agent.set_destination(spawn_points[100].location)

start_time = time.time()
timeout = 120.0  # 2-minute timeout

while not agent.done():
    if time.time() - start_time > timeout:
        print("Navigation timed out!")
        break

    control = agent.run_step()
    vehicle.apply_control(control)
    world.tick()
else:
    print("Destination reached successfully!")

vehicle.destroy()

Related Pages

Implements Principle

Page Connections

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