CARLA
Public Member Functions | Private Member Functions | Private Attributes | List of all members
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:
+ Collaboration diagram for carla::nav::Navigation:

Public Member Functions

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

Private Member Functions

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

Private Attributes

std::vector< uint8_t > _binary_mesh
 
dtCrowd * _crowd { nullptr }
 crowd More...
 
double _delta_seconds { 0.0 }
 
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 More...
 
std::mutex _mutex
 
dtNavMesh * _nav_mesh { nullptr }
 meshes More...
 
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 More...
 
std::unordered_map< int, carla::geom::Vector3D_walkers_blocked_position
 saves the position of each actor at intervals and check if any is blocked More...
 
std::unordered_map< ActorId, float > _yaw_walkers
 store walkers yaw angle from previous tick More...
 

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 57 of file Navigation.h.

Constructor & Destructor Documentation

◆ Navigation()

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

Definition at line 51 of file Navigation.cpp.

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

+ Here is the call graph for this function:

◆ ~Navigation()

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

Member Function Documentation

◆ AddOrUpdateVehicle()

bool carla::nav::Navigation::AddOrUpdateVehicle ( VehicleCollisionInfo vehicle)

create a new vehicle in crowd to be avoided by walkers

Definition at line 534 of file Navigation.cpp.

References _crowd, _mapped_by_index, _mapped_vehicles_id, _mutex, _ready, carla::nav::AGENT_HEIGHT, carla::nav::VehicleCollisionInfo::bounding, DEBUG_ASSERT, carla::nav::DT_CROWD_SEPARATION, carla::geom::BoundingBox::extent, carla::nav::VehicleCollisionInfo::id, carla::geom::Transform::location, carla::logging::log(), carla::geom::Math::RotatePointOnOrigin2D(), carla::geom::Transform::rotation, carla::geom::Math::ToRadians(), carla::nav::VehicleCollisionInfo::transform, carla::geom::Vector3D::x, carla::geom::Vector3D::y, carla::geom::Rotation::yaw, and carla::geom::Vector3D::z.

Referenced by UpdateVehicles().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AddWalker()

bool carla::nav::Navigation::AddWalker ( ActorId  id,
carla::geom::Location  from 
)

create a new walker

Definition at line 473 of file Navigation.cpp.

References _crowd, _mapped_by_index, _mapped_walkers_id, _mutex, _probability_crossing, _ready, _walker_manager, _yaw_walkers, carla::nav::WalkerManager::AddWalker(), carla::nav::AGENT_HEIGHT, carla::nav::AGENT_RADIUS, DEBUG_ASSERT, carla::nav::DT_CROWD_ANTICIPATE_TURNS, carla::nav::DT_CROWD_OBSTACLE_AVOIDANCE, carla::nav::DT_CROWD_SEPARATION, carla::nav::frand(), carla::geom::Vector3D::x, carla::geom::Vector3D::y, and carla::geom::Vector3D::z.

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CreateCrowd()

void carla::nav::Navigation::CreateCrowd ( void  )

create the crowd object

Definition at line 201 of file Navigation.cpp.

References _crowd, _nav_mesh, _ready, carla::nav::CARLA_AREA_GRASS, carla::nav::CARLA_AREA_ROAD, carla::nav::CARLA_TYPE_NONE, carla::nav::CARLA_TYPE_ROAD, carla::nav::CARLA_TYPE_WALKABLE, DEBUG_ASSERT, and carla::logging::log().

Referenced by Load().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 
)

Definition at line 372 of file Navigation.cpp.

References _crowd, _mapped_walkers_id, _mutex, _nav_mesh, _nav_query, _ready, DEBUG_ASSERT, carla::nav::MAX_POLYS, carla::geom::Vector3D::x, carla::geom::Vector3D::y, and carla::geom::Vector3D::z.

Referenced by carla::nav::WalkerManager::SetWalkerRoute().

+ Here is the caller graph for this function:

◆ GetCrowd()

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

Definition at line 116 of file Navigation.h.

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

+ Here is the caller graph for this function:

◆ GetDeltaSeconds()

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

return the last delta seconds

Definition at line 119 of file Navigation.h.

◆ 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

get a random location for navigation

Definition at line 1062 of file Navigation.cpp.

References _mutex, _nav_query, _ready, carla::nav::CARLA_TYPE_NONE, carla::nav::CARLA_TYPE_SIDEWALK, DEBUG_ASSERT, carla::nav::frand(), carla::geom::Vector3D::x, carla::geom::Vector3D::y, and carla::geom::Vector3D::z.

Referenced by carla::client::detail::WalkerNavigation::GetRandomLocation(), carla::nav::WalkerManager::SetWalkerRoute(), and UpdateCrowd().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetWalkerPosition()

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

get the walker current location

Definition at line 987 of file Navigation.cpp.

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

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

+ Here is the caller graph for this function:

◆ GetWalkerSpeed()

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

get the walker current transform

Definition at line 1028 of file Navigation.cpp.

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

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

+ Here is the caller graph for this function:

◆ GetWalkerTransform()

bool carla::nav::Navigation::GetWalkerTransform ( ActorId  id,
carla::geom::Transform trans 
)

get the walker current transform

Definition at line 923 of file Navigation.cpp.

References _crowd, _delta_seconds, _mapped_walkers_id, _mutex, _ready, _yaw_walkers, DEBUG_ASSERT, carla::geom::Transform::location, min(), carla::geom::Transform::rotation, carla::geom::Vector3D::x, carla::geom::Vector3D::y, carla::geom::Rotation::yaw, and carla::geom::Vector3D::z.

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 1157 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()().

+ Here is the caller graph for this function:

◆ IsWalkerAlive()

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

return if the agent has been killed by a vehicle

Definition at line 1214 of file Navigation.cpp.

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

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

+ Here is the caller graph for this function:

◆ Load() [1/2]

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

load navigation data

Definition at line 83 of file Navigation.cpp.

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

+ Here is the caller graph for this function:

◆ Load() [2/2]

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

load navigation data from memory

Definition at line 100 of file Navigation.cpp.

References _binary_mesh, _nav_mesh, _nav_query, _ready, CreateCrowd(), and carla::logging::log().

+ Here is the call graph for this function:

◆ PauseAgent()

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

set an agent as paused for the crowd

Definition at line 1125 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().

+ Here is the caller graph for this function:

◆ RemoveAgent()

bool carla::nav::Navigation::RemoveAgent ( ActorId  id)

remove an agent

Definition at line 663 of file Navigation.cpp.

References _crowd, _mapped_by_index, _mapped_vehicles_id, _mapped_walkers_id, _mutex, _ready, _walker_manager, DEBUG_ASSERT, and carla::nav::WalkerManager::RemoveWalker().

Referenced by carla::client::detail::WalkerNavigation::CheckIfWalkerExist(), carla::client::detail::WalkerNavigation::RemoveWalker(), carla::client::detail::WalkerNavigation::Tick(), and UpdateVehicles().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetAgentFilter()

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

assign a filter index to an agent

Definition at line 1103 of file Navigation.cpp.

References _crowd, and _mutex.

Referenced by UpdateCrowd().

+ Here is the caller graph for this function:

◆ 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 1119 of file Navigation.cpp.

References _probability_crossing.

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

+ Here is the caller graph for this function:

◆ SetSeed()

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

set the seed to use with random numbers

Definition at line 78 of file Navigation.cpp.

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

+ Here is the caller graph for this function:

◆ 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 71 of file Navigation.cpp.

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

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetWalkerDirectTarget()

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

Definition at line 782 of file Navigation.cpp.

References _mapped_walkers_id, _ready, and SetWalkerDirectTargetIndex().

Referenced by carla::nav::WalkerManager::SetWalkerNextPoint().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetWalkerDirectTargetIndex()

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

Definition at line 799 of file Navigation.cpp.

References _crowd, _mutex, _nav_query, _ready, DEBUG_ASSERT, carla::geom::Vector3D::x, carla::geom::Vector3D::y, and carla::geom::Vector3D::z.

Referenced by SetWalkerDirectTarget().

+ Here is the caller graph for this function:

◆ SetWalkerLookAt()

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

make agent look at some location

Definition at line 1178 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 735 of file Navigation.cpp.

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

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

+ Here is the caller graph for this function:

◆ 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 765 of file Navigation.cpp.

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

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ UpdateCrowd()

void carla::nav::Navigation::UpdateCrowd ( const client::detail::EpisodeState state)

update all walkers in crowd

Definition at line 834 of file Navigation.cpp.

References _crowd, _delta_seconds, _mapped_by_index, _mutex, _probability_crossing, _ready, _time_to_unblock, _walker_manager, _walkers_blocked_position, DEBUG_ASSERT, carla::nav::frand(), GetRandomLocation(), carla::client::detail::EpisodeState::GetTimestamp(), SetAgentFilter(), carla::nav::WalkerManager::SetWalkerRoute(), carla::geom::Vector3D::SquaredLength(), and carla::nav::WalkerManager::Update().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ UpdateVehicles()

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

add/update/delete vehicles in crowd

Definition at line 709 of file Navigation.cpp.

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

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ _binary_mesh

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

Definition at line 124 of file Navigation.h.

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

◆ _crowd

dtCrowd* carla::nav::Navigation::_crowd { nullptr }
private

◆ _delta_seconds

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

Definition at line 125 of file Navigation.h.

Referenced by GetWalkerTransform(), and UpdateCrowd().

◆ _mapped_by_index

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

Definition at line 135 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

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

◆ _mutex

std::mutex carla::nav::Navigation::_mutex
mutableprivate

◆ _nav_mesh

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

meshes

Definition at line 127 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 149 of file Navigation.h.

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

◆ _ready

bool carla::nav::Navigation::_ready { false }
private

◆ _simulator

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

Definition at line 145 of file Navigation.h.

Referenced by SetSimulator().

◆ _time_to_unblock

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

Definition at line 140 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 143 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 139 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 137 of file Navigation.h.

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


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