CARLA
Loading...
Searching...
No Matches
TrafficManagerLocal.cpp
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#include <algorithm>
8
9#include "carla/Logging.h"
10
12
14
15namespace carla {
16namespace traffic_manager {
17
18using namespace constants::FrameMemory;
19using namespace constants::WorldInfoRefresh;
20
22 std::vector<float> longitudinal_PID_parameters,
23 std::vector<float> longitudinal_highway_PID_parameters,
24 std::vector<float> lateral_PID_parameters,
25 std::vector<float> lateral_highway_PID_parameters,
26 float perc_difference_from_limit,
27 cc::detail::EpisodeProxy &episode_proxy,
28 uint16_t &RPCportTM)
29
30 : longitudinal_PID_parameters(longitudinal_PID_parameters),
31 longitudinal_highway_PID_parameters(longitudinal_highway_PID_parameters),
32 lateral_PID_parameters(lateral_PID_parameters),
33 lateral_highway_PID_parameters(lateral_highway_PID_parameters),
34
35 episode_proxy(episode_proxy),
36 world(cc::World(episode_proxy)),
37
38 localization_stage(LocalizationStage(vehicle_id_list,
39 buffer_map,
40 simulation_state,
41 track_traffic,
42 local_map,
43 large_vehicles,
44 parameters,
45 marked_for_removal,
46 localization_frame,
47 random_device)),
48
49 collision_stage(CollisionStage(vehicle_id_list,
50 simulation_state,
51 buffer_map,
52 track_traffic,
53 parameters,
54 collision_frame,
55 random_device)),
56
57 traffic_light_stage(TrafficLightStage(vehicle_id_list,
58 simulation_state,
59 buffer_map,
60 parameters,
61 world,
62 tl_frame,
63 random_device)),
64
65 motion_plan_stage(MotionPlanStage(vehicle_id_list,
66 simulation_state,
67 parameters,
68 buffer_map,
69 track_traffic,
70 longitudinal_PID_parameters,
71 longitudinal_highway_PID_parameters,
72 lateral_PID_parameters,
73 lateral_highway_PID_parameters,
74 localization_frame,
75 collision_frame,
76 tl_frame,
77 control_frame,
78 random_device,
79 local_map,
80 large_vehicles)),
81
82 vehicle_light_stage(VehicleLightStage(vehicle_id_list,
83 buffer_map,
84 parameters,
85 world,
86 control_frame)),
87
88 alsm(ALSM(registered_vehicles,
89 buffer_map,
90 track_traffic,
91 marked_for_removal,
92 parameters,
93 world,
94 local_map,
95 simulation_state,
96 large_vehicles,
97 localization_stage,
98 collision_stage,
99 traffic_light_stage,
100 motion_plan_stage,
101 vehicle_light_stage)),
102
103 server(TrafficManagerServer(RPCportTM, static_cast<carla::traffic_manager::TrafficManagerBase *>(this))) {
104
105 parameters.SetGlobalPercentageSpeedDifference(perc_difference_from_limit);
106
108
110
111 Start();
112}
113
115 episode_proxy.Lock()->DestroyTrafficManager(server.port());
116 Release();
117}
118
120 const carla::SharedPtr<const cc::Map> world_map = world.GetMap();
121 local_map = std::make_shared<InMemoryMap>(world_map);
122
123 auto files = episode_proxy.Lock()->GetRequiredFiles("TM");
124 if (!files.empty()) {
125 auto content = episode_proxy.Lock()->GetCacheFile(files[0], true);
126 if (content.size() != 0) {
127 if (!local_map->Load(content)) {
128 // The copy in the client's file cache (~/carlaCache) is kept for ever once
129 // downloaded, so a rejected cache is most likely a stale local copy: fetch
130 // the server's current file once and try again before rebuilding from the
131 // OpenDRIVE.
132 log_warning("fetching the Traffic Manager cache", files[0], "from the server again");
133 episode_proxy.Lock()->RequestFile(files[0]);
134 content = episode_proxy.Lock()->GetCacheFile(files[0], false);
135 local_map = std::make_shared<InMemoryMap>(world_map);
136 if (content.size() == 0 || !local_map->Load(content)) {
137 local_map = std::make_shared<InMemoryMap>(world_map);
138 local_map->SetUp();
139 }
140 }
141 } else {
142 log_warning("No InMemoryMap cache found. Setting up local map. This may take a while...");
143 local_map->SetUp();
144 }
145 } else {
146 log_warning("No InMemoryMap cache found. Setting up local map. This may take a while...");
147 local_map->SetUp();
148 }
149}
150
152 run_traffic_manger.store(true);
153
156 tl_frame.reserve(INITIAL_SIZE);
159
160 bool synchronous_mode = parameters.GetSynchronousMode();
161 if (!synchronous_mode) {
162 worker_thread = std::make_unique<std::thread>(&TrafficManagerLocal::Run, this);
163 }
164}
165
167 bool synchronous_mode = parameters.GetSynchronousMode();
168 bool hybrid_physics_mode = parameters.GetHybridPhysicsMode();
169
170 // Skipping velocity update if elapsed time is less than 0.05s in asynchronous, hybrid mode.
171 if (!synchronous_mode && hybrid_physics_mode) {
172 TimePoint current_instance = chr::system_clock::now();
173 chr::duration<float> elapsed_time = current_instance - previous_update_instance;
174 chr::duration<float> time_to_wait = chr::duration<float>(HYBRID_MODE_DT) - elapsed_time;
175 if (time_to_wait > chr::duration<float>(0.0f)) {
176 std::this_thread::sleep_for(time_to_wait);
177 }
178 previous_update_instance = current_instance;
179 }
180
181 // Read from the episode state the client already holds, so no round trip.
183
184 // Stop TM from processing the same frame more than once
185 if (!synchronous_mode) {
186 if (timestamp.frame == last_frame) {
187 std::this_thread::sleep_for(SNAPSHOT_POLL_PERIOD);
188 return;
189 }
190 last_frame = timestamp.frame;
191 }
192
193 if (synchronous_mode ||
195 episode_settings = episode_proxy.Lock()->GetEpisodeSettings();
197 }
199
200 std::unique_lock<std::mutex> registration_lock(registration_mutex);
201 // Updating simulation state, actor life cycle and performing necessary cleanup.
202 alsm.Update();
203
204 // Re-allocating inter-stage communication frames based on changed number of registered vehicles.
205 int current_registered_vehicles_state = registered_vehicles.GetState();
206 unsigned long number_of_vehicles = vehicle_id_list.size();
207 if (registered_vehicles_state != current_registered_vehicles_state || number_of_vehicles != registered_vehicles.Size()) {
209 number_of_vehicles = vehicle_id_list.size();
210
211 // Reserve more space if needed.
212 uint64_t growth_factor = static_cast<uint64_t>(static_cast<float>(number_of_vehicles) * INV_GROWTH_STEP_SIZE);
213 uint64_t new_frame_capacity = INITIAL_SIZE + GROWTH_STEP_SIZE * growth_factor;
214 if (new_frame_capacity > current_reserved_capacity) {
215 localization_frame.reserve(new_frame_capacity);
216 collision_frame.reserve(new_frame_capacity);
217 tl_frame.reserve(new_frame_capacity);
218 control_frame.reserve(new_frame_capacity);
219 }
220
222 }
223
224 // Reset frames for current cycle.
225 localization_frame.clear();
226 localization_frame.resize(number_of_vehicles);
227 collision_frame.clear();
228 collision_frame.resize(number_of_vehicles);
229 tl_frame.clear();
230 tl_frame.resize(number_of_vehicles);
231 control_frame.clear();
232 // Reserve two frames for each vehicle: one for the ApplyVehicleControl command,
233 // and one for the optional SetVehicleLightState command
234 control_frame.reserve(2 * number_of_vehicles);
235 // Resize to accomodate at least all ApplyVehicleControl commands,
236 // that will be inserted by the motion_plan_stage stage.
237 control_frame.resize(number_of_vehicles);
238
239 // Run core operation stages.
240 for (unsigned long index = 0u; index < vehicle_id_list.size(); ++index) {
242 }
243 for (unsigned long index = 0u; index < vehicle_id_list.size(); ++index) {
244 if (!localization_frame[index].localized) {
245 continue;
246 }
247 collision_stage.Update(index);
248 }
250 vehicle_light_stage.UpdateWorldInfo(timestamp.elapsed_seconds, synchronous_mode);
252 for (unsigned long index = 0u; index < vehicle_id_list.size(); ++index) {
253 if (!localization_frame[index].localized) {
254 continue;
255 }
259 }
260
261 // A vehicle skipped above never had its control command written, and the
262 // default-constructed command would reach the server as an empty spawn
263 // request ("Invalid ActorDescription '' (UId=0)"). Drop those slots; the
264 // commands appended past the per-vehicle range (vehicle lights) are kept.
265 const bool any_skipped = std::any_of(
266 localization_frame.begin(),
267 localization_frame.begin() + static_cast<long>(vehicle_id_list.size()),
268 [](const LocalizationData &data) { return !data.localized; });
269 if (any_skipped) {
270 ControlFrame filtered_frame;
271 filtered_frame.reserve(control_frame.size());
272 for (unsigned long index = 0u; index < control_frame.size(); ++index) {
273 if (index < vehicle_id_list.size() && !localization_frame[index].localized) {
274 continue;
275 }
276 filtered_frame.push_back(std::move(control_frame[index]));
277 }
278 control_frame = std::move(filtered_frame);
279 }
280
281 registration_lock.unlock();
282
283 // Sending the current cycle's batch command to the simulator. Synchronous
284 // mode must apply it before the next tick; async waiting costs a server frame.
285 if (synchronous_mode) {
286 episode_proxy.Lock()->ApplyBatchSync(control_frame, false);
287 } else if (!control_frame.empty()) {
288 // An unwaited batch is acknowledged on receipt, not on application, so
289 // periodically waiting is what bounds the queue ahead of the game thread.
291 episode_proxy.Lock()->ApplyBatchSync(control_frame, false);
293 } else {
294 episode_proxy.Lock()->ApplyBatch(control_frame, false);
296 }
297 }
298}
299
302 Step();
303 }
304}
305
308 Step(); // Do one step of TM.
309 }
310 return true;
311}
312
314 run_traffic_manger.store(false);
315
316 // Join regardless of mode, or Start() may overwrite a joinable thread.
317 if (worker_thread) {
318 if (worker_thread->joinable()) {
319 worker_thread->join();
320 }
321 worker_thread.reset();
322 }
323
324 std::unique_lock<std::mutex> registration_lock(registration_mutex);
325 vehicle_id_list.clear();
329 previous_update_instance = chr::system_clock::now();
331
338
339 last_frame = 0;
341 last_settings_update = -std::numeric_limits<double>::infinity();
343
344 buffer_map.clear();
345 localization_frame.clear();
346 collision_frame.clear();
347 tl_frame.clear();
348 control_frame.clear();
349 registration_lock.unlock();
350
351 run_traffic_manger.store(true);
352}
353
355
356 Stop();
357
358 local_map.reset();
359}
360
361void TrafficManagerLocal::Reset(uint64_t episode_id) {
362 // Every client alive in the process reports the change; reset once.
363 if (episode_proxy.GetId() == episode_id) {
364 return;
365 }
366 // Our client may see the change after another one; wait, or we'd reset onto the old episode.
367 auto simulator = episode_proxy.Lock();
368 const auto deadline = std::chrono::steady_clock::now() + simulator->GetNetworkingTimeout().to_chrono();
369 while (simulator->GetCurrentEpisodeId() != episode_id && std::chrono::steady_clock::now() < deadline) {
370 std::this_thread::sleep_for(std::chrono::milliseconds(10));
371 }
372 Release();
373 episode_proxy = simulator->GetCurrentEpisode();
376 Start();
377}
378
379void TrafficManagerLocal::RegisterVehicles(const std::vector<ActorPtr> &vehicle_list) {
380 std::scoped_lock<std::mutex> registration_lock(registration_mutex);
381 registered_vehicles.Insert(vehicle_list);
382 for (auto actor : vehicle_list) {
383 alsm.AddActor(actor);
384 }
385}
386
387void TrafficManagerLocal::UnregisterVehicles(const std::vector<ActorPtr> &actor_list) {
388 std::scoped_lock<std::mutex> registration_lock(registration_mutex);
389 std::vector<ActorId> actor_id_list;
390 for (auto &actor : actor_list) {
391 alsm.RemoveActor(actor->GetId(), true);
392 }
393}
394
395void TrafficManagerLocal::SetPercentageSpeedDifference(const ActorPtr &actor, const float percentage) {
396 parameters.SetPercentageSpeedDifference(actor, percentage);
397}
398
402
403void TrafficManagerLocal::SetLaneOffset(const ActorPtr &actor, const float offset) {
404 parameters.SetLaneOffset(actor, offset);
405}
406
410
411void TrafficManagerLocal::SetLargeVehicleWideTurn(const ActorPtr &actor, const bool enable) {
412 parameters.SetLargeVehicleWideTurn(actor, enable);
413}
414
418
419void TrafficManagerLocal::SetDesiredSpeed(const ActorPtr &actor, const float value) {
420 parameters.SetDesiredSpeed(actor, value);
421}
422
423/// Method to set the automatic management of the vehicle lights
424void TrafficManagerLocal::SetUpdateVehicleLights(const ActorPtr &actor, const bool do_update) {
425 parameters.SetUpdateVehicleLights(actor, do_update);
426}
427
428void TrafficManagerLocal::SetCollisionDetection(const ActorPtr &reference_actor, const ActorPtr &other_actor, const bool detect_collision) {
429 parameters.SetCollisionDetection(reference_actor, other_actor, detect_collision);
430}
431
432void TrafficManagerLocal::SetForceLaneChange(const ActorPtr &actor, const bool direction) {
433 parameters.SetForceLaneChange(actor, direction);
434}
435
436void TrafficManagerLocal::SetAutoLaneChange(const ActorPtr &actor, const bool enable) {
437 parameters.SetAutoLaneChange(actor, enable);
438}
439
443
447
448void TrafficManagerLocal::SetPercentageIgnoreWalkers(const ActorPtr &actor, const float perc) {
450}
451
452void TrafficManagerLocal::SetPercentageIgnoreVehicles(const ActorPtr &actor, const float perc) {
454}
455
456void TrafficManagerLocal::SetPercentageRunningLight(const ActorPtr &actor, const float perc) {
458}
459
460void TrafficManagerLocal::SetPercentageRunningSign(const ActorPtr &actor, const float perc) {
462}
463
464void TrafficManagerLocal::SetKeepSlowLanePercentage(const ActorPtr &actor, const float percentage) {
465 parameters.SetKeepSlowLanePercentage(actor, percentage);
466}
467
468
469void TrafficManagerLocal::SetRandomLeftLaneChangePercentage(const ActorPtr &actor, const float percentage) {
471}
472
473void TrafficManagerLocal::SetRandomRightLaneChangePercentage(const ActorPtr &actor, const float percentage) {
475}
476
477void TrafficManagerLocal::SetHybridPhysicsMode(const bool mode_switch) {
478 parameters.SetHybridPhysicsMode(mode_switch);
479}
480
484
485void TrafficManagerLocal::SetOSMMode(const bool mode_switch) {
486 parameters.SetOSMMode(mode_switch);
487}
488
489void TrafficManagerLocal::SetCustomPath(const ActorPtr &actor, const Path path, const bool empty_buffer) {
490 parameters.SetCustomPath(actor, path, empty_buffer);
491}
492
493void TrafficManagerLocal::RemoveUploadPath(const ActorId &actor_id, const bool remove_path) {
494 parameters.RemoveUploadPath(actor_id, remove_path);
495}
496
497void TrafficManagerLocal::UpdateUploadPath(const ActorId &actor_id, const Path path) {
498 parameters.UpdateUploadPath(actor_id, path);
499}
500
501void TrafficManagerLocal::SetImportedRoute(const ActorPtr &actor, const Route route, const bool empty_buffer) {
502 parameters.SetImportedRoute(actor, route, empty_buffer);
503}
504
505void TrafficManagerLocal::RemoveImportedRoute(const ActorId &actor_id, const bool remove_path) {
506 parameters.RemoveImportedRoute(actor_id, remove_path);
507}
508
509void TrafficManagerLocal::UpdateImportedRoute(const ActorId &actor_id, const Route route) {
510 parameters.UpdateImportedRoute(actor_id, route);
511}
512
515}
516
517void TrafficManagerLocal::SetBoundariesRespawnDormantVehicles(const float lower_bound, const float upper_bound) {
518 parameters.SetBoundariesRespawnDormantVehicles(lower_bound, upper_bound);
519}
520
521void TrafficManagerLocal::SetMaxBoundaries(const float lower, const float upper) {
522 parameters.SetMaxBoundaries(lower, upper);
523}
524
528
532
534 for (auto &elem : tl_to_freeze) {
535 if (!elem->IsFrozen() || elem->GetState() != TLS::Red) {
536 return false;
537 }
538 }
539 return true;
540}
541
543 const bool previously_synchronous = parameters.GetSynchronousMode();
545 if (mode == previously_synchronous) { // Same mode as before, do nothing.
546 return;
547 }
548
549 if (!previously_synchronous) { // Switch from async to synchronous
550 if (worker_thread) {
551 if (worker_thread->joinable()) {
552 worker_thread->join();
553 }
554 worker_thread.reset();
555 }
556 }
557 else { // Switch from synchronous to async, start worker thread again.
558 if (worker_thread) {
559 // A worker thread should not exist while in synchronous mode. Tear it
560 // down before spawning a fresh one so a buggy prior transition does
561 // not leak running threads.
562 log_error("TrafficManagerLocal: worker thread present in synchronous mode; joining before async restart.");
563 if (worker_thread->joinable()) {
564 worker_thread->join();
565 }
566 worker_thread.reset();
567 }
568 worker_thread = std::make_unique<std::thread>(&TrafficManagerLocal::Run, this);
569 }
570}
571
575
579
583
589
590} // namespace traffic_manager
591} // namespace carla
float distance
std::size_t frame
Number of frames elapsed since the simulator was launched.
Definition Timestamp.h:30
double elapsed_seconds
Simulated seconds elapsed since the beginning of the current episode.
Definition Timestamp.h:33
const Timestamp & GetTimestamp() const
Get timestamp of this snapshot.
WorldSnapshot GetSnapshot() const
Return a snapshot of the world at this moment.
Definition World.cpp:114
void ResetAllTrafficLights()
Definition World.cpp:234
SharedPtr< Map > GetMap() const
Return the map that describes this world.
Definition World.cpp:26
SharedPtrType Lock() const
Same as TryLock but never return nullptr.
ALSM: Agent Lifecycle and State Managerment This class has functionality to update the local cache of...
Definition ALSM.h:43
void AddActor(const Actor actor)
Definition ALSM.cpp:412
void RemoveActor(const ActorId actor_id, const bool registered_actor)
Definition ALSM.cpp:438
void Insert(std::vector< ActorPtr > actor_list)
This class has functionality to detect potential collision with a nearby actor.
void Update(const unsigned long index) override
This class has functionality to maintain a horizon of waypoints ahead of the vehicle for it to follow...
ActionBuffer ComputeActionBuffer(const ActorId &actor_id)
Action ComputeNextAction(const ActorId &actor_id)
void Update(const unsigned long index) override
void Update(const unsigned long index)
void SetCycleTimestamp(const cc::Timestamp &timestamp)
Pins one frame for the whole cycle; reading it per vehicle lets a frame land mid-cycle and skews the ...
void SetGlobalLargeVehicleWideTurn(const bool enable)
Method to enable/disable the wide-turn manoeuvre globally for all large vehicles.
void SetLaneOffset(const ActorPtr &actor, const float offset)
Method to set a lane offset displacement from the center line.
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.
void SetHybridPhysicsRadius(const float radius)
Method to set hybrid physics radius.
void UpdateUploadPath(const ActorId &actor_id, const Path path)
Method to update an already set list of points.
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.
void UpdateImportedRoute(const ActorId &actor_id, const Route route)
Method to update an already set route.
void SetGlobalLaneOffset(float const offset)
Method to set a global lane offset displacement from the center line.
void SetDistanceToLeadingVehicle(const ActorPtr &actor, const float distance)
Method to specify how much distance a vehicle should maintain to the leading vehicle.
void SetForceLaneChange(const ActorPtr &actor, const bool direction)
Method to force lane change on a vehicle.
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.
void RemoveImportedRoute(const ActorId &actor_id, const bool remove_path)
Method to remove a route.
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.
void SetCollisionDetection(const ActorPtr &reference_actor, const ActorPtr &other_actor, const bool detect_collision)
Method to set collision detection rules between vehicles.
void SetPercentageRunningLight(const ActorPtr &actor, const float perc)
Method to set % to run any traffic light.
void SetRespawnDormantVehicles(const bool mode_switch)
Method to set if we are automatically respawning vehicles.
void SetAutoLaneChange(const ActorPtr &actor, const bool enable)
Enable/disable automatic lane change on a 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.
void SetPercentageIgnoreWalkers(const ActorPtr &actor, const float perc)
Method to set % to ignore any vehicle.
void SetBoundariesRespawnDormantVehicles(const float lower_bound, const float upper_bound)
Method to set boundaries for respawning vehicles.
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.
void SetOSMMode(const bool mode_switch)
Method to set Open Street Map mode.
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.
This class has functionality for responding to traffic lights and managing entry into non-signalized ...
void Update(const unsigned long index) override
The function of this class is to integrate all the various stages of the traffic manager appropriatel...
void Reset(uint64_t episode_id)
To reset the traffic manager for the episode episode_id.
int registered_vehicles_state
State counter to track changes in registered actors.
LocalizationStage localization_stage
Various stages representing core operations of traffic manager.
TimePoint previous_update_instance
Time instance used to calculate dt in asynchronous mode.
void SetDistanceToLeadingVehicle(const ActorPtr &actor, const float distance)
Method to specify how much distance a vehicle should maintain to the leading vehicle.
void SetLaneOffset(const ActorPtr &actor, const float offset)
Method to set a lane offset displacement from the center line.
AtomicActorSet registered_vehicles
Set of all actors registered with traffic manager.
std::unique_ptr< std::thread > worker_thread
Single worker thread for sequential execution of sub-components.
void SetRespawnDormantVehicles(const bool mode_switch)
Method to set automatic respawn of dormant vehicles.
void SetRandomLeftLaneChangePercentage(const ActorPtr &actor, const float percentage)
Method to set % to randomly do a left lane change.
void SetGlobalPercentageSpeedDifference(float const percentage)
Method to set a global % decrease in velocity with respect to the speed limit.
void SetupLocalMap()
Method to setup InMemoryMap.
carla::client::detail::EpisodeProxy & GetEpisodeProxy()
Get CARLA episode information.
ControlFrame control_frame
Array to hold output data of motion planning.
Parameters parameters
Parameterization object.
std::vector< ActorId > vehicle_id_list
List of vehicles registered with the traffic manager in current update cycle.
bool CheckAllFrozen(TLGroup tl_to_freeze)
Method to check if all traffic lights are frozen in a group.
void UpdateImportedRoute(const ActorId &actor_id, const Route route)
Method to update an already set route.
void SetRandomRightLaneChangePercentage(const ActorPtr &actor, const float percentage)
Method to set % to randomly do a right lane change.
void SetPercentageIgnoreVehicles(const ActorPtr &actor, const float perc)
Method to specify the % chance of ignoring collisions with any vehicle.
BufferMap buffer_map
Structures to hold waypoint buffers for all vehicles.
void SetForceLaneChange(const ActorPtr &actor, const bool direction)
Method to force lane change on a vehicle.
void RemoveImportedRoute(const ActorId &actor_id, const bool remove_path)
Method to remove a route.
void SetKeepSlowLanePercentage(const ActorPtr &actor, const float percentage)
Method to set % to keep on the slow lane.
void SetBoundariesRespawnDormantVehicles(const float lower_bound, const float upper_bound)
Method to set boundaries to respawn of dormant vehicles.
TrackTraffic track_traffic
Object for tracking paths of the traffic vehicles.
TrafficManagerServer server
Traffic manager server instance.
Action GetNextAction(const ActorId &actor_id)
Method to get the vehicle's next action.
void UpdateUploadPath(const ActorId &actor_id, const Path path)
Method to update an already set list of points.
CollisionFrame collision_frame
Array to hold output data of collision avoidance.
rpc::EpisodeSettings episode_settings
Cached episode settings; they only change through world.apply_settings.
void SetHybridPhysicsMode(const bool mode_switch)
Method to set hybrid physics mode.
void SetCustomPath(const ActorPtr &actor, const Path path, const bool empty_buffer)
Method to set our own imported path.
void Run()
Initiates thread to run the TrafficManager sequentially.
TLFrame tl_frame
Array to hold output data of traffic light response.
TrafficManagerLocal(std::vector< float > longitudinal_PID_parameters, std::vector< float > longitudinal_highway_PID_parameters, std::vector< float > lateral_PID_parameters, std::vector< float > lateral_highway_PID_parameters, float perc_decrease_from_limit, cc::detail::EpisodeProxy &episode_proxy, uint16_t &RPCportTM)
Private constructor for singleton lifecycle management.
void SetPercentageRunningLight(const ActorPtr &actor, const float perc)
Method to specify the % chance of running any traffic light.
uint64_t current_reserved_capacity
Variable to keep track of currently reserved array space for frames.
LocalizationFrame localization_frame
Array to hold output data of localization stage.
void SetPercentageRunningSign(const ActorPtr &actor, const float perc)
Method to specify the % chance of running any traffic sign.
void SetCollisionDetection(const ActorPtr &reference_actor, const ActorPtr &other_actor, const bool detect_collision)
Method to set collision detection rules between vehicles.
void SetOSMMode(const bool mode_switch)
Method to set Open Street Map mode.
ActionBuffer GetActionBuffer(const ActorId &actor_id)
Method to get the vehicle's action buffer.
cc::World world
CARLA client and object.
bool SynchronousTick()
Method to provide synchronous tick.
std::vector< ActorId > GetRegisteredVehiclesIDs()
Get list of all registered vehicles.
void SetImportedRoute(const ActorPtr &actor, const Route route, const bool empty_buffer)
Method to set our own imported route.
LocalMapPtr local_map
Pointer to local map cache.
void SetMaxBoundaries(const float lower, const float upper)
Method to set limits for boundaries when respawning dormant vehicles.
void SetPercentageSpeedDifference(const ActorPtr &actor, const float percentage)
Method to set a vehicle's % decrease in velocity with respect to the speed limit.
void SetGlobalLaneOffset(float const offset)
Method to set a global lane offset displacement from the center line.
void SetDesiredSpeed(const ActorPtr &actor, const float value)
Set a vehicle's exact desired velocity.
void SetAutoLaneChange(const ActorPtr &actor, const bool enable)
Enable/disable automatic lane change on a vehicle.
carla::client::detail::EpisodeProxy episode_proxy
CARLA client connection object.
void SetLargeVehicleWideTurn(const ActorPtr &actor, const bool enable)
Method to enable/disable the wide-turn manoeuvre for a single large vehicle.
void SetGlobalDistanceToLeadingVehicle(const float distance)
Method to specify how much distance a vehicle should maintain to the Global leading vehicle.
std::atomic< bool > run_traffic_manger
Switch to turn on / turn off traffic manager.
RandomGenerator random_device
Structure holding random devices per vehicle.
SimulationState simulation_state
Type containing the current state of all actors involved in the simulation.
void RemoveUploadPath(const ActorId &actor_id, const bool remove_path)
Method to remove a list of points.
uint64_t unwaited_control_batches
Starts at the limit so the first batch of an episode is waited for.
void SetPercentageIgnoreWalkers(const ActorPtr &actor, const float perc)
Method to specify the % chance of ignoring collisions with any walker.
void SetUpdateVehicleLights(const ActorPtr &actor, const bool do_update)
Method to set the automatic management of the vehicle lights.
double last_settings_update
Simulation time of the last episode settings refresh.
void RegisterVehicles(const std::vector< ActorPtr > &actor_list)
This method registers a vehicle with the traffic manager.
void UnregisterVehicles(const std::vector< ActorPtr > &actor_list)
This method unregisters a vehicle from traffic manager.
void SetGlobalLargeVehicleWideTurn(const bool enable)
Method to enable/disable the wide-turn manoeuvre globally for large vehicles.
void SetSynchronousMode(bool mode)
Method to switch traffic manager into synchronous execution.
void SetHybridPhysicsRadius(const float radius)
Method to set hybrid physics radius.
void Release()
To release the traffic manager.
void SetRandomDeviceSeed(const uint64_t _seed)
Method to set randomization seed.
void Step()
To do one step of the TrafficManager.
std::mutex registration_mutex
Mutex to prevent vehicle registration during frame array re-allocation.
void SetSynchronousModeTimeOutInMiliSecond(double time)
Method to set Tick timeout for synchronous execution.
This class has functionality for turning on/off the vehicle lights according to the current vehicle s...
void UpdateWorldInfo(const double current_time, const bool synchronous_mode)
Synchronous mode refreshes every step.
void Update(const unsigned long index) override
bool IsRefreshDue(const double now, const double last, const double period)
Also true when the clock jumps backwards (new episode) or on NaN, so an unusable clock refreshes rath...
Definition Constants.h:57
bool IsBatchSyncDue(const uint64_t unwaited_batches, const uint64_t limit)
Definition Constants.h:69
static const std::chrono::milliseconds SNAPSHOT_POLL_PERIOD
Definition Constants.h:53
std::vector< carla::SharedPtr< carla::client::TrafficLight > > TLGroup
std::vector< uint8_t > Route
std::vector< cg::Location > Path
std::pair< RoadOption, WaypointPtr > Action
std::vector< carla::rpc::Command > ControlFrame
chr::time_point< chr::system_clock, chr::nanoseconds > TimePoint
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
static void log_error(Args &&... args)
Definition Logging.h:110
static void log_warning(Args &&... args)
Definition Logging.h:96