|
CARLA
|
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 | |
| 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 | |
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.
| carla::nav::Navigation::Navigation | ( | ) |
Definition at line 55 of file Navigation.cpp.
References _walker_manager, and carla::nav::WalkerManager::SetNav().
| carla::nav::Navigation::~Navigation | ( | ) |
Definition at line 60 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 538 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::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 477 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 205 of file Navigation.cpp.
References _crowd, _nav_mesh, _ready, carla::nav::AGENT_RADIUS, carla::nav::AREA_GRASS_COST, carla::nav::AREA_ROAD_COST, 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::nav::MAX_AGENTS.
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 376 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 118 of file Navigation.h.
References _crowd.
Referenced by carla::client::detail::WalkerNavigation::UpdateVehiclesInCrowd().
|
inline |
return the last delta seconds
Definition at line 121 of file Navigation.h.
References _delta_seconds.
| 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 271 of file Navigation.cpp.
References _mutex, _nav_mesh, _nav_query, _ready, carla::nav::AREA_GRASS_COST, carla::nav::AREA_ROAD_COST, 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 1078 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 1003 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 1044 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 939 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 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()().
| 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().
| 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().
| 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.
| 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().
| bool carla::nav::Navigation::RemoveAgent | ( | ActorId | id | ) |
remove an agent
Definition at line 667 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 1119 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 1135 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 82 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 75 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 786 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 803 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 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.
| 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().
| 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().
| void carla::nav::Navigation::UpdateCrowd | ( | const client::detail::EpisodeState & | state | ) |
update all walkers in crowd
Definition at line 838 of file Navigation.cpp.
References _crowd, _delta_seconds, _last_elapsed_seconds, _mapped_by_index, _mutex, _probability_crossing, _ready, _time_to_unblock, _walker_manager, _walkers_blocked_position, carla::nav::AGENT_UNBLOCK_DISTANCE_SQUARED, carla::nav::AGENT_UNBLOCK_TIME, DEBUG_ASSERT, carla::nav::frand(), GetRandomLocation(), carla::client::detail::EpisodeState::GetTimestamp(), carla::nav::MAX_NAV_CATCH_UP, carla::nav::MAX_NAV_STEP, 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 713 of file Navigation.cpp.
References _mapped_vehicles_id, AddOrUpdateVehicle(), and RemoveAgent().
Referenced by carla::client::detail::WalkerNavigation::UpdateVehiclesInCrowd().
|
private |
Definition at line 126 of file Navigation.h.
Referenced by Load(), and ~Navigation().
|
private |
crowd
Definition at line 134 of file Navigation.h.
Referenced by AddOrUpdateVehicle(), AddWalker(), CreateCrowd(), GetAgentRoute(), GetCrowd(), GetWalkerPosition(), GetWalkerSpeed(), GetWalkerTransform(), HasVehicleNear(), IsWalkerAlive(), PauseAgent(), RemoveAgent(), SetAgentFilter(), SetWalkerDirectTargetIndex(), SetWalkerLookAt(), SetWalkerMaxSpeed(), UpdateCrowd(), and ~Navigation().
|
private |
Definition at line 127 of file Navigation.h.
Referenced by GetDeltaSeconds(), GetWalkerTransform(), and UpdateCrowd().
|
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().
|
private |
Definition at line 139 of file Navigation.h.
Referenced by AddOrUpdateVehicle(), AddWalker(), RemoveAgent(), UpdateCrowd(), and ~Navigation().
|
private |
Definition at line 137 of file Navigation.h.
Referenced by AddOrUpdateVehicle(), HasVehicleNear(), RemoveAgent(), SetWalkerLookAt(), UpdateVehicles(), and ~Navigation().
|
private |
mapping Id
Definition at line 136 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 151 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 131 of file Navigation.h.
Referenced by CreateCrowd(), GetAgentRoute(), GetPath(), Load(), and ~Navigation().
|
private |
Definition at line 132 of file Navigation.h.
Referenced by GetAgentRoute(), GetPath(), GetRandomLocation(), Load(), SetWalkerDirectTargetIndex(), and ~Navigation().
|
private |
Definition at line 153 of file Navigation.h.
Referenced by AddWalker(), SetPedestriansCrossFactor(), and UpdateCrowd().
|
private |
Definition at line 125 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 149 of file Navigation.h.
Referenced by SetSimulator().
|
private |
Definition at line 144 of file Navigation.h.
Referenced by UpdateCrowd(), and ~Navigation().
|
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().
|
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().
|
private |
store walkers yaw angle from previous tick
Definition at line 141 of file Navigation.h.
Referenced by AddWalker(), GetWalkerTransform(), and ~Navigation().