CARLA
Loading...
Searching...
No Matches
TrafficManagerRemote.h
Go to the documentation of this file.
1// Copyright (c) 2026 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
18namespace carla {
19namespace traffic_manager {
20
22using Path = std::vector<cg::Location>;
23using 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
30public:
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 for the episode @a episode_id.
42 void Reset(uint64_t episode_id);
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 enable/disable the wide-turn manoeuvre for a single large vehicle.
76 void SetLargeVehicleWideTurn(const ActorPtr &actor, const bool enable);
77
78 /// Method to enable/disable the wide-turn manoeuvre globally for large vehicles.
79 void SetGlobalLargeVehicleWideTurn(const bool enable);
80
81 /// Method to set the automatic management of the vehicle lights
82 void SetUpdateVehicleLights(const ActorPtr &actor, const bool do_update);
83
84 /// Method to set collision detection rules between vehicles.
85 void SetCollisionDetection(const ActorPtr &reference_actor, const ActorPtr &other_actor, const bool detect_collision);
86
87 /// Method to force lane change on a vehicle.
88 /// Direction flag can be set to true for left and false for right.
89 void SetForceLaneChange(const ActorPtr &actor, const bool direction);
90
91 /// Enable/disable automatic lane change on a vehicle.
92 void SetAutoLaneChange(const ActorPtr &actor, const bool enable);
93
94 /// Method to specify how much distance a vehicle should maintain to
95 /// the leading vehicle.
96 void SetDistanceToLeadingVehicle(const ActorPtr &actor, const float distance);
97
98 /// Method to specify Global Distance
100
101 /// Method to specify the % chance of ignoring collisions with any walker.
102 void SetPercentageIgnoreWalkers(const ActorPtr &actor, const float perc);
103
104 /// Method to specify the % chance of ignoring collisions with any vehicle.
105 void SetPercentageIgnoreVehicles(const ActorPtr &actor, const float perc);
106
107 /// Method to specify the % chance of running any traffic light
108 void SetPercentageRunningLight(const ActorPtr &actor, const float perc);
109
110 /// Method to specify the % chance of running any traffic sign
111 void SetPercentageRunningSign(const ActorPtr &actor, const float perc);
112
113 /// Method to switch traffic manager into synchronous execution.
114 void SetSynchronousMode(bool mode);
115
116 /// Method to set Tick timeout for synchronous execution.
118
119 /// Method to set % to keep on the slow lane.
120 void SetKeepSlowLanePercentage(const ActorPtr &actor, const float percentage);
121
122 /// Method to set % to randomly do a left lane change.
123 void SetRandomLeftLaneChangePercentage(const ActorPtr &actor, const float percentage);
124
125 /// Method to set % to randomly do a right lane change.
126 void SetRandomRightLaneChangePercentage(const ActorPtr &actor, const float percentage);
127
128 /// Method to set hybrid physics mode.
129 void SetHybridPhysicsMode(const bool mode_switch);
130
131 /// Method to set hybrid physics radius.
132 void SetHybridPhysicsRadius(const float radius);
133
134 /// Method to set Open Street Map mode.
135 void SetOSMMode(const bool mode_switch);
136
137 /// Method to set our own imported path.
138 void SetCustomPath(const ActorPtr &actor, const Path path, const bool empty_buffer);
139
140 /// Method to remove a path.
141 void RemoveUploadPath(const ActorId &actor_id, const bool remove_path);
142
143 /// Method to update an already set path.
144 void UpdateUploadPath(const ActorId &actor_id, const Path path);
145
146 /// Method to set our own imported route.
147 void SetImportedRoute(const ActorPtr &actor, const Route route, const bool empty_buffer);
148
149 /// Method to remove a route.
150 void RemoveImportedRoute(const ActorId &actor_id, const bool remove_path);
151
152 /// Method to update an already set route.
153 void UpdateImportedRoute(const ActorId &actor_id, const Route route);
154
155 /// Method to set automatic respawn of dormant vehicles.
156 void SetRespawnDormantVehicles(const bool mode_switch);
157
158 // Method to set boundaries to respawn of dormant vehicles.
159 void SetBoundariesRespawnDormantVehicles(const float lower_bound, const float upper_bound);
160
161 // Method to set boundaries to respawn of dormant vehicles.
162 void SetMaxBoundaries(const float lower, const float upper);
163
164 virtual void ShutDown();
165
166 /// Method to get the vehicle's next action.
167 Action GetNextAction(const ActorId &actor_id);
168
169 /// Method to get the vehicle's action buffer.
170 ActionBuffer GetActionBuffer(const ActorId &actor_id);
171
172 /// Method to provide synchronous tick
173 bool SynchronousTick();
174
175 /// Get CARLA episode information.
177
178 /// Method to check server is alive or not.
179 void HealthCheckRemoteTM();
180
181 /// Method to set randomization seed.
182 void SetRandomDeviceSeed(const uint64_t seed);
183
184private:
185
186 /// Remote client using the IP and port information it connects to
187 /// as remote RPC traffic manager server.
189
190 /// CARLA client connection object.
192
193 std::condition_variable _cv;
194
195 std::mutex _mutex;
196
197 bool _keep_alive = true;
198};
199
200} // namespace traffic_manager
201} // namespace carla
float distance
The function of this class is to integrate all the various stages of the traffic manager appropriatel...
Provides communication with the rpc of TrafficManagerServer.
The function of this class is to integrate all the various stages of the traffic manager appropriatel...
void SetPercentageIgnoreVehicles(const ActorPtr &actor, const float perc)
Method to specify the % chance of ignoring collisions with any vehicle.
carla::client::detail::EpisodeProxy & GetEpisodeProxy()
Get CARLA episode information.
void SetUpdateVehicleLights(const ActorPtr &actor, const bool do_update)
Method to set the automatic management of the vehicle lights.
void SetGlobalPercentageSpeedDifference(float const percentage)
Method to set a global % decrease in velocity with respect to the speed limit.
void RemoveUploadPath(const ActorId &actor_id, const bool remove_path)
Method to remove a path.
carla::client::detail::EpisodeProxy episodeProxyTM
CARLA client connection object.
void SetCollisionDetection(const ActorPtr &reference_actor, const ActorPtr &other_actor, const bool detect_collision)
Method to set collision detection rules between vehicles.
bool SynchronousTick()
Method to provide synchronous tick.
void UpdateUploadPath(const ActorId &actor_id, const Path path)
Method to update an already set path.
void SetGlobalLaneOffset(float const offset)
Method to set a global lane offset displacement from the center line.
void UnregisterVehicles(const std::vector< ActorPtr > &actor_list)
This method unregisters a vehicle from traffic manager.
void SetLargeVehicleWideTurn(const ActorPtr &actor, const bool enable)
Method to enable/disable the wide-turn manoeuvre for a single large vehicle.
void SetHybridPhysicsMode(const bool mode_switch)
Method to set hybrid physics mode.
void RemoveImportedRoute(const ActorId &actor_id, const bool remove_path)
Method to remove a route.
void RegisterVehicles(const std::vector< ActorPtr > &actor_list)
This method registers a vehicle with the traffic manager.
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's exact desired velocity.
void SetLaneOffset(const ActorPtr &actor, const float offset)
Method to set a lane offset displacement from the center line.
void SetOSMMode(const bool mode_switch)
Method to set Open Street Map mode.
void SetRandomDeviceSeed(const uint64_t seed)
Method to set randomization seed.
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 SetRandomRightLaneChangePercentage(const ActorPtr &actor, const float percentage)
Method to set % to randomly do a right lane change.
void SetGlobalLargeVehicleWideTurn(const bool enable)
Method to enable/disable the wide-turn manoeuvre globally for large vehicles.
void SetRespawnDormantVehicles(const bool mode_switch)
Method to set automatic respawn of dormant vehicles.
TrafficManagerClient client
Remote client using the IP and port information it connects to as remote RPC traffic manager server.
void SetAutoLaneChange(const ActorPtr &actor, const bool enable)
Enable/disable automatic lane change on a vehicle.
void SetBoundariesRespawnDormantVehicles(const float lower_bound, const float upper_bound)
Method to set boundaries for respawning vehicles.
void Reset(uint64_t episode_id)
To reset the traffic manager for the episode episode_id.
void SetImportedRoute(const ActorPtr &actor, const Route route, const bool empty_buffer)
Method to set our own imported route.
void SetPercentageIgnoreWalkers(const ActorPtr &actor, const float perc)
Method to specify the % chance of ignoring collisions with any walker.
Action GetNextAction(const ActorId &actor_id)
Method to get the vehicle's next action.
void SetPercentageRunningLight(const ActorPtr &actor, const float perc)
Method to specify the % chance of running any traffic light.
void SetSynchronousModeTimeOutInMiliSecond(double time)
Method to set Tick timeout for synchronous execution.
ActionBuffer GetActionBuffer(const ActorId &actor_id)
Method to get the vehicle's action buffer.
void SetRandomLeftLaneChangePercentage(const ActorPtr &actor, const float percentage)
Method to set % to randomly do a left lane change.
void SetPercentageSpeedDifference(const ActorPtr &actor, const float percentage)
Method to set a vehicle's % decrease in velocity with respect to the speed limit.
void SetDistanceToLeadingVehicle(const ActorPtr &actor, const float distance)
Method to specify how much distance a vehicle should maintain to the leading vehicle.
void HealthCheckRemoteTM()
Method to check server is alive or not.
void SetPercentageRunningSign(const ActorPtr &actor, const float perc)
Method to specify the % chance of running any traffic sign.
void SetKeepSlowLanePercentage(const ActorPtr &actor, const float percentage)
Method to set % to keep on the slow lane.
void SetSynchronousMode(bool mode)
Method to switch traffic manager into synchronous execution.
void SetForceLaneChange(const ActorPtr &actor, const bool direction)
Method to force lane change on a vehicle.
void SetHybridPhysicsRadius(const float radius)
Method to set hybrid physics radius.
void Release()
To release the traffic manager.
void SetMaxBoundaries(const float lower, const float upper)
Method to set limits for boundaries when respawning vehicles.
std::vector< uint8_t > Route
std::vector< cg::Location > Path
std::pair< RoadOption, WaypointPtr > Action
carla::SharedPtr< cc::Actor > ActorPtr
std::vector< Action > ActionBuffer
This file contains definitions of common data structures used in traffic manager.
std::shared_ptr< T > SharedPtr
Definition Memory.h:15