CARLA
Loading...
Searching...
No Matches
Parameters.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 <atomic>
10#include <chrono>
11#include <random>
12#include <unordered_map>
13
14#include "carla/client/Actor.h"
16#include "carla/Memory.h"
17#include "carla/rpc/ActorId.h"
18
21
22namespace carla {
23namespace traffic_manager {
24
25namespace cc = carla::client;
26namespace cg = carla::geom;
29using Path = std::vector<cg::Location>;
30using Route = std::vector<uint8_t>;
31
33 bool change_lane = false;
34 bool direction = false;
35};
36
38
39private:
40 /// Target velocity map for individual vehicles, based on a % diffrerence from speed limit.
42 /// Lane offset map for individual vehicles.
44 /// Target velocity map for individual vehicles, based on a desired velocity.
46 /// Global target velocity limit % difference.
48 /// Global lane offset
50 /// Per-vehicle enable flag for the large-vehicle wide-turn manoeuvre.
52 /// Global enable flag for the large-vehicle wide-turn manoeuvre.
54 /// Map containing a set of actors to be ignored during collision detection.
56 /// Map containing distance to leading vehicle command.
58 /// Map containing force lane change commands.
60 /// Map containing auto lane change commands.
62 /// Map containing % of running a traffic light.
64 /// Map containing % of running a traffic sign.
66 /// Map containing % of ignoring walkers.
68 /// Map containing % of ignoring vehicles.
70 /// Map containing % of keep slow lane rule.
72 /// Map containing % of random left lane change.
74 /// Map containing % of random right lane change.
76 /// Map containing the automatic vehicle lights update flag
78 /// Synchronous mode switch.
79 std::atomic<bool> synchronous_mode{false};
80 /// Distance margin
81 std::atomic<float> distance_margin{2.0};
82 /// Hybrid physics mode switch.
83 std::atomic<bool> hybrid_physics_mode{false};
84 /// Automatic respawn mode switch.
85 std::atomic<bool> respawn_dormant_vehicles{false};
86 /// Minimum distance to respawn vehicles with respect to the hero vehicle.
87 std::atomic<float> respawn_lower_bound{100.0};
88 /// Maximum distance to respawn vehicles with respect to the hero vehicle.
89 std::atomic<float> respawn_upper_bound{1000.0};
90 /// Minimum possible distance to respawn vehicles with respect to the hero vehicle.
92 /// Maximum possible distance to respawn vehicles with respect to the hero vehicle.
94 /// Hybrid physics radius.
95 std::atomic<float> hybrid_physics_radius {70.0};
96 /// Parameter specifying Open Street Map mode.
97 std::atomic<bool> osm_mode {true};
98 /// Parameter specifying if importing a custom path.
100 /// Structure to hold all custom paths.
102 /// Parameter specifying if importing a custom route.
104 /// Structure to hold all custom routes.
106
107public:
108 Parameters();
109 ~Parameters();
110
111 ////////////////////////////////// SETTERS /////////////////////////////////////
112
113 /// Set a vehicle's % decrease in velocity with respect to the speed limit.
114 /// If less than 0, it's a % increase.
115 void SetPercentageSpeedDifference(const ActorPtr &actor, const float percentage);
116
117 /// Method to set a lane offset displacement from the center line.
118 /// Positive values imply a right offset while negative ones mean a left one.
119 void SetLaneOffset(const ActorPtr &actor, const float offset);
120
121 /// Set a vehicle's exact desired velocity.
122 void SetDesiredSpeed(const ActorPtr &actor, const float value);
123
124 /// Set a global % decrease in velocity with respect to the speed limit.
125 /// If less than 0, it's a % increase.
126 void SetGlobalPercentageSpeedDifference(float const percentage);
127
128 /// Method to set a global lane offset displacement from the center line.
129 /// Positive values imply a right offset while negative ones mean a left one.
130 void SetGlobalLaneOffset(float const offset);
131
132 /// Method to enable/disable the wide-turn manoeuvre for a single large
133 /// vehicle (bus/truck). Enabled by default.
134 void SetLargeVehicleWideTurn(const ActorPtr &actor, const bool enable);
135
136 /// Method to enable/disable the wide-turn manoeuvre globally for all large
137 /// vehicles. Enabled by default.
138 void SetGlobalLargeVehicleWideTurn(const bool enable);
139
140 /// Method to set collision detection rules between vehicles.
142 const ActorPtr &reference_actor,
143 const ActorPtr &other_actor,
144 const bool detect_collision);
145
146 /// Method to force lane change on a vehicle.
147 /// Direction flag can be set to true for left and false for right.
148 void SetForceLaneChange(const ActorPtr &actor, const bool direction);
149
150 /// Enable/disable automatic lane change on a vehicle.
151 void SetAutoLaneChange(const ActorPtr &actor, const bool enable);
152
153 /// Method to specify how much distance a vehicle should maintain to
154 /// the leading vehicle.
155 void SetDistanceToLeadingVehicle(const ActorPtr &actor, const float distance);
156
157 /// Method to set % to run any traffic sign.
158 void SetPercentageRunningSign(const ActorPtr &actor, const float perc);
159
160 /// Method to set % to run any traffic light.
161 void SetPercentageRunningLight(const ActorPtr &actor, const float perc);
162
163 /// Method to set % to ignore any vehicle.
164 void SetPercentageIgnoreVehicles(const ActorPtr &actor, const float perc);
165
166 /// Method to set % to ignore any vehicle.
167 void SetPercentageIgnoreWalkers(const ActorPtr &actor, const float perc);
168
169 /// Method to set % to keep on the slow lane.
170 void SetKeepSlowLanePercentage(const ActorPtr &actor, const float percentage);
171
172 /// Method to set % to randomly do a left lane change.
173 void SetRandomLeftLaneChangePercentage(const ActorPtr &actor, const float percentage);
174
175 /// Method to set % to randomly do a right lane change.
176 void SetRandomRightLaneChangePercentage(const ActorPtr &actor, const float percentage);
177
178 /// Method to set the automatic vehicle light state update flag.
179 void SetUpdateVehicleLights(const ActorPtr &actor, const bool do_update);
180
181 /// Method to set the distance to leading vehicle for all registered vehicles.
182 void SetGlobalDistanceToLeadingVehicle(const float dist);
183
184 /// Set Synchronous mode time out.
185 void SetSynchronousModeTimeOutInMiliSecond(const double time);
186
187 /// Method to set hybrid physics mode.
188 void SetHybridPhysicsMode(const bool mode_switch);
189
190 /// Method to set synchronous mode.
191 void SetSynchronousMode(const bool mode_switch = true);
192
193 /// Method to set hybrid physics radius.
194 void SetHybridPhysicsRadius(const float radius);
195
196 /// Method to set Open Street Map mode.
197 void SetOSMMode(const bool mode_switch);
198
199 /// Method to set if we are automatically respawning vehicles.
200 void SetRespawnDormantVehicles(const bool mode_switch);
201
202 /// Method to set boundaries for respawning vehicles.
203 void SetBoundariesRespawnDormantVehicles(const float lower_bound, const float upper_bound);
204
205 /// Method to set limits for boundaries when respawning vehicles.
206 void SetMaxBoundaries(const float lower, const float upper);
207
208 /// Method to set our own imported path.
209 void SetCustomPath(const ActorPtr &actor, const Path path, const bool empty_buffer);
210
211 /// Method to remove a list of points.
212 void RemoveUploadPath(const ActorId &actor_id, const bool remove_path);
213
214 /// Method to update an already set list of points.
215 void UpdateUploadPath(const ActorId &actor_id, const Path path);
216
217 /// Method to set our own imported route.
218 void SetImportedRoute(const ActorPtr &actor, const Route route, const bool empty_buffer);
219
220 /// Method to remove a route.
221 void RemoveImportedRoute(const ActorId &actor_id, const bool remove_path);
222
223 /// Method to update an already set route.
224 void UpdateImportedRoute(const ActorId &actor_id, const Route route);
225
226 ///////////////////////////////// GETTERS /////////////////////////////////////
227
228 /// Method to retrieve hybrid physics radius.
229 float GetHybridPhysicsRadius() const;
230
231 /// Method to query target velocity for a vehicle.
232 float GetVehicleTargetVelocity(const ActorId &actor_id, const float speed_limit) const;
233
234 /// Method to query lane offset for a vehicle.
235 float GetLaneOffset(const ActorId &actor_id) const;
236
237 /// Method to query whether the wide-turn manoeuvre is enabled for a large
238 /// vehicle (per-vehicle override, otherwise the global flag).
239 bool GetLargeVehicleWideTurn(const ActorId &actor_id) const;
240
241 /// Method to query collision avoidance rule between a pair of vehicles.
242 bool GetCollisionDetection(const ActorId &reference_actor_id, const ActorId &other_actor_id) const;
243
244 /// Method to query lane change command for a vehicle.
246
247 /// Method to query percentage probability of keep slow lane rule for a vehicle.
248 float GetKeepSlowLanePercentage(const ActorId &actor_id);
249
250 /// Method to query percentage probability of a random right lane change for a vehicle.
251 float GetRandomLeftLaneChangePercentage(const ActorId &actor_id);
252
253 /// Method to query percentage probability of a random left lane change for a vehicle.
254 float GetRandomRightLaneChangePercentage(const ActorId &actor_id);
255
256 /// Method to query auto lane change rule for a vehicle.
257 bool GetAutoLaneChange(const ActorId &actor_id) const;
258
259 /// Method to query distance to leading vehicle for a given vehicle.
260 float GetDistanceToLeadingVehicle(const ActorId &actor_id) const;
261
262 /// Method to get % to run any traffic light.
263 float GetPercentageRunningSign(const ActorId &actor_id) const;
264
265 /// Method to get % to run any traffic light.
266 float GetPercentageRunningLight(const ActorId &actor_id) const;
267
268 /// Method to get % to ignore any vehicle.
269 float GetPercentageIgnoreVehicles(const ActorId &actor_id) const;
270
271 /// Method to get % to ignore any walker.
272 float GetPercentageIgnoreWalkers(const ActorId &actor_id) const;
273
274 /// Method to get if the vehicle lights should be updates automatically
275 bool GetUpdateVehicleLights(const ActorId &actor_id) const;
276
277 /// Method to get synchronous mode.
278 bool GetSynchronousMode() const;
279
280 /// Get synchronous mode time out
282
283 /// Method to retrieve hybrid physics mode.
284 bool GetHybridPhysicsMode() const;
285
286 /// Method to retrieve if we are automatically respawning vehicles.
287 bool GetRespawnDormantVehicles() const;
288
289 /// Method to retrieve minimum distance from hero vehicle when respawning vehicles.
291
292 /// Method to retrieve maximum distance from hero vehicle when respawning vehicles.
294
295 /// Method to get Open Street Map mode.
296 bool GetOSMMode() const;
297
298 /// Method to get if we are uploading a path.
299 bool GetUploadPath(const ActorId &actor_id) const;
300
301 /// Method to get a custom path.
302 Path GetCustomPath(const ActorId &actor_id) const;
303
304 /// Method to get if we are uploading a route.
305 bool GetUploadRoute(const ActorId &actor_id) const;
306
307 /// Method to get a custom route.
308 Route GetImportedRoute(const ActorId &actor_id) const;
309
310 /// Synchronous mode time out variable.
311 std::chrono::duration<double, std::milli> synchronous_time_out;
312};
313
314} // namespace traffic_manager
315} // namespace carla
float distance
float GetRandomLeftLaneChangePercentage(const ActorId &actor_id)
Method to query percentage probability of a random right lane change for a vehicle.
void SetGlobalLargeVehicleWideTurn(const bool enable)
Method to enable/disable the wide-turn manoeuvre globally for all large vehicles.
std::atomic< float > respawn_lower_bound
Minimum distance to respawn vehicles with respect to the hero vehicle.
Definition Parameters.h:87
float GetPercentageIgnoreWalkers(const ActorId &actor_id) const
Method to get % to ignore any walker.
AtomicMap< ActorId, ChangeLaneInfo > force_lane_change
Map containing force lane change commands.
Definition Parameters.h:59
ChangeLaneInfo GetForceLaneChange(const ActorId &actor_id)
Method to query lane change command for a vehicle.
AtomicMap< ActorId, bool > auto_lane_change
Map containing auto lane change commands.
Definition Parameters.h:61
bool GetLargeVehicleWideTurn(const ActorId &actor_id) const
Method to query whether the wide-turn manoeuvre is enabled for a large vehicle (per-vehicle override,...
float GetLaneOffset(const ActorId &actor_id) const
Method to query lane offset for a vehicle.
AtomicMap< ActorId, bool > upload_path
Parameter specifying if importing a custom path.
Definition Parameters.h:99
void SetLaneOffset(const ActorPtr &actor, const float offset)
Method to set a lane offset displacement from the center line.
float GetDistanceToLeadingVehicle(const ActorId &actor_id) const
Method to query distance to leading vehicle for a given vehicle.
void SetKeepSlowLanePercentage(const ActorPtr &actor, const float percentage)
Method to set % to keep on the slow lane.
void SetImportedRoute(const ActorPtr &actor, const Route route, const bool empty_buffer)
Method to set our own imported route.
bool GetCollisionDetection(const ActorId &reference_actor_id, const ActorId &other_actor_id) const
Method to query collision avoidance rule between a pair of vehicles.
void SetHybridPhysicsRadius(const float radius)
Method to set hybrid physics radius.
Route GetImportedRoute(const ActorId &actor_id) const
Method to get a custom route.
float global_lane_offset
Global lane offset.
Definition Parameters.h:49
float global_percentage_difference_from_limit
Global target velocity limit % difference.
Definition Parameters.h:47
std::atomic< bool > synchronous_mode
Synchronous mode switch.
Definition Parameters.h:79
float GetKeepSlowLanePercentage(const ActorId &actor_id)
Method to query percentage probability of keep slow lane rule for a vehicle.
double GetSynchronousModeTimeOutInMiliSecond() const
Get synchronous mode time out.
std::atomic< float > distance_margin
Distance margin.
Definition Parameters.h:81
std::chrono::duration< double, std::milli > synchronous_time_out
Synchronous mode time out variable.
Definition Parameters.h:311
std::atomic< float > hybrid_physics_radius
Hybrid physics radius.
Definition Parameters.h:95
bool GetUploadRoute(const ActorId &actor_id) const
Method to get if we are uploading a route.
AtomicMap< ActorId, bool > large_vehicle_wide_turn
Per-vehicle enable flag for the large-vehicle wide-turn manoeuvre.
Definition Parameters.h:51
void UpdateUploadPath(const ActorId &actor_id, const Path path)
Method to update an already set list of points.
bool GetOSMMode() const
Method to get Open Street Map mode.
void SetRandomLeftLaneChangePercentage(const ActorPtr &actor, const float percentage)
Method to set % to randomly do a left lane change.
void SetGlobalDistanceToLeadingVehicle(const float dist)
Method to set the distance to leading vehicle for all registered vehicles.
AtomicMap< ActorId, float > perc_random_left
Map containing % of random left lane change.
Definition Parameters.h:73
AtomicMap< ActorId, float > perc_ignore_walkers
Map containing % of ignoring walkers.
Definition Parameters.h:67
float GetHybridPhysicsRadius() const
Method to retrieve hybrid physics radius.
void UpdateImportedRoute(const ActorId &actor_id, const Route route)
Method to update an already set route.
float GetVehicleTargetVelocity(const ActorId &actor_id, const float speed_limit) const
Method to query target velocity for a vehicle.
void SetGlobalLaneOffset(float const offset)
Method to set a global lane offset displacement from the center line.
AtomicMap< ActorId, float > exact_desired_speed
Target velocity map for individual vehicles, based on a desired velocity.
Definition Parameters.h:45
AtomicMap< ActorId, bool > upload_route
Parameter specifying if importing a custom route.
Definition Parameters.h:103
bool GetUploadPath(const ActorId &actor_id) const
Method to get if we are uploading a path.
float min_lower_bound
Minimum possible distance to respawn vehicles with respect to the hero vehicle.
Definition Parameters.h:91
void SetDistanceToLeadingVehicle(const ActorPtr &actor, const float distance)
Method to specify how much distance a vehicle should maintain to the leading vehicle.
float GetUpperBoundaryRespawnDormantVehicles() const
Method to retrieve maximum distance from hero vehicle when respawning vehicles.
float GetRandomRightLaneChangePercentage(const ActorId &actor_id)
Method to query percentage probability of a random left lane change for a vehicle.
void SetForceLaneChange(const ActorPtr &actor, const bool direction)
Method to force lane change on a vehicle.
AtomicMap< ActorId, float > perc_run_traffic_light
Map containing % of running a traffic light.
Definition Parameters.h:63
float GetLowerBoundaryRespawnDormantVehicles() const
Method to retrieve minimum distance from hero vehicle when respawning vehicles.
void SetPercentageRunningSign(const ActorPtr &actor, const float perc)
Method to set % to run any traffic sign.
void SetCustomPath(const ActorPtr &actor, const Path path, const bool empty_buffer)
Method to set our own imported path.
std::atomic< bool > hybrid_physics_mode
Hybrid physics mode switch.
Definition Parameters.h:83
void RemoveImportedRoute(const ActorId &actor_id, const bool remove_path)
Method to remove a route.
bool GetAutoLaneChange(const ActorId &actor_id) const
Method to query auto lane change rule for a vehicle.
void SetPercentageIgnoreVehicles(const ActorPtr &actor, const float perc)
Method to set % to ignore any vehicle.
void SetMaxBoundaries(const float lower, const float upper)
Method to set limits for boundaries when respawning vehicles.
void SetSynchronousModeTimeOutInMiliSecond(const double time)
Set Synchronous mode time out.
void SetHybridPhysicsMode(const bool mode_switch)
Method to set hybrid physics mode.
AtomicMap< ActorId, float > perc_random_right
Map containing % of random right lane change.
Definition Parameters.h:75
float GetPercentageRunningSign(const ActorId &actor_id) const
Method to get % to run any traffic light.
void SetCollisionDetection(const ActorPtr &reference_actor, const ActorPtr &other_actor, const bool detect_collision)
Method to set collision detection rules between vehicles.
bool GetRespawnDormantVehicles() const
Method to retrieve if we are automatically respawning vehicles.
AtomicMap< ActorId, std::shared_ptr< AtomicActorSet > > ignore_collision
Map containing a set of actors to be ignored during collision detection.
Definition Parameters.h:55
AtomicMap< ActorId, float > perc_keep_slow_lane
Map containing % of keep slow lane rule.
Definition Parameters.h:71
void SetPercentageRunningLight(const ActorPtr &actor, const float perc)
Method to set % to run any traffic light.
AtomicMap< ActorId, float > perc_run_traffic_sign
Map containing % of running a traffic sign.
Definition Parameters.h:65
void SetRespawnDormantVehicles(const bool mode_switch)
Method to set if we are automatically respawning vehicles.
std::atomic< bool > osm_mode
Parameter specifying Open Street Map mode.
Definition Parameters.h:97
Path GetCustomPath(const ActorId &actor_id) const
Method to get a custom path.
void SetAutoLaneChange(const ActorPtr &actor, const bool enable)
Enable/disable automatic lane change on a vehicle.
AtomicMap< ActorId, float > distance_to_leading_vehicle
Map containing distance to leading vehicle command.
Definition Parameters.h:57
float GetPercentageIgnoreVehicles(const ActorId &actor_id) const
Method to get % to ignore any vehicle.
void SetDesiredSpeed(const ActorPtr &actor, const float value)
Set a vehicle's exact desired velocity.
void RemoveUploadPath(const ActorId &actor_id, const bool remove_path)
Method to remove a list of points.
bool GetSynchronousMode() const
Method to get synchronous mode.
void SetGlobalPercentageSpeedDifference(float const percentage)
Set a global % decrease in velocity with respect to the speed limit.
std::atomic< bool > respawn_dormant_vehicles
Automatic respawn mode switch.
Definition Parameters.h:85
AtomicMap< ActorId, float > lane_offset
Lane offset map for individual vehicles.
Definition Parameters.h:43
void SetPercentageIgnoreWalkers(const ActorPtr &actor, const float perc)
Method to set % to ignore any vehicle.
float GetPercentageRunningLight(const ActorId &actor_id) const
Method to get % to run any traffic light.
bool global_large_vehicle_wide_turn
Global enable flag for the large-vehicle wide-turn manoeuvre.
Definition Parameters.h:53
void SetBoundariesRespawnDormantVehicles(const float lower_bound, const float upper_bound)
Method to set boundaries for respawning vehicles.
bool GetUpdateVehicleLights(const ActorId &actor_id) const
Method to get if the vehicle lights should be updates automatically.
void SetRandomRightLaneChangePercentage(const ActorPtr &actor, const float percentage)
Method to set % to randomly do a right lane change.
void SetPercentageSpeedDifference(const ActorPtr &actor, const float percentage)
Set a vehicle's % decrease in velocity with respect to the speed limit.
AtomicMap< ActorId, bool > auto_update_vehicle_lights
Map containing the automatic vehicle lights update flag.
Definition Parameters.h:77
std::atomic< float > respawn_upper_bound
Maximum distance to respawn vehicles with respect to the hero vehicle.
Definition Parameters.h:89
AtomicMap< ActorId, Route > custom_route
Structure to hold all custom routes.
Definition Parameters.h:105
AtomicMap< ActorId, float > perc_ignore_vehicles
Map containing % of ignoring vehicles.
Definition Parameters.h:69
AtomicMap< ActorId, float > percentage_difference_from_speed_limit
Target velocity map for individual vehicles, based on a % diffrerence from speed limit.
Definition Parameters.h:41
void SetOSMMode(const bool mode_switch)
Method to set Open Street Map mode.
AtomicMap< ActorId, Path > custom_path
Structure to hold all custom paths.
Definition Parameters.h:101
bool GetHybridPhysicsMode() const
Method to retrieve hybrid physics mode.
void SetLargeVehicleWideTurn(const ActorPtr &actor, const bool enable)
Method to enable/disable the wide-turn manoeuvre for a single large vehicle (bus/truck).
void SetSynchronousMode(const bool mode_switch=true)
Method to set synchronous mode.
void SetUpdateVehicleLights(const ActorPtr &actor, const bool do_update)
Method to set the automatic vehicle light state update flag.
float max_upper_bound
Maximum possible distance to respawn vehicles with respect to the hero vehicle.
Definition Parameters.h:93
std::vector< uint8_t > Route
std::vector< cg::Location > Path
carla::SharedPtr< cc::Actor > ActorPtr
This file contains definitions of common data structures used in traffic manager.
std::shared_ptr< T > SharedPtr
Definition Memory.h:15
rpc::ActorId ActorId
Definition ActorId.h:18