CARLA
Loading...
Searching...
No Matches
WalkerNavigation.h
Go to the documentation of this file.
1// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
7#pragma once
8
9#include "carla/AtomicList.h"
11#include "carla/NonCopyable.h"
13#include "carla/rpc/ActorId.h"
14
15#include <memory>
16
17namespace carla {
18namespace client {
19namespace detail {
20
21 class Episode;
22 class EpisodeState;
23 class Simulator;
24
26 : public std::enable_shared_from_this<WalkerNavigation>,
27 private NonCopyable {
28 public:
29
30 explicit WalkerNavigation(std::weak_ptr<Simulator> simulator, bool server_side = false);
31
32 /// True when the server hosts the navigation (World-Partitioned navmesh):
33 /// the client-side Detour crowd stays disabled and walker AI goes through
34 /// the walker_* RPCs instead.
35 bool IsServerSide() const {
36 return _server_side;
37 }
38
39 void RegisterWalker(ActorId walker_id, ActorId controller_id) {
40 // add to list
41 _walkers.Push(WalkerHandle { walker_id, controller_id });
42 }
43
44 void UnregisterWalker(ActorId walker_id, ActorId controller_id) {
45 // remove from list
46 auto list = _walkers.Load();
47 unsigned int i = 0;
48 while (i < list->size()) {
49 if ((*list)[i].walker == walker_id &&
50 (*list)[i].controller == controller_id) {
51 _walkers.DeleteByIndex(i);
52 break;
53 }
54 ++i;
55 }
56 }
57
58 void RemoveWalker(ActorId walker_id) {
59 // remove the walker in the crowd
60 _nav.RemoveAgent(walker_id);
61 }
62
63 void AddWalker(ActorId walker_id, carla::geom::Location location) {
64 // create the walker in the crowd (to manage its movement in Detour)
65 _nav.AddWalker(walker_id, location);
66 }
67
68 void Tick(std::shared_ptr<Episode> episode);
69
70 // Get Random location in nav mesh
71 std::optional<geom::Location> GetRandomLocation() {
72 geom::Location random_location(0, 0, 0);
73 if (_nav.GetRandomLocation(random_location))
74 return std::optional<geom::Location>(random_location);
75 else
76 return {};
77 }
78
79 // set a new target point to go
81 return _nav.SetWalkerTarget(id, to);
82 }
83
84 // set new max speed
85 bool SetWalkerMaxSpeed(ActorId id, float max_speed) {
86 return _nav.SetWalkerMaxSpeed(id, max_speed);
87 }
88
89 // set percentage of pedestrians that can cross the road
90 void SetPedestriansCrossFactor(float percentage) {
92 }
93
94 void SetPedestriansSeed(unsigned int seed) {
95 _nav.SetSeed(seed);
96 }
97
98 private:
99
100 std::weak_ptr<Simulator> _simulator;
101
102 unsigned long _next_check_index;
103
104 const bool _server_side;
105
107
112
114
115 /// check a few walkers and if they don't exist then remove from the crowd
116 void CheckIfWalkerExist(std::vector<WalkerHandle> walkers, const EpisodeState &state);
117 /// add/update/delete all vehicles in crowd
118 void UpdateVehiclesInCrowd(std::shared_ptr<Episode> episode, bool show_debug = false);
119 };
120
121} // namespace detail
122} // namespace client
123} // namespace carla
Inherit (privately) to suppress copy/move construction and assignment.
Holds an atomic pointer to a list.
Definition AtomicList.h:25
Represents the state of all the actors of an episode at a given frame.
void UpdateVehiclesInCrowd(std::shared_ptr< Episode > episode, bool show_debug=false)
add/update/delete all vehicles in crowd
void SetPedestriansCrossFactor(float percentage)
void RegisterWalker(ActorId walker_id, ActorId controller_id)
std::optional< geom::Location > GetRandomLocation()
bool SetWalkerMaxSpeed(ActorId id, float max_speed)
void Tick(std::shared_ptr< Episode > episode)
void CheckIfWalkerExist(std::vector< WalkerHandle > walkers, const EpisodeState &state)
check a few walkers and if they don't exist then remove from the crowd
void AddWalker(ActorId walker_id, carla::geom::Location location)
bool IsServerSide() const
True when the server hosts the navigation (World-Partitioned navmesh): the client-side Detour crowd s...
void UnregisterWalker(ActorId walker_id, ActorId controller_id)
bool SetWalkerTarget(ActorId id, const carla::geom::Location to)
Manage the pedestrians navigation, using the Recast & Detour library for low level calculations.
Definition Navigation.h:57
bool SetWalkerMaxSpeed(ActorId id, float max_speed)
set new max speed
bool RemoveAgent(ActorId id)
remove an agent
bool SetWalkerTarget(ActorId id, carla::geom::Location to)
set a new target point to go through a route with events
void SetSeed(unsigned int seed)
set the seed to use with random numbers
bool GetRandomLocation(carla::geom::Location &location, dtQueryFilter *filter=nullptr) const
get a random location for navigation
void SetPedestriansCrossFactor(float percentage)
set the probability that an agent could cross the roads in its path following
bool AddWalker(ActorId id, carla::geom::Location from)
create a new walker
This file contains definitions of common data structures used in traffic manager.