CARLA
WalkerNavigation.h
Go to the documentation of this file.
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"
10 #include "carla/nav/Navigation.h"
11 #include "carla/NonCopyable.h"
12 #include "carla/client/Timestamp.h"
13 #include "carla/rpc/ActorId.h"
14 
15 #include <memory>
16 
17 namespace carla {
18 namespace client {
19 namespace 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) {
84  _nav.SetPedestriansCrossFactor(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 
99  struct WalkerHandle {
102  };
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
boost::optional< geom::Location > GetRandomLocation()
bool SetWalkerTarget(ActorId id, const carla::geom::Location to)
void CheckIfWalkerExist(std::vector< WalkerHandle > walkers, const EpisodeState &state)
check a few walkers and if they don&#39;t exist then remove from the crowd
Holds an atomic pointer to a list.
Definition: AtomicList.h:25
WalkerNavigation(std::weak_ptr< Simulator > simulator)
bool AddWalker(ActorId id, carla::geom::Location from)
create a new walker
Definition: Navigation.cpp:473
bool RemoveAgent(ActorId id)
remove an agent
Definition: Navigation.cpp:663
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
Represents the state of all the actors of an episode at a given frame.
Definition: EpisodeState.h:27
bool SetWalkerTarget(ActorId id, carla::geom::Location to)
set a new target point to go through a route with events
Definition: Navigation.cpp:765
void SetPedestriansSeed(unsigned int seed)
bool SetWalkerMaxSpeed(ActorId id, float max_speed)
void UpdateVehiclesInCrowd(std::shared_ptr< Episode > episode, bool show_debug=false)
add/update/delete all vehicles in crowd
carla::ActorId ActorId
void SetPedestriansCrossFactor(float percentage)
set the probability that an agent could cross the roads in its path following
void SetPedestriansCrossFactor(float percentage)
void Tick(std::shared_ptr< Episode > episode)
void AddWalker(ActorId walker_id, carla::geom::Location location)
void UnregisterWalker(ActorId walker_id, ActorId controller_id)
bool GetRandomLocation(carla::geom::Location &location, dtQueryFilter *filter=nullptr) const
get a random location for navigation
void RegisterWalker(ActorId walker_id, ActorId controller_id)
void SetSeed(unsigned int seed)
set the seed to use with random numbers
Definition: Navigation.cpp:78
bool SetWalkerMaxSpeed(ActorId id, float max_speed)
set new max speed
Definition: Navigation.cpp:735
std::weak_ptr< Simulator > _simulator
Inherit (privately) to suppress copy/move construction and assignment.
Manage the pedestrians navigation, using the Recast & Detour library for low level calculations...
Definition: Navigation.h:57