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
34
36 world(cc::World(episode_proxy)),
37
48
56
61 world,
64
81
85 world,
87
93 world,
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
154 localization_frame.reserve(INITIAL_SIZE);
155 collision_frame.reserve(INITIAL_SIZE);
156 tl_frame.reserve(INITIAL_SIZE);
157 control_frame.reserve(INITIAL_SIZE);
158 current_reserved_capacity = 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.
182 const carla::client::Timestamp timestamp = world.GetSnapshot().GetTimestamp();
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 std::unique_lock<std::mutex> registration_lock(registration_mutex);
194 // Updating simulation state, actor life cycle and performing necessary cleanup.
195 alsm.Update();
196
197 // Re-allocating inter-stage communication frames based on changed number of registered vehicles.
198 int current_registered_vehicles_state = registered_vehicles.GetState();
199 unsigned long number_of_vehicles = vehicle_id_list.size();
200 if (registered_vehicles_state != current_registered_vehicles_state || number_of_vehicles != registered_vehicles.Size()) {
202 number_of_vehicles = vehicle_id_list.size();
203
204 // Reserve more space if needed.
205 uint64_t growth_factor = static_cast<uint64_t>(static_cast<float>(number_of_vehicles) * INV_GROWTH_STEP_SIZE);
206 uint64_t new_frame_capacity = INITIAL_SIZE + GROWTH_STEP_SIZE * growth_factor;
207 if (new_frame_capacity > current_reserved_capacity) {
208 localization_frame.reserve(new_frame_capacity);
209 collision_frame.reserve(new_frame_capacity);
210 tl_frame.reserve(new_frame_capacity);
211 control_frame.reserve(new_frame_capacity);
212 }
213
215 }
216
217 // Reset frames for current cycle.
218 localization_frame.clear();
219 localization_frame.resize(number_of_vehicles);
220 collision_frame.clear();
221 collision_frame.resize(number_of_vehicles);
222 tl_frame.clear();
223 tl_frame.resize(number_of_vehicles);
224 control_frame.clear();
225 // Reserve two frames for each vehicle: one for the ApplyVehicleControl command,
226 // and one for the optional SetVehicleLightState command
227 control_frame.reserve(2 * number_of_vehicles);
228 // Resize to accomodate at least all ApplyVehicleControl commands,
229 // that will be inserted by the motion_plan_stage stage.
230 control_frame.resize(number_of_vehicles);
231
232 // Run core operation stages.
233 for (unsigned long index = 0u; index < vehicle_id_list.size(); ++index) {
235 }
236 for (unsigned long index = 0u; index < vehicle_id_list.size(); ++index) {
237 if (!localization_frame[index].localized) {
238 continue;
239 }
240 collision_stage.Update(index);
241 }
243 vehicle_light_stage.UpdateWorldInfo(timestamp.elapsed_seconds, synchronous_mode);
245 for (unsigned long index = 0u; index < vehicle_id_list.size(); ++index) {
246 if (!localization_frame[index].localized) {
247 continue;
248 }
252 }
253
254 // A vehicle skipped above never had its control command written, and the
255 // default-constructed command would reach the server as an empty spawn
256 // request ("Invalid ActorDescription '' (UId=0)"). Drop those slots; the
257 // commands appended past the per-vehicle range (vehicle lights) are kept.
258 const bool any_skipped = std::any_of(
259 localization_frame.begin(),
260 localization_frame.begin() + static_cast<long>(vehicle_id_list.size()),
261 [](const LocalizationData &data) { return !data.localized; });
262 if (any_skipped) {
263 ControlFrame filtered_frame;
264 filtered_frame.reserve(control_frame.size());
265 for (unsigned long index = 0u; index < control_frame.size(); ++index) {
266 if (index < vehicle_id_list.size() && !localization_frame[index].localized) {
267 continue;
268 }
269 filtered_frame.push_back(std::move(control_frame[index]));
270 }
271 control_frame = std::move(filtered_frame);
272 }
273
274 registration_lock.unlock();
275
276 // Sending the current cycle's batch command to the simulator. Synchronous
277 // mode must apply it before the next tick; async waiting costs a server frame.
278 if (synchronous_mode) {
279 episode_proxy.Lock()->ApplyBatchSync(control_frame, false);
280 } else if (!control_frame.empty()) {
281 // An unwaited batch is acknowledged on receipt, not on application, so
282 // periodically waiting is what bounds the queue ahead of the game thread.
283 if (IsBatchSyncDue(unwaited_control_batches, MAX_UNWAITED_CONTROL_BATCHES)) {
284 episode_proxy.Lock()->ApplyBatchSync(control_frame, false);
286 } else {
287 episode_proxy.Lock()->ApplyBatch(control_frame, false);
289 }
290 }
291}
292
295 Step();
296 // No TM lock held here: drop released vehicles.
298 }
299}
300
303 Step(); // Do one step of TM.
304 }
305 return true;
306}
307
309 run_traffic_manger.store(false);
310
311 // Join regardless of mode, or Start() may overwrite a joinable thread.
312 if (worker_thread) {
313 if (worker_thread->joinable()) {
314 worker_thread->join();
315 }
316 worker_thread.reset();
317 }
318
319 std::unique_lock<std::mutex> registration_lock(registration_mutex);
320 vehicle_id_list.clear();
324 previous_update_instance = chr::system_clock::now();
326
333
334 last_frame = 0;
335 unwaited_control_batches = MAX_UNWAITED_CONTROL_BATCHES;
336
337 buffer_map.clear();
338 localization_frame.clear();
339 collision_frame.clear();
340 tl_frame.clear();
341 control_frame.clear();
342 registration_lock.unlock();
343
344 run_traffic_manger.store(true);
345}
346
348
349 Stop();
350
351 local_map.reset();
352}
353
354void TrafficManagerLocal::Reset(uint64_t episode_id) {
355 // Every client alive in the process reports the change; reset once.
356 if (episode_proxy.GetId() == episode_id) {
357 return;
358 }
359 // Our client may see the change after another one; wait, or we'd reset onto the old episode.
360 auto simulator = episode_proxy.Lock();
361 const auto deadline = std::chrono::steady_clock::now() + simulator->GetNetworkingTimeout().to_chrono();
362 while (simulator->GetCurrentEpisodeId() != episode_id && std::chrono::steady_clock::now() < deadline) {
363 std::this_thread::sleep_for(std::chrono::milliseconds(10));
364 }
365 Release();
366 episode_proxy = simulator->GetCurrentEpisode();
367 world = cc::World(episode_proxy);
369 Start();
370}
371
372void TrafficManagerLocal::RegisterVehicles(const std::vector<ActorPtr> &vehicle_list) {
373 std::scoped_lock<std::mutex> registration_lock(registration_mutex);
374 registered_vehicles.Insert(vehicle_list);
375 for (auto actor : vehicle_list) {
376 alsm.AddActor(actor);
377 }
378}
379
380void TrafficManagerLocal::UnregisterVehicles(const std::vector<ActorPtr> &actor_list) {
381 std::scoped_lock<std::mutex> registration_lock(registration_mutex);
382 std::vector<ActorId> actor_id_list;
383 for (auto &actor : actor_list) {
384 alsm.RemoveActor(actor->GetId(), true);
385 }
386}
387
388void TrafficManagerLocal::SetPercentageSpeedDifference(const ActorPtr &actor, const float percentage) {
389 parameters.SetPercentageSpeedDifference(actor, percentage);
390}
391
395
396void TrafficManagerLocal::SetLaneOffset(const ActorPtr &actor, const float offset) {
397 parameters.SetLaneOffset(actor, offset);
398}
399
403
404void TrafficManagerLocal::SetLargeVehicleWideTurn(const ActorPtr &actor, const bool enable) {
405 parameters.SetLargeVehicleWideTurn(actor, enable);
406}
407
411
412void TrafficManagerLocal::SetDesiredSpeed(const ActorPtr &actor, const float value) {
413 parameters.SetDesiredSpeed(actor, value);
414}
415
416/// Method to set the automatic management of the vehicle lights
417void TrafficManagerLocal::SetUpdateVehicleLights(const ActorPtr &actor, const bool do_update) {
418 parameters.SetUpdateVehicleLights(actor, do_update);
419}
420
421void TrafficManagerLocal::SetCollisionDetection(const ActorPtr &reference_actor, const ActorPtr &other_actor, const bool detect_collision) {
422 parameters.SetCollisionDetection(reference_actor, other_actor, detect_collision);
423}
424
425void TrafficManagerLocal::SetForceLaneChange(const ActorPtr &actor, const bool direction) {
426 parameters.SetForceLaneChange(actor, direction);
427}
428
429void TrafficManagerLocal::SetAutoLaneChange(const ActorPtr &actor, const bool enable) {
430 parameters.SetAutoLaneChange(actor, enable);
431}
432
433void TrafficManagerLocal::SetDistanceToLeadingVehicle(const ActorPtr &actor, const float distance) {
435}
436
440
441void TrafficManagerLocal::SetPercentageIgnoreWalkers(const ActorPtr &actor, const float perc) {
443}
444
445void TrafficManagerLocal::SetPercentageIgnoreVehicles(const ActorPtr &actor, const float perc) {
447}
448
449void TrafficManagerLocal::SetPercentageRunningLight(const ActorPtr &actor, const float perc) {
451}
452
453void TrafficManagerLocal::SetPercentageRunningSign(const ActorPtr &actor, const float perc) {
455}
456
457void TrafficManagerLocal::SetKeepSlowLanePercentage(const ActorPtr &actor, const float percentage) {
458 parameters.SetKeepSlowLanePercentage(actor, percentage);
459}
460
461
462void TrafficManagerLocal::SetRandomLeftLaneChangePercentage(const ActorPtr &actor, const float percentage) {
464}
465
466void TrafficManagerLocal::SetRandomRightLaneChangePercentage(const ActorPtr &actor, const float percentage) {
468}
469
470void TrafficManagerLocal::SetHybridPhysicsMode(const bool mode_switch) {
471 parameters.SetHybridPhysicsMode(mode_switch);
472}
473
477
478void TrafficManagerLocal::SetOSMMode(const bool mode_switch) {
479 parameters.SetOSMMode(mode_switch);
480}
481
482void TrafficManagerLocal::SetCustomPath(const ActorPtr &actor, const Path path, const bool empty_buffer) {
483 parameters.SetCustomPath(actor, path, empty_buffer);
484}
485
486void TrafficManagerLocal::RemoveUploadPath(const ActorId &actor_id, const bool remove_path) {
487 parameters.RemoveUploadPath(actor_id, remove_path);
488}
489
490void TrafficManagerLocal::UpdateUploadPath(const ActorId &actor_id, const Path path) {
491 parameters.UpdateUploadPath(actor_id, path);
492}
493
494void TrafficManagerLocal::SetImportedRoute(const ActorPtr &actor, const Route route, const bool empty_buffer) {
495 parameters.SetImportedRoute(actor, route, empty_buffer);
496}
497
498void TrafficManagerLocal::RemoveImportedRoute(const ActorId &actor_id, const bool remove_path) {
499 parameters.RemoveImportedRoute(actor_id, remove_path);
500}
501
502void TrafficManagerLocal::UpdateImportedRoute(const ActorId &actor_id, const Route route) {
503 parameters.UpdateImportedRoute(actor_id, route);
504}
505
509
513
515 for (auto &elem : tl_to_freeze) {
516 if (!elem->IsFrozen() || elem->GetState() != TLS::Red) {
517 return false;
518 }
519 }
520 return true;
521}
522
524 const bool previously_synchronous = parameters.GetSynchronousMode();
526 if (mode == previously_synchronous) { // Same mode as before, do nothing.
527 return;
528 }
529
530 if (!previously_synchronous) { // Switch from async to synchronous
531 if (worker_thread) {
532 if (worker_thread->joinable()) {
533 worker_thread->join();
534 }
535 worker_thread.reset();
536 }
537 }
538 else { // Switch from synchronous to async, start worker thread again.
539 if (worker_thread) {
540 // A worker thread should not exist while in synchronous mode. Tear it
541 // down before spawning a fresh one so a buggy prior transition does
542 // not leak running threads.
543 log_error("TrafficManagerLocal: worker thread present in synchronous mode; joining before async restart.");
544 if (worker_thread->joinable()) {
545 worker_thread->join();
546 }
547 worker_thread.reset();
548 }
549 worker_thread = std::make_unique<std::thread>(&TrafficManagerLocal::Run, this);
550 }
551}
552
556
560
564
566 seed = _seed;
568 world.ResetAllTrafficLights();
569}
570
571} // namespace traffic_manager
572} // namespace carla
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
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:404
void RemoveActor(const ActorId actor_id, const bool registered_actor)
Definition ALSM.cpp:430
std::vector< ActorPtr > TakeReleased()
Actors removed since the last call; drop them with no lock held.
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 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 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 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
TrafficManagerBase()
Protected constructor for singleton lifecycle management.
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 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.
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.
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 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.
std::unordered_map< ActorId, std::pair< float, bool > > large_vehicles
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.
std::vector< float > longitudinal_PID_parameters
PID controller parameters.
void SetUpdateVehicleLights(const ActorPtr &actor, const bool do_update)
Method to set the automatic management of the vehicle lights.
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
EpisodeProxyImpl< EpisodeProxyPointerType::Strong > EpisodeProxy
bool IsBatchSyncDue(const uint64_t unwaited_batches, const uint64_t limit)
Definition Constants.h:68
carla::SharedPtr< cc::Actor > ActorPtr
std::vector< uint8_t > Route
std::vector< cg::Location > Path
std::vector< carla::rpc::Command > ControlFrame
std::vector< Action > ActionBuffer
std::pair< RoadOption, WaypointPtr > Action
chr::time_point< chr::system_clock, chr::nanoseconds > TimePoint
std::vector< carla::SharedPtr< carla::client::TrafficLight > > TLGroup
This file contains definitions of common data structures used in traffic manager.
std::shared_ptr< T > SharedPtr
Definition Memory.h:15