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"
14 #include "carla/rpc/ActorId.h"
15 
16 #include <memory>
17 
18 namespace carla {
19 namespace client {
20 namespace detail {
21 
22  class Client;
23  class Episode;
24  class EpisodeState;
25 
27  : public std::enable_shared_from_this<WalkerNavigation>,
28  private NonCopyable {
29  public:
30 
31  explicit WalkerNavigation(Client & client);
32 
33  void RegisterWalker(ActorId walker_id, ActorId controller_id) {
34  // add to list
35  _walkers.Push(WalkerHandle { walker_id, controller_id });
36  }
37 
38  void UnregisterWalker(ActorId walker_id, ActorId controller_id) {
39  // remove from list
40  auto list = _walkers.Load();
41  unsigned int i = 0;
42  while (i < list->size()) {
43  if ((*list)[i].walker == walker_id &&
44  (*list)[i].controller == controller_id) {
45  _walkers.DeleteByIndex(i);
46  break;
47  }
48  ++i;
49  }
50  }
51 
52  void RemoveWalker(ActorId walker_id) {
53  // remove the walker in the crowd
54  _nav.RemoveAgent(walker_id);
55  }
56 
57  void AddWalker(ActorId walker_id, carla::geom::Location location) {
58  // create the walker in the crowd (to manage its movement in Detour)
59  _nav.AddWalker(walker_id, location);
60  }
61 
62  void Tick(std::shared_ptr<Episode> episode);
63 
64  // Get Random location in nav mesh
65  boost::optional<geom::Location> GetRandomLocation() {
66  geom::Location random_location(0, 0, 0);
67  if (_nav.GetRandomLocation(random_location))
68  return boost::optional<geom::Location>(random_location);
69  else
70  return {};
71  }
72 
73  // set a new target point to go
75  return _nav.SetWalkerTarget(id, to);
76  }
77 
78  // set new max speed
79  bool SetWalkerMaxSpeed(ActorId id, float max_speed) {
80  return _nav.SetWalkerMaxSpeed(id, max_speed);
81  }
82 
83  // set percentage of pedestrians that can cross the road
84  void SetPedestriansCrossFactor(float percentage) {
85  _nav.SetPedestriansCrossFactor(percentage);
86  }
87 
88  void SetPedestriansSeed(unsigned int seed) {
89  _nav.SetSeed(seed);
90  }
91 
92  private:
93 
95 
96  unsigned long _next_check_index;
97 
99 
100  struct WalkerHandle {
103  };
104 
106 
107  /// check a few walkers and if they don't exist then remove from the crowd
108  void CheckIfWalkerExist(std::vector<WalkerHandle> walkers, const EpisodeState &state);
109  /// add/update/delete all vehicles in crowd
110  void UpdateVehiclesInCrowd(std::shared_ptr<Episode> episode, bool show_debug = false);
111  };
112 
113 } // namespace detail
114 } // namespace client
115 } // 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
bool AddWalker(ActorId id, carla::geom::Location from)
create a new walker
Definition: Navigation.cpp:466
bool RemoveAgent(ActorId id)
remove an agent
Definition: Navigation.cpp:656
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:758
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)
Provides communication with the rpc and streaming servers of a CARLA simulator.
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:71
bool SetWalkerMaxSpeed(ActorId id, float max_speed)
set new max speed
Definition: Navigation.cpp:728
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