Manage the pedestrians navigation, using the Recast & Detour library for low level calculations. More...
#include <Navigation.h>
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 | 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... | |
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... | |
![]() | |
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 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 } |
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... | |
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.
carla::nav::Navigation::Navigation | ( | ) |
Definition at line 51 of file Navigation.cpp.
References _walker_manager, and carla::nav::WalkerManager::SetNav().
carla::nav::Navigation::~Navigation | ( | ) |
Definition at line 56 of file Navigation.cpp.
References _binary_mesh, _crowd, _mapped_by_index, _mapped_vehicles_id, _mapped_walkers_id, _nav_mesh, _nav_query, _ready, _time_to_unblock, _walkers_blocked_position, and _yaw_walkers.
bool carla::nav::Navigation::AddOrUpdateVehicle | ( | VehicleCollisionInfo & | vehicle | ) |
create a new vehicle in crowd to be avoided by walkers
Definition at line 527 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().
bool carla::nav::Navigation::AddWalker | ( | ActorId | id, |
carla::geom::Location | from | ||
) |
create a new walker
Definition at line 466 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().
void carla::nav::Navigation::CreateCrowd | ( | void | ) |
create the crowd object
Definition at line 194 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().
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 365 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().
|
inline |
Definition at line 112 of file Navigation.h.
Referenced by carla::client::detail::WalkerNavigation::UpdateVehiclesInCrowd().
|
inline |
return the last delta seconds
Definition at line 115 of file Navigation.h.
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 | ||
) |
return the path points to go from one position to another
Definition at line 260 of file Navigation.cpp.
References _mutex, _nav_mesh, _nav_query, _ready, carla::nav::CARLA_AREA_GRASS, carla::nav::CARLA_AREA_ROAD, carla::nav::CARLA_TYPE_NONE, carla::nav::CARLA_TYPE_WALKABLE, DEBUG_ASSERT, carla::nav::MAX_POLYS, carla::geom::Vector3D::x, carla::geom::Vector3D::y, and carla::geom::Vector3D::z.
bool carla::nav::Navigation::GetRandomLocation | ( | carla::geom::Location & | location, |
dtQueryFilter * | filter = nullptr |
||
) | const |
get a random location for navigation
Definition at line 1054 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().
bool carla::nav::Navigation::GetWalkerPosition | ( | ActorId | id, |
carla::geom::Location & | location | ||
) |
get the walker current location
Definition at line 979 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().
float carla::nav::Navigation::GetWalkerSpeed | ( | ActorId | id | ) |
get the walker current transform
Definition at line 1020 of file Navigation.cpp.
References _crowd, _mapped_walkers_id, _mutex, _ready, and DEBUG_ASSERT.
Referenced by carla::client::detail::WalkerNavigation::Tick().
bool carla::nav::Navigation::GetWalkerTransform | ( | ActorId | id, |
carla::geom::Transform & | trans | ||
) |
get the walker current transform
Definition at line 915 of file Navigation.cpp.
References _crowd, _delta_seconds, _mapped_walkers_id, _mutex, _ready, _yaw_walkers, DEBUG_ASSERT, carla::geom::Transform::location, 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().
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 1149 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()().
bool carla::nav::Navigation::Load | ( | const std::string & | filename | ) |
load navigation data
Definition at line 76 of file Navigation.cpp.
Referenced by carla::client::detail::WalkerNavigation::WalkerNavigation().
bool carla::nav::Navigation::Load | ( | std::vector< uint8_t > | content | ) |
load navigation data from memory
Definition at line 93 of file Navigation.cpp.
References _binary_mesh, _nav_mesh, _nav_query, _ready, CreateCrowd(), and carla::logging::log().
void carla::nav::Navigation::PauseAgent | ( | ActorId | id, |
bool | pause | ||
) |
set an agent as paused for the crowd
Definition at line 1117 of file Navigation.cpp.
References _crowd, _mapped_walkers_id, _mutex, _ready, and DEBUG_ASSERT.
Referenced by carla::nav::WalkerManager::SetWalkerNextPoint(), and carla::nav::WalkerManager::Update().
bool carla::nav::Navigation::RemoveAgent | ( | ActorId | id | ) |
remove an agent
Definition at line 656 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(), and UpdateVehicles().
|
private |
assign a filter index to an agent
Definition at line 1095 of file Navigation.cpp.
References _crowd, and _mutex.
Referenced by UpdateCrowd().
void carla::nav::Navigation::SetPedestriansCrossFactor | ( | float | percentage | ) |
set the probability that an agent could cross the roads in its path following
Definition at line 1111 of file Navigation.cpp.
References _probability_crossing.
Referenced by carla::client::detail::WalkerNavigation::SetPedestriansCrossFactor().
void carla::nav::Navigation::SetSeed | ( | unsigned int | seed | ) |
set the seed to use with random numbers
Definition at line 71 of file Navigation.cpp.
Referenced by carla::client::detail::WalkerNavigation::SetPedestriansSeed().
bool carla::nav::Navigation::SetWalkerDirectTarget | ( | ActorId | id, |
carla::geom::Location | to | ||
) |
Definition at line 775 of file Navigation.cpp.
References _mapped_walkers_id, _ready, and SetWalkerDirectTargetIndex().
Referenced by carla::nav::WalkerManager::SetWalkerNextPoint().
bool carla::nav::Navigation::SetWalkerDirectTargetIndex | ( | int | index, |
carla::geom::Location | to | ||
) |
Definition at line 792 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().
bool carla::nav::Navigation::SetWalkerLookAt | ( | ActorId | id, |
carla::geom::Location | location | ||
) |
make agent look at some location
Definition at line 1170 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.
bool carla::nav::Navigation::SetWalkerMaxSpeed | ( | ActorId | id, |
float | max_speed | ||
) |
set new max speed
Definition at line 728 of file Navigation.cpp.
References _crowd, _mapped_walkers_id, _mutex, _ready, and DEBUG_ASSERT.
Referenced by carla::client::detail::WalkerNavigation::SetWalkerMaxSpeed().
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 758 of file Navigation.cpp.
References _mapped_walkers_id, _ready, _walker_manager, and carla::nav::WalkerManager::SetWalkerRoute().
Referenced by carla::client::detail::WalkerNavigation::SetWalkerTarget().
void carla::nav::Navigation::UpdateCrowd | ( | const client::detail::EpisodeState & | state | ) |
update all walkers in crowd
Definition at line 827 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().
bool carla::nav::Navigation::UpdateVehicles | ( | std::vector< VehicleCollisionInfo > | vehicles | ) |
add/update/delete vehicles in crowd
Definition at line 702 of file Navigation.cpp.
References _mapped_vehicles_id, AddOrUpdateVehicle(), and RemoveAgent().
Referenced by carla::client::detail::WalkerNavigation::UpdateVehiclesInCrowd().
|
private |
Definition at line 120 of file Navigation.h.
Referenced by Load(), and ~Navigation().
|
private |
crowd
Definition at line 126 of file Navigation.h.
Referenced by AddOrUpdateVehicle(), AddWalker(), CreateCrowd(), GetAgentRoute(), GetWalkerPosition(), GetWalkerSpeed(), GetWalkerTransform(), HasVehicleNear(), PauseAgent(), RemoveAgent(), SetAgentFilter(), SetWalkerDirectTargetIndex(), SetWalkerLookAt(), SetWalkerMaxSpeed(), UpdateCrowd(), and ~Navigation().
|
private |
Definition at line 121 of file Navigation.h.
Referenced by GetWalkerTransform(), and UpdateCrowd().
|
private |
Definition at line 131 of file Navigation.h.
Referenced by AddOrUpdateVehicle(), AddWalker(), RemoveAgent(), UpdateCrowd(), and ~Navigation().
|
private |
Definition at line 129 of file Navigation.h.
Referenced by AddOrUpdateVehicle(), HasVehicleNear(), RemoveAgent(), SetWalkerLookAt(), UpdateVehicles(), and ~Navigation().
|
private |
mapping Id
Definition at line 128 of file Navigation.h.
Referenced by AddWalker(), GetAgentRoute(), GetWalkerPosition(), GetWalkerSpeed(), GetWalkerTransform(), HasVehicleNear(), PauseAgent(), RemoveAgent(), SetWalkerDirectTarget(), SetWalkerLookAt(), SetWalkerMaxSpeed(), SetWalkerTarget(), and ~Navigation().
|
mutableprivate |
Definition at line 141 of file Navigation.h.
Referenced by AddOrUpdateVehicle(), AddWalker(), GetAgentRoute(), GetPath(), GetRandomLocation(), GetWalkerPosition(), GetWalkerSpeed(), GetWalkerTransform(), HasVehicleNear(), PauseAgent(), RemoveAgent(), SetAgentFilter(), SetWalkerDirectTargetIndex(), SetWalkerLookAt(), SetWalkerMaxSpeed(), and UpdateCrowd().
|
private |
meshes
Definition at line 123 of file Navigation.h.
Referenced by CreateCrowd(), GetAgentRoute(), GetPath(), Load(), and ~Navigation().
|
private |
Definition at line 124 of file Navigation.h.
Referenced by GetAgentRoute(), GetPath(), GetRandomLocation(), Load(), SetWalkerDirectTargetIndex(), and ~Navigation().
|
private |
Definition at line 143 of file Navigation.h.
Referenced by AddWalker(), SetPedestriansCrossFactor(), and UpdateCrowd().
|
private |
Definition at line 119 of file Navigation.h.
Referenced by AddOrUpdateVehicle(), AddWalker(), CreateCrowd(), GetAgentRoute(), GetPath(), GetRandomLocation(), GetWalkerPosition(), GetWalkerSpeed(), GetWalkerTransform(), Load(), PauseAgent(), RemoveAgent(), SetWalkerDirectTarget(), SetWalkerDirectTargetIndex(), SetWalkerMaxSpeed(), SetWalkerTarget(), UpdateCrowd(), and ~Navigation().
|
private |
Definition at line 136 of file Navigation.h.
Referenced by UpdateCrowd(), and ~Navigation().
|
private |
walker manager for the route planning with events
Definition at line 139 of file Navigation.h.
Referenced by AddWalker(), Navigation(), RemoveAgent(), SetWalkerTarget(), and UpdateCrowd().
|
private |
saves the position of each actor at intervals and check if any is blocked
Definition at line 135 of file Navigation.h.
Referenced by UpdateCrowd(), and ~Navigation().
|
private |
store walkers yaw angle from previous tick
Definition at line 133 of file Navigation.h.
Referenced by AddWalker(), GetWalkerTransform(), and ~Navigation().