CARLA
 
载入中...
搜索中...
未找到
Navigation.h
浏览该文件的文档.
1// Copyright (c) 2019 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
7#pragma once
8
9#include "carla/AtomicList.h"
12#include "carla/geom/Location.h"
15#include "carla/rpc/ActorId.h"
16#include <recast/Recast.h>
17#include <recast/DetourCrowd.h>
18#include <recast/DetourNavMesh.h>
19#include <recast/DetourNavMeshBuilder.h>
20#include <recast/DetourNavMeshQuery.h>
21#include <recast/DetourCommon.h>
22
23namespace carla {
24namespace nav {
25
33
45
46 /// struct to send info about vehicles to the crowd
52
53 /// Manage the pedestrians navigation, using the Recast & Detour library for low level calculations.
54 ///
55 /// This class gets the binary content of the map from the server, which is required for the path finding.
56 /// Then this class can add or remove pedestrians, and also set target points to walk for each one.
57 class Navigation : private NonCopyable {
58
59 public:
60
61 Navigation();
63
64 /// load navigation data
65 bool Load(const std::string &filename);
66 /// load navigation data from memory
67 bool Load(std::vector<uint8_t> content);
68 /// return the path points to go from one position to another
69 bool GetPath(carla::geom::Location from, carla::geom::Location to, dtQueryFilter * filter,
70 std::vector<carla::geom::Location> &path, std::vector<unsigned char> &area);
72 std::vector<carla::geom::Location> &path, std::vector<unsigned char> &area);
73
74 /// reference to the simulator to access API functions
75 void SetSimulator(std::weak_ptr<carla::client::detail::Simulator> simulator);
76 /// set the seed to use with random numbers
77 void SetSeed(unsigned int seed);
78 /// create the crowd object
79 void CreateCrowd(void);
80 /// create a new walker
82 /// create a new vehicle in crowd to be avoided by walkers
84 /// remove an agent
85 bool RemoveAgent(ActorId id);
86 /// add/update/delete vehicles in crowd
87 bool UpdateVehicles(std::vector<VehicleCollisionInfo> vehicles);
88 /// set new max speed
89 bool SetWalkerMaxSpeed(ActorId id, float max_speed);
90 /// set a new target point to go through a route with events
92 // set a new target point to go directly without events
95 /// get the walker current transform
97 /// get the walker current location
99 /// get the walker current transform
100 float GetWalkerSpeed(ActorId id);
101 /// update all walkers in crowd
102 void UpdateCrowd(const client::detail::EpisodeState &state);
103 /// get a random location for navigation
104 bool GetRandomLocation(carla::geom::Location &location, dtQueryFilter * filter = nullptr) const;
105 /// set the probability that an agent could cross the roads in its path following
106 void SetPedestriansCrossFactor(float percentage);
107 /// set an agent as paused for the crowd
108 void PauseAgent(ActorId id, bool pause);
109 /// return if the agent has a vehicle near (as neighbour)
110 bool HasVehicleNear(ActorId id, float distance, carla::geom::Location direction);
111 /// make agent look at some location
113 /// return if the agent has been killed by a vehicle
114 bool IsWalkerAlive(ActorId id, bool &alive);
115
116 dtCrowd *GetCrowd() { return _crowd; };
117
118 /// return the last delta seconds
119 double GetDeltaSeconds() { return _delta_seconds; };
120
121 private:
122
123 bool _ready { false };
124 std::vector<uint8_t> _binary_mesh;
125 double _delta_seconds { 0.0 };
126 /// meshes
127 dtNavMesh *_nav_mesh { nullptr };
128 dtNavMeshQuery *_nav_query { nullptr };
129 /// crowd
130 dtCrowd *_crowd { nullptr };
131 /// mapping Id
132 std::unordered_map<ActorId, int> _mapped_walkers_id;
133 std::unordered_map<ActorId, int> _mapped_vehicles_id;
134 // mapping by index also
135 std::unordered_map<int, ActorId> _mapped_by_index;
136 /// store walkers yaw angle from previous tick
137 std::unordered_map<ActorId, float> _yaw_walkers;
138 /// saves the position of each actor at intervals and check if any is blocked
139 std::unordered_map<int, carla::geom::Vector3D> _walkers_blocked_position;
140 double _time_to_unblock { 0.0 };
141
142 /// walker manager for the route planning with events
144
145 std::weak_ptr<carla::client::detail::Simulator> _simulator;
146
147 mutable std::mutex _mutex;
148
149 float _probability_crossing { 0.0f };
150
151 /// assign a filter index to an agent
152 void SetAgentFilter(int agent_index, int filter_index);
153 };
154
155} // namespace nav
156} // namespace carla
Inherit (privately) to suppress copy/move construction and assignment.
Represents the state of all the actors of an episode at a given frame.
Manage the pedestrians navigation, using the Recast & Detour library for low level calculations.
Definition Navigation.h:57
bool SetWalkerMaxSpeed(ActorId id, float max_speed)
set new max speed
void UpdateCrowd(const client::detail::EpisodeState &state)
update all walkers in crowd
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
void SetAgentFilter(int agent_index, int filter_index)
assign a filter index to an agent
std::unordered_map< ActorId, int > _mapped_vehicles_id
Definition Navigation.h:133
std::unordered_map< ActorId, int > _mapped_walkers_id
mapping Id
Definition Navigation.h:132
bool RemoveAgent(ActorId id)
remove an agent
std::weak_ptr< carla::client::detail::Simulator > _simulator
Definition Navigation.h:145
bool GetWalkerPosition(ActorId id, carla::geom::Location &location)
get the walker current location
float GetWalkerSpeed(ActorId id)
get the walker current transform
bool Load(const std::string &filename)
load navigation data
bool SetWalkerTarget(ActorId id, carla::geom::Location to)
set a new target point to go through a route with events
void SetSeed(unsigned int seed)
set the seed to use with random numbers
dtNavMesh * _nav_mesh
meshes
Definition Navigation.h:127
bool UpdateVehicles(std::vector< VehicleCollisionInfo > vehicles)
add/update/delete vehicles in crowd
std::unordered_map< int, ActorId > _mapped_by_index
Definition Navigation.h:135
bool SetWalkerDirectTarget(ActorId id, carla::geom::Location to)
bool SetWalkerLookAt(ActorId id, carla::geom::Location location)
make agent look at some location
void PauseAgent(ActorId id, bool pause)
set an agent as paused for the crowd
bool HasVehicleNear(ActorId id, float distance, carla::geom::Location direction)
return if the agent has a vehicle near (as neighbour)
bool GetWalkerTransform(ActorId id, carla::geom::Transform &trans)
get the walker current transform
bool GetRandomLocation(carla::geom::Location &location, dtQueryFilter *filter=nullptr) const
get a random location for navigation
bool IsWalkerAlive(ActorId id, bool &alive)
return if the agent has been killed by a vehicle
WalkerManager _walker_manager
walker manager for the route planning with events
Definition Navigation.h:143
bool GetAgentRoute(ActorId id, carla::geom::Location from, carla::geom::Location to, std::vector< carla::geom::Location > &path, std::vector< unsigned char > &area)
void SetPedestriansCrossFactor(float percentage)
set the probability that an agent could cross the roads in its path following
std::unordered_map< ActorId, float > _yaw_walkers
store walkers yaw angle from previous tick
Definition Navigation.h:137
dtCrowd * _crowd
crowd
Definition Navigation.h:130
bool AddWalker(ActorId id, carla::geom::Location from)
create a new walker
std::vector< uint8_t > _binary_mesh
Definition Navigation.h:124
double GetDeltaSeconds()
return the last delta seconds
Definition Navigation.h:119
bool SetWalkerDirectTargetIndex(int index, carla::geom::Location to)
void SetSimulator(std::weak_ptr< carla::client::detail::Simulator > simulator)
reference to the simulator to access API functions
dtNavMeshQuery * _nav_query
Definition Navigation.h:128
void CreateCrowd(void)
create the crowd object
bool AddOrUpdateVehicle(VehicleCollisionInfo &vehicle)
create a new vehicle in crowd to be avoided by walkers
std::unordered_map< int, carla::geom::Vector3D > _walkers_blocked_position
saves the position of each actor at intervals and check if any is blocked
Definition Navigation.h:139
@ CARLA_AREA_CROSSWALK
Definition Navigation.h:29
@ CARLA_AREA_SIDEWALK
Definition Navigation.h:28
@ CARLA_AREA_GRASS
Definition Navigation.h:31
@ CARLA_AREA_BLOCK
Definition Navigation.h:27
@ CARLA_AREA_ROAD
Definition Navigation.h:30
@ CARLA_TYPE_CROSSWALK
Definition Navigation.h:38
@ CARLA_TYPE_GRASS
Definition Navigation.h:40
@ CARLA_TYPE_WALKABLE
Definition Navigation.h:43
@ CARLA_TYPE_SIDEWALK
Definition Navigation.h:37
@ CARLA_TYPE_NONE
Definition Navigation.h:36
@ CARLA_TYPE_ROAD
Definition Navigation.h:39
uint32_t ActorId
Definition ActorId.h:14
This file contains definitions of common data structures used in traffic manager.
Definition Carla.cpp:133
rpc::ActorId ActorId
Definition ActorId.h:18
struct to send info about vehicles to the crowd
Definition Navigation.h:47
carla::geom::BoundingBox bounding
Definition Navigation.h:50
carla::geom::Transform transform
Definition Navigation.h:49