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  /// Method to set a lane offset displacement from the center line.
61  /// Positive values imply a right offset while negative ones mean a left one.
62  void SetLaneOffset(const ActorPtr &actor, const float offset);
63 
64  /// Set a vehicle's exact desired velocity.
65  void SetDesiredSpeed(const ActorPtr &actor, const float value);
66 
67  /// Method to set a global % decrease in velocity with respect to the speed limit.
68  /// If less than 0, it's a % increase.
69  void SetGlobalPercentageSpeedDifference(float const percentage);
70 
71  /// Method to set a global lane offset displacement from the center line.
72  /// Positive values imply a right offset while negative ones mean a left one.
73  void SetGlobalLaneOffset(float const offset);
74 
75  /// Method to set the automatic management of the vehicle lights
76  void SetUpdateVehicleLights(const ActorPtr &actor, const bool do_update);
77 
78  /// Method to set collision detection rules between vehicles.
79  void SetCollisionDetection(const ActorPtr &reference_actor, const ActorPtr &other_actor, const bool detect_collision);
80 
81  /// Method to force lane change on a vehicle.
82  /// Direction flag can be set to true for left and false for right.
83  void SetForceLaneChange(const ActorPtr &actor, const bool direction);
84 
85  /// Enable/disable automatic lane change on a vehicle.
86  void SetAutoLaneChange(const ActorPtr &actor, const bool enable);
87 
88  /// Method to specify how much distance a vehicle should maintain to
89  /// the leading vehicle.
90  void SetDistanceToLeadingVehicle(const ActorPtr &actor, const float distance);
91 
92  /// Method to specify Global Distance
93  void SetGlobalDistanceToLeadingVehicle(const float distance);
94 
95  /// Method to specify the % chance of ignoring collisions with any walker.
96  void SetPercentageIgnoreWalkers(const ActorPtr &actor, const float perc);
97 
98  /// Method to specify the % chance of ignoring collisions with any vehicle.
99  void SetPercentageIgnoreVehicles(const ActorPtr &actor, const float perc);
100 
101  /// Method to specify the % chance of running any traffic light
102  void SetPercentageRunningLight(const ActorPtr &actor, const float perc);
103 
104  /// Method to specify the % chance of running any traffic sign
105  void SetPercentageRunningSign(const ActorPtr &actor, const float perc);
106 
107  /// Method to switch traffic manager into synchronous execution.
108  void SetSynchronousMode(bool mode);
109 
110  /// Method to set Tick timeout for synchronous execution.
111  void SetSynchronousModeTimeOutInMiliSecond(double time);
112 
113  /// Method to set % to keep on the right lane.
114  void SetKeepRightPercentage(const ActorPtr &actor, const float percentage);
115 
116  /// Method to set % to randomly do a left lane change.
117  void SetRandomLeftLaneChangePercentage(const ActorPtr &actor, const float percentage);
118 
119  /// Method to set % to randomly do a right lane change.
120  void SetRandomRightLaneChangePercentage(const ActorPtr &actor, const float percentage);
121 
122  /// Method to set hybrid physics mode.
123  void SetHybridPhysicsMode(const bool mode_switch);
124 
125  /// Method to set hybrid physics radius.
126  void SetHybridPhysicsRadius(const float radius);
127 
128  /// Method to set Open Street Map mode.
129  void SetOSMMode(const bool mode_switch);
130 
131  /// Method to set our own imported path.
132  void SetCustomPath(const ActorPtr &actor, const Path path, const bool empty_buffer);
133 
134  /// Method to remove a path.
135  void RemoveUploadPath(const ActorId &actor_id, const bool remove_path);
136 
137  /// Method to update an already set path.
138  void UpdateUploadPath(const ActorId &actor_id, const Path path);
139 
140  /// Method to set our own imported route.
141  void SetImportedRoute(const ActorPtr &actor, const Route route, const bool empty_buffer);
142 
143  /// Method to remove a route.
144  void RemoveImportedRoute(const ActorId &actor_id, const bool remove_path);
145 
146  /// Method to update an already set route.
147  void UpdateImportedRoute(const ActorId &actor_id, const Route route);
148 
149  /// Method to set automatic respawn of dormant vehicles.
150  void SetRespawnDormantVehicles(const bool mode_switch);
151 
152  // Method to set boundaries to respawn of dormant vehicles.
153  void SetBoundariesRespawnDormantVehicles(const float lower_bound, const float upper_bound);
154 
155  // Method to set boundaries to respawn of dormant vehicles.
156  void SetMaxBoundaries(const float lower, const float upper);
157 
158  virtual void ShutDown();
159 
160  /// Method to get the vehicle's next action.
161  Action GetNextAction(const ActorId &actor_id);
162 
163  /// Method to get the vehicle's action buffer.
164  ActionBuffer GetActionBuffer(const ActorId &actor_id);
165 
166  /// Method to provide synchronous tick
167  bool SynchronousTick();
168 
169  /// Get CARLA episode information.
171 
172  /// Method to check server is alive or not.
173  void HealthCheckRemoteTM();
174 
175  /// Method to set randomization seed.
176  void SetRandomDeviceSeed(const uint64_t seed);
177 
178 private:
179 
180  /// Remote client using the IP and port information it connects to
181  /// as remote RPC traffic manager server.
183 
184  /// CARLA client connection object.
186 
187  std::condition_variable _cv;
188 
189  std::mutex _mutex;
190 
191  bool _keep_alive = true;
192 };
193 
194 } // namespace traffic_manager
195 } // 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 SetLaneOffset(const ActorPtr &actor, const float offset)
Method to set a lane offset displacement from the center line.
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.
void SetGlobalLaneOffset(float const offset)
Method to set a global lane offset displacement from the center line.
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.