CARLA
TrafficManagerRemote.h
Go to the documentation of this file.
1 // Copyright (c) 2020 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 <condition_variable>
10 #include <mutex>
11 #include <vector>
12 
13 #include "carla/client/Actor.h"
17 
18 namespace carla {
19 namespace traffic_manager {
20 
22 using Path = std::vector<cg::Location>;
23 using Route = std::vector<uint8_t>;
24 
25 
26 /// The function of this class is to integrate all the various stages of
27 /// the traffic manager appropriately using messengers.
29 
30 public:
31 
32  /// To start the TrafficManager.
33  void Start();
34 
35  /// To stop the TrafficManager.
36  void Stop();
37 
38  /// To release the traffic manager.
39  void Release();
40 
41  /// To reset the traffic manager.
42  void Reset();
43 
44  /// Constructor store remote location information.
45  TrafficManagerRemote(const std::pair<std::string, uint16_t> &_serverTM, carla::client::detail::EpisodeProxy &episodeProxy);
46 
47  /// Destructor.
48  virtual ~TrafficManagerRemote();
49 
50  /// This method registers a vehicle with the traffic manager.
51  void RegisterVehicles(const std::vector<ActorPtr> &actor_list);
52 
53  /// This method unregisters a vehicle from traffic manager.
54  void UnregisterVehicles(const std::vector<ActorPtr> &actor_list);
55 
56  /// Method to set a vehicle's % decrease in velocity with respect to the speed limit.
57  /// If less than 0, it's a % increase.
58  void SetPercentageSpeedDifference(const ActorPtr &actor, const float percentage);
59 
60  /// Set a vehicle's exact desired velocity.
61  void SetDesiredSpeed(const ActorPtr &actor, const float value);
62 
63  /// Method to set a global % decrease in velocity with respect to the speed limit.
64  /// If less than 0, it's a % increase.
65  void SetGlobalPercentageSpeedDifference(float const percentage);
66 
67  /// Method to set the automatic management of the vehicle lights
68  void SetUpdateVehicleLights(const ActorPtr &actor, const bool do_update);
69 
70  /// Method to set collision detection rules between vehicles.
71  void SetCollisionDetection(const ActorPtr &reference_actor, const ActorPtr &other_actor, const bool detect_collision);
72 
73  /// Method to force lane change on a vehicle.
74  /// Direction flag can be set to true for left and false for right.
75  void SetForceLaneChange(const ActorPtr &actor, const bool direction);
76 
77  /// Enable/disable automatic lane change on a vehicle.
78  void SetAutoLaneChange(const ActorPtr &actor, const bool enable);
79 
80  /// Method to specify how much distance a vehicle should maintain to
81  /// the leading vehicle.
82  void SetDistanceToLeadingVehicle(const ActorPtr &actor, const float distance);
83 
84  /// Method to specify Global Distance
85  void SetGlobalDistanceToLeadingVehicle(const float distance);
86 
87  /// Method to specify the % chance of ignoring collisions with any walker.
88  void SetPercentageIgnoreWalkers(const ActorPtr &actor, const float perc);
89 
90  /// Method to specify the % chance of ignoring collisions with any vehicle.
91  void SetPercentageIgnoreVehicles(const ActorPtr &actor, const float perc);
92 
93  /// Method to specify the % chance of running any traffic light
94  void SetPercentageRunningLight(const ActorPtr &actor, const float perc);
95 
96  /// Method to specify the % chance of running any traffic sign
97  void SetPercentageRunningSign(const ActorPtr &actor, const float perc);
98 
99  /// Method to switch traffic manager into synchronous execution.
100  void SetSynchronousMode(bool mode);
101 
102  /// Method to set Tick timeout for synchronous execution.
103  void SetSynchronousModeTimeOutInMiliSecond(double time);
104 
105  /// Method to set % to keep on the right lane.
106  void SetKeepRightPercentage(const ActorPtr &actor, const float percentage);
107 
108  /// Method to set % to randomly do a left lane change.
109  void SetRandomLeftLaneChangePercentage(const ActorPtr &actor, const float percentage);
110 
111  /// Method to set % to randomly do a right lane change.
112  void SetRandomRightLaneChangePercentage(const ActorPtr &actor, const float percentage);
113 
114  /// Method to set hybrid physics mode.
115  void SetHybridPhysicsMode(const bool mode_switch);
116 
117  /// Method to set hybrid physics radius.
118  void SetHybridPhysicsRadius(const float radius);
119 
120  /// Method to set Open Street Map mode.
121  void SetOSMMode(const bool mode_switch);
122 
123  /// Method to set our own imported path.
124  void SetCustomPath(const ActorPtr &actor, const Path path, const bool empty_buffer);
125 
126  /// Method to remove a path.
127  void RemoveUploadPath(const ActorId &actor_id, const bool remove_path);
128 
129  /// Method to update an already set path.
130  void UpdateUploadPath(const ActorId &actor_id, const Path path);
131 
132  /// Method to set our own imported route.
133  void SetImportedRoute(const ActorPtr &actor, const Route route, const bool empty_buffer);
134 
135  /// Method to remove a route.
136  void RemoveImportedRoute(const ActorId &actor_id, const bool remove_path);
137 
138  /// Method to update an already set route.
139  void UpdateImportedRoute(const ActorId &actor_id, const Route route);
140 
141  /// Method to set automatic respawn of dormant vehicles.
142  void SetRespawnDormantVehicles(const bool mode_switch);
143 
144  // Method to set boundaries to respawn of dormant vehicles.
145  void SetBoundariesRespawnDormantVehicles(const float lower_bound, const float upper_bound);
146 
147  // Method to set boundaries to respawn of dormant vehicles.
148  void SetMaxBoundaries(const float lower, const float upper);
149 
150  virtual void ShutDown();
151 
152  /// Method to get the vehicle's next action.
153  Action GetNextAction(const ActorId &actor_id);
154 
155  /// Method to get the vehicle's action buffer.
156  ActionBuffer GetActionBuffer(const ActorId &actor_id);
157 
158  /// Method to provide synchronous tick
159  bool SynchronousTick();
160 
161  /// Get CARLA episode information.
163 
164  /// Method to check server is alive or not.
165  void HealthCheckRemoteTM();
166 
167  /// Method to set randomization seed.
168  void SetRandomDeviceSeed(const uint64_t seed);
169 
170 private:
171 
172  /// Remote client using the IP and port information it connects to
173  /// as remote RPC traffic manager server.
175 
176  /// CARLA client connection object.
178 
179  std::condition_variable _cv;
180 
181  std::mutex _mutex;
182 
183  bool _keep_alive = true;
184 };
185 
186 } // namespace traffic_manager
187 } // namespace carla
TrafficManagerClient client
Remote client using the IP and port information it connects to as remote RPC traffic manager server...
void SetForceLaneChange(const ActorPtr &actor, const bool direction)
Method to force lane change on a vehicle.
void SetPercentageIgnoreVehicles(const ActorPtr &actor, const float perc)
Method to specify the % chance of ignoring collisions with any vehicle.
void SetAutoLaneChange(const ActorPtr &actor, const bool enable)
Enable/disable automatic lane change on a vehicle.
void SetPercentageRunningSign(const ActorPtr &actor, const float perc)
Method to specify the % chance of running any traffic sign.
void SetHybridPhysicsMode(const bool mode_switch)
Method to set hybrid physics mode.
carla::client::detail::EpisodeProxy episodeProxyTM
CARLA client connection object.
void SetSynchronousModeTimeOutInMiliSecond(double time)
Method to set Tick timeout for synchronous execution.
void UpdateImportedRoute(const ActorId &actor_id, const Route route)
Method to update an already set route.
void SetGlobalDistanceToLeadingVehicle(const float distance)
Method to specify Global Distance.
void Reset()
To reset the traffic manager.
carla::SharedPtr< cc::Actor > ActorPtr
void SetHybridPhysicsRadius(const float radius)
Method to set hybrid physics radius.
void UnregisterVehicles(const std::vector< ActorPtr > &actor_list)
This method unregisters a vehicle from traffic manager.
void SetRespawnDormantVehicles(const bool mode_switch)
Method to set automatic respawn of dormant vehicles.
void SetSynchronousMode(bool mode)
Method to switch traffic manager into synchronous execution.
bool SynchronousTick()
Method to provide synchronous tick.
ActionBuffer GetActionBuffer(const ActorId &actor_id)
Method to get the vehicle&#39;s action buffer.
std::vector< cg::Location > Path
void SetCollisionDetection(const ActorPtr &reference_actor, const ActorPtr &other_actor, const bool detect_collision)
Method to set collision detection rules between vehicles.
Action GetNextAction(const ActorId &actor_id)
Method to get the vehicle&#39;s next action.
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
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
void RegisterVehicles(const std::vector< ActorPtr > &actor_list)
This method registers a vehicle with the traffic manager.
void SetPercentageIgnoreWalkers(const ActorPtr &actor, const float perc)
Method to specify the % chance of ignoring collisions with any walker.
void SetPercentageRunningLight(const ActorPtr &actor, const float perc)
Method to specify the % chance of running any traffic light.
void SetGlobalPercentageSpeedDifference(float const percentage)
Method to set a global % decrease in velocity with respect to the speed limit.
void SetCustomPath(const ActorPtr &actor, const Path path, const bool empty_buffer)
Method to set our own imported path.
void SetDesiredSpeed(const ActorPtr &actor, const float value)
Set a vehicle&#39;s exact desired velocity.
void SetPercentageSpeedDifference(const ActorPtr &actor, const float percentage)
Method to set a vehicle&#39;s % decrease in velocity with respect to the speed limit. ...
void SetUpdateVehicleLights(const ActorPtr &actor, const bool do_update)
Method to set the automatic management of the vehicle lights.
void RemoveUploadPath(const ActorId &actor_id, const bool remove_path)
Method to remove a path.
void SetBoundariesRespawnDormantVehicles(const float lower_bound, const float upper_bound)
Method to set boundaries for respawning vehicles.
void SetImportedRoute(const ActorPtr &actor, const Route route, const bool empty_buffer)
Method to set our own imported route.
void Start()
To start the TrafficManager.
void SetRandomRightLaneChangePercentage(const ActorPtr &actor, const float percentage)
Method to set % to randomly do a right lane change.
std::pair< RoadOption, WaypointPtr > Action
void SetOSMMode(const bool mode_switch)
Method to set Open Street Map mode.
carla::ActorId ActorId
void UpdateUploadPath(const ActorId &actor_id, const Path path)
Method to update an already set path.
The function of this class is to integrate all the various stages of the traffic manager appropriatel...
std::vector< uint8_t > Route
Provides communication with the rpc of TrafficManagerServer.
void SetMaxBoundaries(const float lower, const float upper)
Method to set limits for boundaries when respawning vehicles.
TrafficManagerRemote(const std::pair< std::string, uint16_t > &_serverTM, carla::client::detail::EpisodeProxy &episodeProxy)
Constructor store remote location information.
void SetDistanceToLeadingVehicle(const ActorPtr &actor, const float distance)
Method to specify how much distance a vehicle should maintain to the leading vehicle.
void Release()
To release the traffic manager.
void RemoveImportedRoute(const ActorId &actor_id, const bool remove_path)
Method to remove a route.
The function of this class is to integrate all the various stages of the traffic manager appropriatel...
void SetKeepRightPercentage(const ActorPtr &actor, const float percentage)
Method to set % to keep on the right lane.
void HealthCheckRemoteTM()
Method to check server is alive or not.
std::vector< Action > ActionBuffer
void SetRandomDeviceSeed(const uint64_t seed)
Method to set randomization seed.
carla::client::detail::EpisodeProxy & GetEpisodeProxy()
Get CARLA episode information.
void SetRandomLeftLaneChangePercentage(const ActorPtr &actor, const float percentage)
Method to set % to randomly do a left lane change.