CARLA
Loading...
Searching...
No Matches
carla::nav::Navigation Class Reference

Manage the pedestrians navigation, using the Recast & Detour library for low level calculations. More...

#include <Navigation.h>

Inheritance diagram for carla::nav::Navigation:

Public Member Functions

bool AddOrUpdateVehicle (VehicleCollisionInfo &vehicle)
 create a new vehicle in crowd to be avoided by walkers
bool AddWalker (ActorId id, carla::geom::Location from)
 create a new walker
void CreateCrowd (void)
 create the crowd object
bool GetAgentRoute (ActorId id, carla::geom::Location from, carla::geom::Location to, std::vector< carla::geom::Location > &path, std::vector< unsigned char > &area)
dtCrowd * GetCrowd ()
double GetDeltaSeconds ()
 return the last delta seconds
bool GetPath (carla::geom::Location from, carla::geom::Location to, dtQueryFilter *filter, std::vector< carla::geom::Location > &path, std::vector< unsigned char > &area)
 return the path points to go from one position to another
bool GetRandomLocation (carla::geom::Location &location, dtQueryFilter *filter=nullptr) const
 get a random location for navigation
bool GetWalkerPosition (ActorId id, carla::geom::Location &location)
 get the walker current location
float GetWalkerSpeed (ActorId id)
 get the walker current transform
bool GetWalkerTransform (ActorId id, carla::geom::Transform &trans)
 get the walker current transform
bool HasVehicleNear (ActorId id, float distance, carla::geom::Location direction)
 return if the agent has a vehicle near (as neighbour)
bool IsWalkerAlive (ActorId id, bool &alive)
 return if the agent has been killed by a vehicle
bool Load (const std::string &filename)
 load navigation data
bool Load (std::vector< uint8_t > content)
 load navigation data from memory
 Navigation ()
void PauseAgent (ActorId id, bool pause)
 set an agent as paused for the crowd
bool RemoveAgent (ActorId id)
 remove an agent
void SetPedestriansCrossFactor (float percentage)
 set the probability that an agent could cross the roads in its path following
void SetSeed (unsigned int seed)
 set the seed to use with random numbers
void SetSimulator (std::weak_ptr< carla::client::detail::Simulator > simulator)
 reference to the simulator to access API functions
bool SetWalkerDirectTarget (ActorId id, carla::geom::Location to)
bool SetWalkerDirectTargetIndex (int index, carla::geom::Location to)
bool SetWalkerLookAt (ActorId id, carla::geom::Location location)
 make agent look at some location
bool SetWalkerMaxSpeed (ActorId id, float max_speed)
 set new max speed
bool SetWalkerTarget (ActorId id, carla::geom::Location to)
 set a new target point to go through a route with events
void UpdateCrowd (const client::detail::EpisodeState &state)
 update all walkers in crowd
bool UpdateVehicles (std::vector< VehicleCollisionInfo > vehicles)
 add/update/delete vehicles in crowd
 ~Navigation ()

Private Member Functions

void SetAgentFilter (int agent_index, int filter_index)
 assign a filter index to an agent
Private Member Functions inherited from carla::NonCopyable
 NonCopyable ()=default
 NonCopyable (const NonCopyable &)=delete
 NonCopyable (NonCopyable &&)=delete
NonCopyable & operator= (const NonCopyable &)=delete
NonCopyable & operator= (NonCopyable &&)=delete

Private Attributes

std::vector< uint8_t > _binary_mesh
dtCrowd * _crowd { nullptr }
 crowd
double _delta_seconds { 0.0 }
std::optional< double > _last_elapsed_seconds
 Simulation time of the snapshot the crowd last advanced to; unset before the first update.
std::unordered_map< int, ActorId > _mapped_by_index
std::unordered_map< ActorId, int > _mapped_vehicles_id
std::unordered_map< ActorId, int > _mapped_walkers_id
 mapping Id
std::mutex _mutex
dtNavMesh * _nav_mesh { nullptr }
 meshes
dtNavMeshQuery * _nav_query { nullptr }
float _probability_crossing { 0.0f }
bool _ready { false }
std::weak_ptr< carla::client::detail::Simulator > _simulator
double _time_to_unblock { 0.0 }
WalkerManager _walker_manager
 walker manager for the route planning with events
std::unordered_map< int, carla::geom::Vector3D > _walkers_blocked_position
 saves the position of each actor at intervals and check if any is blocked
std::unordered_map< ActorId, float > _yaw_walkers
 store walkers yaw angle from previous tick

Detailed Description

Manage the pedestrians navigation, using the Recast & Detour library for low level calculations.

This class gets the binary content of the map from the server, which is required for the path finding. Then this class can add or remove pedestrians, and also set target points to walk for each one.

Definition at line 59 of file Navigation.h.

Constructor & Destructor Documentation

◆ Navigation()

carla::nav::Navigation::Navigation ( )

Definition at line 55 of file Navigation.cpp.

References _walker_manager, and carla::nav::WalkerManager::SetNav().

◆ ~Navigation()

Member Function Documentation

◆ AddOrUpdateVehicle()

◆ AddWalker()

◆ CreateCrowd()

◆ GetAgentRoute()

bool carla::nav::Navigation::GetAgentRoute ( ActorId id,
carla::geom::Location from,
carla::geom::Location to,
std::vector< carla::geom::Location > & path,
std::vector< unsigned char > & area )

◆ GetCrowd()

dtCrowd * carla::nav::Navigation::GetCrowd ( )
inline

Definition at line 118 of file Navigation.h.

References _crowd.

Referenced by carla::client::detail::WalkerNavigation::UpdateVehiclesInCrowd().

◆ GetDeltaSeconds()

double carla::nav::Navigation::GetDeltaSeconds ( )
inline

return the last delta seconds

Definition at line 121 of file Navigation.h.

References _delta_seconds.

◆ GetPath()

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

◆ GetRandomLocation()

bool carla::nav::Navigation::GetRandomLocation ( carla::geom::Location & location,
dtQueryFilter * filter = nullptr ) const

◆ GetWalkerPosition()

◆ GetWalkerSpeed()

float carla::nav::Navigation::GetWalkerSpeed ( ActorId id)

get the walker current transform

Definition at line 1044 of file Navigation.cpp.

References _crowd, _mapped_walkers_id, _mutex, _ready, and DEBUG_ASSERT.

Referenced by carla::client::detail::WalkerNavigation::Tick().

◆ GetWalkerTransform()

◆ HasVehicleNear()

bool carla::nav::Navigation::HasVehicleNear ( ActorId id,
float distance,
carla::geom::Location direction )

return if the agent has a vehicle near (as neighbour)

Definition at line 1173 of file Navigation.cpp.

References _crowd, _mapped_vehicles_id, _mapped_walkers_id, _mutex, carla::geom::Vector3D::x, carla::geom::Vector3D::y, and carla::geom::Vector3D::z.

Referenced by carla::nav::WalkerEventVisitor::operator()().

◆ IsWalkerAlive()

bool carla::nav::Navigation::IsWalkerAlive ( ActorId id,
bool & alive )

return if the agent has been killed by a vehicle

Definition at line 1230 of file Navigation.cpp.

References _crowd, _mapped_walkers_id, _mutex, _ready, and DEBUG_ASSERT.

Referenced by carla::client::detail::WalkerNavigation::Tick().

◆ Load() [1/2]

bool carla::nav::Navigation::Load ( const std::string & filename)

load navigation data

Definition at line 87 of file Navigation.cpp.

References Load().

Referenced by Load().

◆ Load() [2/2]

bool carla::nav::Navigation::Load ( std::vector< uint8_t > content)

load navigation data from memory

Definition at line 104 of file Navigation.cpp.

References _binary_mesh, _nav_mesh, _nav_query, _ready, CreateCrowd(), and carla::nav::MAX_QUERY_SEARCH_NODES.

◆ PauseAgent()

void carla::nav::Navigation::PauseAgent ( ActorId id,
bool pause )

set an agent as paused for the crowd

Definition at line 1141 of file Navigation.cpp.

References _crowd, _mapped_walkers_id, _mutex, _ready, and DEBUG_ASSERT.

Referenced by carla::nav::WalkerEventVisitor::operator()(), and carla::nav::WalkerManager::SetWalkerNextPoint().

◆ RemoveAgent()

◆ SetAgentFilter()

void carla::nav::Navigation::SetAgentFilter ( int agent_index,
int filter_index )
private

assign a filter index to an agent

Definition at line 1119 of file Navigation.cpp.

References _crowd, and _mutex.

Referenced by UpdateCrowd().

◆ SetPedestriansCrossFactor()

void carla::nav::Navigation::SetPedestriansCrossFactor ( float percentage)

set the probability that an agent could cross the roads in its path following

Definition at line 1135 of file Navigation.cpp.

References _probability_crossing.

Referenced by carla::client::detail::WalkerNavigation::SetPedestriansCrossFactor().

◆ SetSeed()

void carla::nav::Navigation::SetSeed ( unsigned int seed)

set the seed to use with random numbers

Definition at line 82 of file Navigation.cpp.

Referenced by carla::client::detail::WalkerNavigation::SetPedestriansSeed().

◆ SetSimulator()

void carla::nav::Navigation::SetSimulator ( std::weak_ptr< carla::client::detail::Simulator > simulator)

reference to the simulator to access API functions

Definition at line 75 of file Navigation.cpp.

References _simulator, _walker_manager, and carla::nav::WalkerManager::SetSimulator().

Referenced by carla::client::detail::WalkerNavigation::WalkerNavigation().

◆ SetWalkerDirectTarget()

bool carla::nav::Navigation::SetWalkerDirectTarget ( ActorId id,
carla::geom::Location to )

◆ SetWalkerDirectTargetIndex()

bool carla::nav::Navigation::SetWalkerDirectTargetIndex ( int index,
carla::geom::Location to )

◆ SetWalkerLookAt()

bool carla::nav::Navigation::SetWalkerLookAt ( ActorId id,
carla::geom::Location location )

make agent look at some location

Definition at line 1194 of file Navigation.cpp.

References _crowd, _mapped_vehicles_id, _mapped_walkers_id, _mutex, carla::geom::Vector3D::x, carla::geom::Vector3D::y, and carla::geom::Vector3D::z.

◆ SetWalkerMaxSpeed()

bool carla::nav::Navigation::SetWalkerMaxSpeed ( ActorId id,
float max_speed )

set new max speed

Definition at line 739 of file Navigation.cpp.

References _crowd, _mapped_walkers_id, _mutex, _ready, and DEBUG_ASSERT.

Referenced by carla::client::detail::WalkerNavigation::SetWalkerMaxSpeed().

◆ SetWalkerTarget()

bool carla::nav::Navigation::SetWalkerTarget ( ActorId id,
carla::geom::Location to )

set a new target point to go through a route with events

Definition at line 769 of file Navigation.cpp.

References _mapped_walkers_id, _ready, _walker_manager, and carla::nav::WalkerManager::SetWalkerRoute().

Referenced by carla::client::detail::WalkerNavigation::SetWalkerTarget().

◆ UpdateCrowd()

◆ UpdateVehicles()

bool carla::nav::Navigation::UpdateVehicles ( std::vector< VehicleCollisionInfo > vehicles)

add/update/delete vehicles in crowd

Definition at line 713 of file Navigation.cpp.

References _mapped_vehicles_id, AddOrUpdateVehicle(), and RemoveAgent().

Referenced by carla::client::detail::WalkerNavigation::UpdateVehiclesInCrowd().

Member Data Documentation

◆ _binary_mesh

std::vector<uint8_t> carla::nav::Navigation::_binary_mesh
private

Definition at line 126 of file Navigation.h.

Referenced by Load(), and ~Navigation().

◆ _crowd

◆ _delta_seconds

double carla::nav::Navigation::_delta_seconds { 0.0 }
private

Definition at line 127 of file Navigation.h.

Referenced by GetDeltaSeconds(), GetWalkerTransform(), and UpdateCrowd().

◆ _last_elapsed_seconds

std::optional<double> carla::nav::Navigation::_last_elapsed_seconds
private

Simulation time of the snapshot the crowd last advanced to; unset before the first update.

Definition at line 129 of file Navigation.h.

Referenced by UpdateCrowd().

◆ _mapped_by_index

std::unordered_map<int, ActorId> carla::nav::Navigation::_mapped_by_index
private

Definition at line 139 of file Navigation.h.

Referenced by AddOrUpdateVehicle(), AddWalker(), RemoveAgent(), UpdateCrowd(), and ~Navigation().

◆ _mapped_vehicles_id

std::unordered_map<ActorId, int> carla::nav::Navigation::_mapped_vehicles_id
private

◆ _mapped_walkers_id

◆ _mutex

◆ _nav_mesh

dtNavMesh* carla::nav::Navigation::_nav_mesh { nullptr }
private

meshes

Definition at line 131 of file Navigation.h.

Referenced by CreateCrowd(), GetAgentRoute(), GetPath(), Load(), and ~Navigation().

◆ _nav_query

dtNavMeshQuery* carla::nav::Navigation::_nav_query { nullptr }
private

◆ _probability_crossing

float carla::nav::Navigation::_probability_crossing { 0.0f }
private

Definition at line 153 of file Navigation.h.

Referenced by AddWalker(), SetPedestriansCrossFactor(), and UpdateCrowd().

◆ _ready

◆ _simulator

std::weak_ptr<carla::client::detail::Simulator> carla::nav::Navigation::_simulator
private

Definition at line 149 of file Navigation.h.

Referenced by SetSimulator().

◆ _time_to_unblock

double carla::nav::Navigation::_time_to_unblock { 0.0 }
private

Definition at line 144 of file Navigation.h.

Referenced by UpdateCrowd(), and ~Navigation().

◆ _walker_manager

WalkerManager carla::nav::Navigation::_walker_manager
private

walker manager for the route planning with events

Definition at line 147 of file Navigation.h.

Referenced by AddWalker(), Navigation(), RemoveAgent(), SetSimulator(), SetWalkerTarget(), and UpdateCrowd().

◆ _walkers_blocked_position

std::unordered_map<int, carla::geom::Vector3D> carla::nav::Navigation::_walkers_blocked_position
private

saves the position of each actor at intervals and check if any is blocked

Definition at line 143 of file Navigation.h.

Referenced by UpdateCrowd(), and ~Navigation().

◆ _yaw_walkers

std::unordered_map<ActorId, float> carla::nav::Navigation::_yaw_walkers
private

store walkers yaw angle from previous tick

Definition at line 141 of file Navigation.h.

Referenced by AddWalker(), GetWalkerTransform(), and ~Navigation().


The documentation for this class was generated from the following files: