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 Navigation Interface

From Leeroopedia
Knowledge Sources
Domains Navigation, Pedestrian AI
Last Updated 2026-02-15 05:00 GMT

Overview

The Navigation class manages pedestrian navigation using the Recast and Detour libraries, providing pathfinding, crowd simulation, and walker lifecycle management.

Description

carla::nav::Navigation is a NonCopyable class that serves as the central navigation system for pedestrian simulation. It loads a binary navigation mesh from the server and uses Detour's navmesh query and crowd systems for:

  • Navigation mesh -- loading from file or memory via Load(), creating dtNavMesh and dtNavMeshQuery objects
  • Crowd management -- CreateCrowd() initializes the Detour crowd; UpdateCrowd() advances the simulation each tick
  • Walker management -- AddWalker(), RemoveAgent(), SetWalkerTarget(), SetWalkerDirectTarget() for controlling individual pedestrians
  • Vehicle avoidance -- AddOrUpdateVehicle() and UpdateVehicles() register vehicles as obstacles for walkers to avoid
  • Pathfinding -- GetPath() computes a path between two locations using Detour's query with area-type filters
  • Walker queries -- GetWalkerTransform(), GetWalkerPosition(), GetWalkerSpeed(), IsWalkerAlive()
  • Randomization -- GetRandomLocation() for spawning walkers at random navigable positions; SetSeed() for reproducibility

The class defines navigation area types (Block, Sidewalk, Crosswalk, Road, Grass) and polygon flags for area-based filtering. A WalkerManager instance handles route planning with events.

Usage

Use this class for all pedestrian navigation operations in the CARLA simulation, including spawning walkers, setting destinations, updating the crowd each tick, and querying walker states.

Code Reference

Source Location

  • Repository: CARLA
  • File: LibCarla/source/carla/nav/Navigation.h

Signature

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

  bool Load(const std::string &filename);
  bool Load(std::vector<uint8_t> content);

  bool GetPath(geom::Location from, geom::Location to, dtQueryFilter *filter,
               std::vector<geom::Location> &path, std::vector<unsigned char> &area);

  void SetSimulator(std::weak_ptr<client::detail::Simulator> simulator);
  void SetSeed(unsigned int seed);
  void CreateCrowd(void);

  bool AddWalker(ActorId id, geom::Location from);
  bool AddOrUpdateVehicle(VehicleCollisionInfo &vehicle);
  bool RemoveAgent(ActorId id);
  bool UpdateVehicles(std::vector<VehicleCollisionInfo> vehicles);

  bool SetWalkerMaxSpeed(ActorId id, float max_speed);
  bool SetWalkerTarget(ActorId id, geom::Location to);
  bool SetWalkerDirectTarget(ActorId id, geom::Location to);

  bool GetWalkerTransform(ActorId id, geom::Transform &trans);
  bool GetWalkerPosition(ActorId id, geom::Location &location);
  float GetWalkerSpeed(ActorId id);

  void UpdateCrowd(const client::detail::EpisodeState &state);
  bool GetRandomLocation(geom::Location &location, dtQueryFilter *filter = nullptr) const;
  void SetPedestriansCrossFactor(float percentage);
  void PauseAgent(ActorId id, bool pause);
  bool HasVehicleNear(ActorId id, float distance, geom::Location direction);
  bool IsWalkerAlive(ActorId id, bool &alive);
};

Import

#include "carla/nav/Navigation.h"

I/O Contract

Input Type Description
std::vector<uint8_t> | Binary navmesh data from server
geom::Location | Start and end points for pathfinding
ActorId | Walker or agent identifier
Output Type Description
std::vector<geom::Location> | Computed path waypoints
geom::Transform | Current walker position and orientation
bool | Whether the operation succeeded

Usage Examples

Navigation nav;
nav.Load(navmesh_data);
nav.CreateCrowd();

// Add a walker and set its target
nav.AddWalker(walker_id, spawn_location);
nav.SetWalkerTarget(walker_id, destination);

// Update crowd each tick
nav.UpdateCrowd(episode_state);

Related Pages

Page Connections

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