CARLA
WalkerManager.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/NonCopyable.h"
10 
12 #include "carla/client/World.h"
13 #include "carla/geom/Location.h"
14 #include "carla/nav/WalkerEvent.h"
15 #include "carla/rpc/ActorId.h"
17 
18 namespace carla {
19 namespace nav {
20 
21  class Navigation;
22 
23  enum WalkerState {
28  };
29 
33  unsigned char areaType;
34  WalkerRoutePoint(WalkerEvent ev, carla::geom::Location loc, unsigned char area) : event(ev), location(loc), areaType(area) {};
35  };
36 
37  struct WalkerInfo {
40  unsigned int currentIndex { 0 };
42  std::vector<WalkerRoutePoint> route;
43  };
44 
45  class WalkerManager : private NonCopyable {
46 
47  public:
48 
49  WalkerManager();
50  ~WalkerManager();
51 
52  /// assign the navigation module
53  void SetNav(Navigation *nav);
54 
55  /// reference to the simulator to access API functions
56  void SetSimulator(std::weak_ptr<carla::client::detail::Simulator> simulator);
57 
58  /// create a new walker route
59  bool AddWalker(ActorId id);
60 
61  /// remove a walker route
62  bool RemoveWalker(ActorId id);
63 
64  /// update all routes
65  bool Update(double delta);
66 
67  /// set a new route from its current position
68  bool SetWalkerRoute(ActorId id);
69  bool SetWalkerRoute(ActorId id, carla::geom::Location to);
70 
71  /// set the next point in the route
72  bool SetWalkerNextPoint(ActorId id);
73 
74  /// get the next point in the route
75  bool GetWalkerNextPoint(ActorId id, carla::geom::Location &location);
76 
77  /// get the point in the route that end current crosswalk
78  bool GetWalkerCrosswalkEnd(ActorId id, carla::geom::Location &location);
79 
80  /// return the navigation object
81  Navigation *GetNavigation() { return _nav; };
82 
83  /// return the trafficlight affecting that position
84  SharedPtr<carla::client::TrafficLight> GetTrafficLightAffecting(carla::geom::Location UnrealPos, float max_distance = -1.0f);
85 
86  private:
87 
88  void GetAllTrafficLightWaypoints();
89 
90  EventResult ExecuteEvent(ActorId id, WalkerInfo &info, double delta);
91 
92  std::unordered_map<ActorId, WalkerInfo> _walkers;
93  std::vector<std::pair<SharedPtr<carla::client::TrafficLight>, carla::geom::Location>> _traffic_lights;
94  Navigation *_nav { nullptr };
95  std::weak_ptr<carla::client::detail::Simulator> _simulator;
96  };
97 
98 } // namespace nav
99 } // namespace carla
std::vector< WalkerRoutePoint > route
Definition: WalkerManager.h:42
rpc::ActorId ActorId
Definition: ActorId.h:18
std::weak_ptr< carla::client::detail::Simulator > _simulator
Definition: WalkerManager.h:95
boost::shared_ptr< T > SharedPtr
Use this SharedPtr (boost::shared_ptr) to keep compatibility with boost::python, but it would be nice...
Definition: Memory.h:20
WalkerRoutePoint(WalkerEvent ev, carla::geom::Location loc, unsigned char area)
Definition: WalkerManager.h:34
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
EventResult
result of an event
Definition: WalkerEvent.h:28
boost::variant2::variant< WalkerEventIgnore, WalkerEventWait, WalkerEventStopAndCheck > WalkerEvent
walker event variant
Definition: WalkerEvent.h:55
std::vector< std::pair< SharedPtr< carla::client::TrafficLight >, carla::geom::Location > > _traffic_lights
Definition: WalkerManager.h:93
Navigation * GetNavigation()
return the navigation object
Definition: WalkerManager.h:81
carla::geom::Location from
Definition: WalkerManager.h:38
std::unordered_map< ActorId, WalkerInfo > _walkers
Definition: WalkerManager.h:92
carla::geom::Location location
Definition: WalkerManager.h:32
carla::geom::Location to
Definition: WalkerManager.h:39
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