CARLA
 
载入中...
搜索中...
未找到
WalkerNavigation.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"
11#include "carla/NonCopyable.h"
13#include "carla/rpc/ActorId.h"
14
15#include <memory>
16
17namespace carla {
18namespace client {
19namespace detail {
20
21 class Episode;
22 class EpisodeState;
23 class Simulator;
24
26 : public std::enable_shared_from_this<WalkerNavigation>,
27 private NonCopyable {
28 public:
29
30 explicit WalkerNavigation(std::weak_ptr<Simulator> simulator);
31
32 void RegisterWalker(ActorId walker_id, ActorId controller_id) {
33 // add to list
34 _walkers.Push(WalkerHandle { walker_id, controller_id });
35 }
36
37 void UnregisterWalker(ActorId walker_id, ActorId controller_id) {
38 // remove from list
39 auto list = _walkers.Load();
40 unsigned int i = 0;
41 while (i < list->size()) {
42 if ((*list)[i].walker == walker_id &&
43 (*list)[i].controller == controller_id) {
44 _walkers.DeleteByIndex(i);
45 break;
46 }
47 ++i;
48 }
49 }
50
51 void RemoveWalker(ActorId walker_id) {
52 // remove the walker in the crowd
53 _nav.RemoveAgent(walker_id);
54 }
55
56 void AddWalker(ActorId walker_id, carla::geom::Location location) {
57 // create the walker in the crowd (to manage its movement in Detour)
58 _nav.AddWalker(walker_id, location);
59 }
60
61 void Tick(std::shared_ptr<Episode> episode);
62
63 // Get Random location in nav mesh
64 boost::optional<geom::Location> GetRandomLocation() {
65 geom::Location random_location(0, 0, 0);
66 if (_nav.GetRandomLocation(random_location))
67 return boost::optional<geom::Location>(random_location);
68 else
69 return {};
70 }
71
72 // set a new target point to go
74 return _nav.SetWalkerTarget(id, to);
75 }
76
77 // set new max speed
78 bool SetWalkerMaxSpeed(ActorId id, float max_speed) {
79 return _nav.SetWalkerMaxSpeed(id, max_speed);
80 }
81
82 // set percentage of pedestrians that can cross the road
83 void SetPedestriansCrossFactor(float percentage) {
85 }
86
87 void SetPedestriansSeed(unsigned int seed) {
88 _nav.SetSeed(seed);
89 }
90
91 private:
92
93 std::weak_ptr<Simulator> _simulator;
94
95 unsigned long _next_check_index;
96
98
103
105
106 /// check a few walkers and if they don't exist then remove from the crowd
107 void CheckIfWalkerExist(std::vector<WalkerHandle> walkers, const EpisodeState &state);
108 /// add/update/delete all vehicles in crowd
109 void UpdateVehiclesInCrowd(std::shared_ptr<Episode> episode, bool show_debug = false);
110 };
111
112} // namespace detail
113} // namespace client
114} // namespace carla
Inherit (privately) to suppress copy/move construction and assignment.
Holds an atomic pointer to a list.
Definition AtomicList.h:25
Represents the state of all the actors of an episode at a given frame.
boost::optional< geom::Location > GetRandomLocation()
void UpdateVehiclesInCrowd(std::shared_ptr< Episode > episode, bool show_debug=false)
add/update/delete all vehicles in crowd
void SetPedestriansCrossFactor(float percentage)
void RegisterWalker(ActorId walker_id, ActorId controller_id)
bool SetWalkerMaxSpeed(ActorId id, float max_speed)
WalkerNavigation(std::weak_ptr< Simulator > simulator)
std::weak_ptr< Simulator > _simulator
void Tick(std::shared_ptr< Episode > episode)
void CheckIfWalkerExist(std::vector< WalkerHandle > walkers, const EpisodeState &state)
check a few walkers and if they don't exist then remove from the crowd
void AddWalker(ActorId walker_id, carla::geom::Location location)
void UnregisterWalker(ActorId walker_id, ActorId controller_id)
bool SetWalkerTarget(ActorId id, const carla::geom::Location to)
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
bool RemoveAgent(ActorId id)
remove an agent
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
bool GetRandomLocation(carla::geom::Location &location, dtQueryFilter *filter=nullptr) const
get a random location for navigation
void SetPedestriansCrossFactor(float percentage)
set the probability that an agent could cross the roads in its path following
bool AddWalker(ActorId id, carla::geom::Location from)
create a new walker
This file contains definitions of common data structures used in traffic manager.
Definition Carla.cpp:133