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 | 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 | |
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 } |
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... | |
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 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().
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().
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().
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().
|
inline |
Definition at line 116 of file Navigation.h.
Referenced by carla::client::detail::WalkerNavigation::UpdateVehiclesInCrowd().
|
inline |
return the last delta seconds
Definition at line 119 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 267 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 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().
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().
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().
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().
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()().
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().
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().
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().
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().
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().
|
private |
assign a filter index to an agent
Definition at line 1103 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 1119 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 78 of file Navigation.cpp.
Referenced by carla::client::detail::WalkerNavigation::SetPedestriansSeed().
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().
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().
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().
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.
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().
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().
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().
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().
|
private |
Definition at line 124 of file Navigation.h.
Referenced by Load(), and ~Navigation().
|
private |
crowd
Definition at line 130 of file Navigation.h.
Referenced by AddOrUpdateVehicle(), AddWalker(), CreateCrowd(), GetAgentRoute(), GetWalkerPosition(), GetWalkerSpeed(), GetWalkerTransform(), HasVehicleNear(), IsWalkerAlive(), PauseAgent(), RemoveAgent(), SetAgentFilter(), SetWalkerDirectTargetIndex(), SetWalkerLookAt(), SetWalkerMaxSpeed(), UpdateCrowd(), and ~Navigation().
|
private |
Definition at line 125 of file Navigation.h.
Referenced by GetWalkerTransform(), and UpdateCrowd().
|
private |
Definition at line 135 of file Navigation.h.
Referenced by AddOrUpdateVehicle(), AddWalker(), RemoveAgent(), UpdateCrowd(), and ~Navigation().
|
private |
Definition at line 133 of file Navigation.h.
Referenced by AddOrUpdateVehicle(), HasVehicleNear(), RemoveAgent(), SetWalkerLookAt(), UpdateVehicles(), and ~Navigation().
|
private |
mapping Id
Definition at line 132 of file Navigation.h.
Referenced by AddWalker(), GetAgentRoute(), GetWalkerPosition(), GetWalkerSpeed(), GetWalkerTransform(), HasVehicleNear(), IsWalkerAlive(), PauseAgent(), RemoveAgent(), SetWalkerDirectTarget(), SetWalkerLookAt(), SetWalkerMaxSpeed(), SetWalkerTarget(), and ~Navigation().
|
mutableprivate |
Definition at line 147 of file Navigation.h.
Referenced by AddOrUpdateVehicle(), AddWalker(), GetAgentRoute(), GetPath(), GetRandomLocation(), GetWalkerPosition(), GetWalkerSpeed(), GetWalkerTransform(), HasVehicleNear(), IsWalkerAlive(), PauseAgent(), RemoveAgent(), SetAgentFilter(), SetWalkerDirectTargetIndex(), SetWalkerLookAt(), SetWalkerMaxSpeed(), and UpdateCrowd().
|
private |
meshes
Definition at line 127 of file Navigation.h.
Referenced by CreateCrowd(), GetAgentRoute(), GetPath(), Load(), and ~Navigation().
|
private |
Definition at line 128 of file Navigation.h.
Referenced by GetAgentRoute(), GetPath(), GetRandomLocation(), Load(), SetWalkerDirectTargetIndex(), and ~Navigation().
|
private |
Definition at line 149 of file Navigation.h.
Referenced by AddWalker(), SetPedestriansCrossFactor(), and UpdateCrowd().
|
private |
Definition at line 123 of file Navigation.h.
Referenced by AddOrUpdateVehicle(), AddWalker(), CreateCrowd(), GetAgentRoute(), GetPath(), GetRandomLocation(), GetWalkerPosition(), GetWalkerSpeed(), GetWalkerTransform(), IsWalkerAlive(), Load(), PauseAgent(), RemoveAgent(), SetWalkerDirectTarget(), SetWalkerDirectTargetIndex(), SetWalkerMaxSpeed(), SetWalkerTarget(), UpdateCrowd(), and ~Navigation().
|
private |
Definition at line 145 of file Navigation.h.
Referenced by SetSimulator().
|
private |
Definition at line 140 of file Navigation.h.
Referenced by UpdateCrowd(), and ~Navigation().
|
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().
|
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().
|
private |
store walkers yaw angle from previous tick
Definition at line 137 of file Navigation.h.
Referenced by AddWalker(), GetWalkerTransform(), and ~Navigation().