CARLA
Loading...
Searching...
No Matches
Simulator.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
8
9#include <algorithm>
10
11#include "carla/Debug.h"
12#include "carla/Exception.h"
13#include "carla/Logging.h"
17#include "carla/client/Map.h"
18#include "carla/client/Sensor.h"
25
26#include "carla/ThreadPool.h"
27
28#include <chrono>
29#include <condition_variable>
30#include <deque>
31#include <exception>
32#include <mutex>
33#include <thread>
34
35#ifndef _WIN32
36#include <unistd.h>
37#endif
38
39using namespace std::string_literals;
40
41namespace carla {
42namespace client {
43namespace detail {
44
45 // ===========================================================================
46 // -- Static local methods ---------------------------------------------------
47 // ===========================================================================
48
50 const auto vc = client.GetClientVersion();
51 const auto vs = client.GetServerVersion();
52 if (vc != vs) {
53 log_warning(
54 "Version mismatch detected: You are trying to connect to a simulator",
55 "that might be incompatible with this API");
56 log_warning("Client API version =", vc);
57 log_warning("Simulator API version =", vs);
58 }
59 }
60
61 static bool SynchronizeFrame(uint64_t frame, const Episode &episode, time_duration timeout) {
62 bool result = true;
63 auto start = std::chrono::system_clock::now();
64 while (frame > episode.GetState()->GetTimestamp().frame) {
65 std::this_thread::sleep_for(std::chrono::microseconds(100));
66 auto end = std::chrono::system_clock::now();
67 auto diff = std::chrono::duration_cast<std::chrono::milliseconds>(end-start);
68 if(timeout.to_chrono() < diff) {
69 result = false;
70 break;
71 }
72 }
73 if(result) {
75 }
76
77 return result;
78 }
79
80 // ===========================================================================
81 // -- Constructor ------------------------------------------------------------
82 // ===========================================================================
83
85 const std::string &host,
86 const uint16_t port,
87 const size_t worker_threads,
88 const bool enable_garbage_collection)
89 : LIBCARLA_INITIALIZE_LIFETIME_PROFILER("SimulatorClient("s + host + ":" + std::to_string(port) + ")"),
90 _client(host, port, worker_threads),
92 _gc_policy(enable_garbage_collection ?
94
96 // Join first, or ~Episode can run on a stream thread while _client dies.
98 }
99
100 namespace {
101
102 /// Destroys the Simulators whose last reference went away on a pool thread.
103 class SimulatorReaper {
104 public:
105
106 void Post(Simulator *simulator) {
107 std::unique_lock<std::mutex> lock(_mutex);
108 _queue.push_back(simulator);
109 // A forked child inherits _running but not the thread.
110 if (!_running || _owner != CurrentProcess()) {
111 _running = true;
112 _owner = CurrentProcess();
113 std::thread(&SimulatorReaper::Run, this).detach();
114 }
115 _cv.notify_all();
116 }
117
118 private:
119
120 static long CurrentProcess() {
121 #ifdef _WIN32
122 return 0;
123 #else
124 return static_cast<long>(::getpid());
125 #endif
126 }
127
128 void Run() {
129 std::unique_lock<std::mutex> lock(_mutex);
130 while (true) {
131 _cv.wait(lock, [this]() { return !_queue.empty(); });
132 Simulator *simulator = _queue.front();
133 _queue.pop_front();
134 lock.unlock();
135 try {
136 delete simulator;
137 } catch (const std::exception &e) {
138 log_error("failed to destroy a client:", e.what());
139 }
140 lock.lock();
141 }
142 }
143
144 std::mutex _mutex;
145 std::condition_variable _cv;
146 std::deque<Simulator *> _queue;
147 bool _running = false;
148 long _owner = 0;
149 };
150
151 SimulatorReaper &GetSimulatorReaper() {
152 // Never destroyed: the detached thread may outlive static destruction at exit.
153 static SimulatorReaper *instance = new SimulatorReaper();
154 return *instance;
155 }
156
157 } // namespace
158
159 void Simulator::Delete(Simulator *simulator) {
160 if (simulator == nullptr) {
161 return;
162 }
164 GetSimulatorReaper().Post(simulator);
165 } else {
166 delete simulator;
167 }
168 }
169
170 // ===========================================================================
171 // -- Load a new episode -----------------------------------------------------
172 // ===========================================================================
173
174 EpisodeProxy Simulator::LoadEpisode(std::string map_name, bool reset_settings, rpc::MapLayer map_layers) {
175 const auto id = GetCurrentEpisode().GetId();
176 _client.LoadEpisode(std::move(map_name), reset_settings, map_layers);
177
178 // We are waiting 50ms for the server to reload the episode.
179 // If in this time we have not detected a change of episode, we try again
180 // 'number_of_attempts' times.
181 // TODO This time is completly arbitrary so we need to improve
182 // this pipeline to not depend in this time because this timeout
183 // could result that the client resume the simulation in different
184 // initial ticks when loading a map in syncronous mode.
185 size_t number_of_attempts = _client.GetTimeout().milliseconds() / 50u;
186
187 for (auto i = 0u; i < number_of_attempts; ++i) {
188 using namespace std::literals::chrono_literals;
191
192 _episode->WaitForState(50ms);
193 auto episode = GetCurrentEpisode();
194
195 if (episode.GetId() != id) {
196 // Wait for the stream thread to reset the Traffic Manager for it.
197 const auto deadline = std::chrono::steady_clock::now() + _client.GetTimeout().to_chrono();
198 while (!_episode->IsEpisodeChangeHandled()) {
199 if (std::chrono::steady_clock::now() > deadline) {
200 log_warning("the Traffic Manager has not finished resetting for the new episode");
201 break;
202 }
203 std::this_thread::sleep_for(10ms);
204 }
205 return episode;
206 }
207 }
208 throw_exception(std::runtime_error("failed to connect to newly created map"));
209 }
210
212 std::string opendrive,
213 const rpc::OpendriveGenerationParameters & params, bool reset_settings) {
214 // The "OpenDriveMap" is an ".umap" located in:
215 // "carla/Unreal/CarlaUnreal/Content/Carla/Maps/"
216 // It will load the last sended OpenDRIVE by client's "LoadOpenDriveEpisode()"
217 constexpr auto custom_opendrive_map = "OpenDriveMap";
218 _client.CopyOpenDriveToServer(std::move(opendrive), params);
219 return LoadEpisode(custom_opendrive_map, reset_settings);
220 }
221
222 // ===========================================================================
223 // -- Access to current episode ----------------------------------------------
224 // ===========================================================================
225
227 if (_episode == nullptr) {
229 _episode = std::make_shared<Episode>(_client, std::weak_ptr<Simulator>(shared_from_this()));
230 _episode->Listen();
231 if (!GetEpisodeSettings().synchronous_mode) {
233 }
234 _light_manager->SetEpisode(WeakEpisodeProxy{shared_from_this()});
235 }
236 }
239 return EpisodeProxy{shared_from_this()};
240 }
241
243 if (!_cached_map) {
244 return true;
245 }
246 if (map_info.name != _cached_map->GetName() ||
247 _open_drive_file.size() != _cached_map->GetOpenDrive().size()) {
248 return true;
249 }
250 return false;
251 }
252
254 DEBUG_ASSERT(_episode != nullptr);
255 // Check-and-refetch must be atomic: the Traffic Manager refreshes the map
256 // from its own thread on an episode change, and a caller that ran while
257 // that refresh was still downloading the OpenDRIVE found the change flag
258 // already consumed and the cache still holding the previous map. The
259 // cache is also keyed on the episode id, so a missed change flag cannot
260 // leave a stale map behind either.
261 std::lock_guard<std::mutex> lock(_cached_map_mutex);
262 const auto episode_id = _episode->GetId();
263 if (!_cached_map || _cached_map_episode_id != episode_id || _episode->HasMapChangedSinceLastCall()) {
264 rpc::MapInfo map_info = _client.GetMapInfo();
265 std::string map_name;
266 std::string map_base_path;
267 bool fill_base_string = false;
268 for (size_t ri = map_info.name.size(); ri > 0; --ri) {
269 size_t i = ri - 1;
270 if (fill_base_string == false && map_info.name[i] != '/') {
271 map_name += map_info.name[i];
272 } else {
273 map_base_path += map_info.name[i];
274 fill_base_string = true;
275 }
276 }
277 std::reverse(map_name.begin(), map_name.end());
278 std::reverse(map_base_path.begin(), map_base_path.end());
279 std::string XODRFolder = map_base_path + "/OpenDrive/" + map_name + ".xodr";
280 if (FileTransfer::FileExists(XODRFolder) == false) _client.GetRequiredFiles();
282 _cached_map = MakeShared<Map>(map_info, _open_drive_file);
283 _cached_map_episode_id = episode_id;
284 }
285
286 return _cached_map;
287 }
288
289 // ===========================================================================
290 // -- Required files ---------------------------------------------------------
291 // ===========================================================================
292
293
294 bool Simulator::SetFilesBaseFolder(const std::string &path) {
295 return _client.SetFilesBaseFolder(path);
296 }
297
298 std::vector<std::string> Simulator::GetRequiredFiles(const std::string &folder, const bool download) const {
299 return _client.GetRequiredFiles(folder, download);
300 }
301
302 void Simulator::RequestFile(const std::string &name) const {
303 _client.RequestFile(name);
304 }
305
306 std::vector<uint8_t> Simulator::GetCacheFile(const std::string &name, const bool request_otherwise) const {
307 return _client.GetCacheFile(name, request_otherwise);
308 }
309
310 // ===========================================================================
311 // -- Tick -------------------------------------------------------------------
312 // ===========================================================================
313
315 DEBUG_ASSERT(_episode != nullptr);
316
317 // tick pedestrian navigation
319
320 auto result = _episode->WaitForState(timeout);
321 if (!result.has_value()) {
323 }
324 return *result;
325 }
326
327 uint64_t Simulator::Tick(time_duration timeout) {
328 DEBUG_ASSERT(_episode != nullptr);
329
330 // tick pedestrian navigation
332
333 // send tick command
334 const auto frame = _client.SendTickCue();
335
336 // waits until new episode is received
337 bool result = SynchronizeFrame(frame, *_episode, timeout);
338 if (!result) {
340 }
341 return frame;
342 }
343
344 // ===========================================================================
345 // -- Access to global objects in the episode --------------------------------
346 // ===========================================================================
347
349 auto defs = _client.GetActorDefinitions();
350 return MakeShared<BlueprintLibrary>(std::move(defs));
351 }
352
356
360
362 if (settings.synchronous_mode && !settings.fixed_delta_seconds) {
363 log_warning(
364 "synchronous mode enabled with variable delta seconds. It is highly "
365 "recommended to set 'fixed_delta_seconds' when running on synchronous mode.");
366 }
367 else if (settings.synchronous_mode && settings.substepping) {
368 if(settings.max_substeps < 1 || settings.max_substeps > 16) {
369 log_warning(
370 "synchronous mode and substepping are enabled but the number of substeps is not valid. "
371 "Please be aware that this value needs to be in the range [1-16].");
372 }
373 double n_substeps = settings.fixed_delta_seconds.value() / settings.max_substep_delta_time;
374
375 if (n_substeps > static_cast<double>(settings.max_substeps)) {
376 log_warning(
377 "synchronous mode and substepping are enabled but the values for the simulation are not valid. "
378 "The values should fulfil fixed_delta_seconds <= max_substep_delta_time * max_substeps. "
379 "Be very careful about that, the time deltas are not guaranteed.");
380 }
381 }
382 const auto frame = _client.SetEpisodeSettings(settings);
383
384 using namespace std::literals::chrono_literals;
385 SynchronizeFrame(frame, *_episode, 1s);
386
387 return frame;
388 }
389
390 // ===========================================================================
391 // -- AI ---------------------------------------------------------------------
392 // ===========================================================================
393
394 std::shared_ptr<WalkerNavigation> Simulator::GetNavigation() {
395 DEBUG_ASSERT(_episode != nullptr);
396 auto nav = _episode->CreateNavigationIfMissing();
397 return nav;
398 }
399
400 // tick pedestrian navigation
402 DEBUG_ASSERT(_episode != nullptr);
403 auto nav = _episode->CreateNavigationIfMissing();
404 nav->Tick(_episode);
405 }
406
408 DEBUG_ASSERT(_episode != nullptr);
409 return _episode->CreateNavigationIfMissing()->IsServerSide();
410 }
411
413 auto walker = controller.GetParent();
414 if (walker == nullptr) {
415 throw_exception(std::runtime_error(controller.GetDisplayId() + ": not attached to walker"));
416 return;
417 }
418 DEBUG_ASSERT(_episode != nullptr);
419 auto nav = _episode->CreateNavigationIfMissing();
420 nav->RegisterWalker(walker->GetId(), controller.GetId());
421 }
422
424 auto walker = controller.GetParent();
425 if (walker == nullptr) {
426 throw_exception(std::runtime_error(controller.GetDisplayId() + ": not attached to walker"));
427 return;
428 }
429 DEBUG_ASSERT(_episode != nullptr);
430 auto nav = _episode->CreateNavigationIfMissing();
431 nav->UnregisterWalker(walker->GetId(), controller.GetId());
432 }
433
434 std::optional<geom::Location> Simulator::GetRandomLocationFromNavigation() {
435 DEBUG_ASSERT(_episode != nullptr);
436 auto nav = _episode->CreateNavigationIfMissing();
437 if (nav->IsServerSide()) {
438 // The server samples the loaded navmesh; the sentinel z = -1e6 means it
439 // found no point (e.g. tiles still streaming in), so try a few times
440 // before giving up like the legacy path does (empty optional).
441 constexpr int attempts = 3;
442 for (int i = 0; i < attempts; ++i) {
444 if (location.z > -9.0e5f) {
445 return location;
446 }
447 }
448 return {};
449 }
450 return nav->GetRandomLocation();
451 }
452
454 DEBUG_ASSERT(_episode != nullptr);
455 auto nav = _episode->CreateNavigationIfMissing();
456 if (nav->IsServerSide()) {
458 return;
459 }
460 nav->SetPedestriansCrossFactor(percentage);
461 }
462
463 void Simulator::SetPedestriansSeed(unsigned int seed) {
464 DEBUG_ASSERT(_episode != nullptr);
465 auto nav = _episode->CreateNavigationIfMissing();
466 if (nav->IsServerSide()) {
468 return;
469 }
470 nav->SetPedestriansSeed(seed);
471 }
472
473 // ===========================================================================
474 // -- General operations with actors -----------------------------------------
475 // ===========================================================================
476
478 const ActorBlueprint &blueprint,
479 const geom::Transform &transform,
480 Actor *parent,
481 rpc::AttachmentType attachment_type,
483 rpc::Actor actor;
484 if (parent != nullptr) {
486 blueprint.MakeActorDescription(),
487 transform,
488 parent->GetId(),
489 attachment_type);
490 } else {
491 actor = _client.SpawnActor(
492 blueprint.MakeActorDescription(),
493 transform);
494 }
495 DEBUG_ASSERT(_episode != nullptr);
496 _episode->RegisterActor(actor);
497 const auto gca = (gc == GarbageCollectionPolicy::Inherit ? _gc_policy : gc);
498 auto result = ActorFactory::MakeActor(GetCurrentEpisode(), actor, gca);
499 // Snapshots up to (and including) this frame predate the spawn; see
500 // Simulator::GetActorState. The server's frame at the spawn is the right
501 // bound: the client's latest snapshot can lag behind it, and a snapshot the
502 // server built before the spawn would then arrive "newer" and mark the
503 // actor Invalid. A server that does not report it sends 0.
504 static_cast<ActorState &>(*result)._spawn_frame =
505 std::max<uint64_t>(actor.spawn_frame, _episode->GetState()->GetFrame());
506 log_debug(
507 result->GetDisplayId(),
508 "created",
509 gca == GarbageCollectionPolicy::Enabled ? "with" : "without",
510 "garbage collection");
511 return result;
512 }
513
515 bool success = true;
516 success = _client.DestroyActor(actor.GetId());
517 if (success) {
518 // Remove it's persistent state so it cannot access the client anymore.
519 actor.GetEpisode().Clear();
520 log_debug(actor.GetDisplayId(), "destroyed.");
521 } else {
522 log_debug("failed to destroy", actor.GetDisplayId());
523 }
524 return success;
525 }
526
527 // ===========================================================================
528 // -- Operations with sensors ------------------------------------------------
529 // ===========================================================================
530
532 const Sensor &sensor,
533 std::function<void(SharedPtr<sensor::SensorData>)> callback) {
534 DEBUG_ASSERT(_episode != nullptr);
536 sensor.GetActorDescription().GetStreamToken(),
537 [cb=std::move(callback), ep=WeakEpisodeProxy{shared_from_this()}](auto buffer) {
538 auto data = sensor::Deserializer::Deserialize(std::move(buffer));
539 data->_episode = ep.TryLock();
540 cb(std::move(data));
541 });
542 }
543
545 _client.UnSubscribeFromStream(sensor.GetActorDescription().GetStreamToken());
546 // If in the future we need to unsubscribe from each gbuffer individually, it should be done here.
547 }
548
550 _client.EnableForROS(sensor.GetActorDescription().GetStreamToken());
551 }
552
554 _client.DisableForROS(sensor.GetActorDescription().GetStreamToken());
555 }
556
558 return _client.IsEnabledForROS(sensor.GetActorDescription().GetStreamToken());
559 }
560
562 Actor &actor,
563 uint32_t gbuffer_id,
564 std::function<void(SharedPtr<sensor::SensorData>)> callback) {
565 _client.SubscribeToGBuffer(actor.GetId(), gbuffer_id,
566 [cb=std::move(callback), ep=WeakEpisodeProxy{shared_from_this()}](auto buffer) {
567 auto data = sensor::Deserializer::Deserialize(std::move(buffer));
568 data->_episode = ep.TryLock();
569 cb(std::move(data));
570 });
571 }
572
573 void Simulator::UnSubscribeFromGBuffer(Actor &actor, uint32_t gbuffer_id) {
574 _client.UnSubscribeFromGBuffer(actor.GetId(), gbuffer_id);
575 }
576
578 _client.Send(sensor.GetId(), data);
579 }
580
584
585 // =========================================================================
586 /// -- Texture updating operations
587 // =========================================================================
588
590 const std::vector<std::string> &objects_name,
591 const rpc::MaterialParameter& parameter,
592 const rpc::TextureColor& Texture) {
593 _client.ApplyColorTextureToObjects(objects_name, parameter, Texture);
594 }
595
597 const std::vector<std::string> &objects_name,
598 const rpc::MaterialParameter& parameter,
599 const rpc::TextureFloatColor& Texture) {
600 _client.ApplyColorTextureToObjects(objects_name, parameter, Texture);
601 }
602
603 std::vector<std::string> Simulator::GetNamesOfAllObjects() const {
605 }
606
607} // namespace detail
608} // namespace client
609} // namespace carla
#define DEBUG_ASSERT(predicate)
Definition Debug.h:66
#define LIBCARLA_INITIALIZE_LIFETIME_PROFILER(display_name)
static bool IsPoolThread()
Whether the calling thread is a ThreadPool worker (it must not destroy its own pool).
Definition ThreadPool.h:62
Contains all the necessary information for spawning an Actor.
rpc::ActorDescription MakeActorDescription() const
Represents an actor in the simulation.
static bool FileExists(std::string_view file)
TimeoutException(const std::string &endpoint, time_duration timeout)
static SharedPtr< Actor > MakeActor(EpisodeProxy episode, rpc::Actor actor_description, GarbageCollectionPolicy garbage_collection_policy)
Create an Actor based on the provided actor_description.
SharedPtr< Actor > GetParent() const
const std::string & GetDisplayId() const
Provides communication with the rpc and streaming servers of a CARLA simulator.
bool SetPedestriansSeed(uint32_t seed) const
Seed for the server-side navigation RNG (crosser draw); applies to walkers whose navigation starts af...
const std::string GetEndpoint() const
bool IsEnabledForROS(const streaming::Token &token)
void DisableForROS(const streaming::Token &token)
bool SetFilesBaseFolder(const std::string &path)
void Send(rpc::ActorId ActorId, const rpc::CustomV2XBytes &data)
void RequestFile(const std::string &name) const
void UnSubscribeFromGBuffer(rpc::ActorId ActorId, uint32_t GBufferId)
void UnSubscribeFromStream(const streaming::Token &token)
rpc::VehicleLightStateList GetVehiclesLightStates()
Returns a list of pairs where the firts element is the vehicle ID and the second one is the light sta...
std::vector< std::string > GetRequiredFiles(const std::string &folder="", const bool download=true) const
void LoadEpisode(std::string map_name, bool reset_settings=true, rpc::MapLayer map_layer=rpc::MapLayer::All)
uint64_t SetEpisodeSettings(const rpc::EpisodeSettings &settings)
void SubscribeToStream(const streaming::Token &token, std::function< void(Buffer)> callback)
std::vector< std::string > GetNamesOfAllObjects() const
void CopyOpenDriveToServer(std::string opendrive, const rpc::OpendriveGenerationParameters &params)
void StopStreaming()
Join the streaming threads; no stream callback runs afterwards.
bool DestroyActor(rpc::ActorId actor)
bool SetPedestriansCrossFactor(float percentage) const
Probability that a walker whose navigation starts after this call may cross roads (server-side naviga...
std::vector< uint8_t > GetCacheFile(const std::string &name, const bool request_otherwise=true) const
void EnableForROS(const streaming::Token &token)
std::vector< rpc::ActorDefinition > GetActorDefinitions()
void SubscribeToGBuffer(rpc::ActorId ActorId, uint32_t GBufferId, std::function< void(Buffer)> callback)
geom::Location GetRandomLocationFromNavigation() const
Server-side random point on the loaded navmesh.
void ApplyColorTextureToObjects(const std::vector< std::string > &objects_name, const rpc::MaterialParameter &parameter, const rpc::TextureColor &Texture)
rpc::Actor SpawnActorWithParent(const rpc::ActorDescription &description, const geom::Transform &transform, rpc::ActorId parent, rpc::AttachmentType attachment_type)
rpc::EpisodeSettings GetEpisodeSettings()
rpc::Actor SpawnActor(const rpc::ActorDescription &description, const geom::Transform &transform)
Holds the current episode, and the current episode state.
Definition Episode.h:38
std::shared_ptr< const EpisodeState > GetState() const
Definition Episode.h:56
Connects and controls a CARLA Simulator.
Definition Simulator.h:55
WorldSnapshot WaitForTick(time_duration timeout)
std::shared_ptr< Episode > _episode
Definition Simulator.h:1002
bool ShouldUpdateMap(rpc::MapInfo &map_info)
void DisableForROS(const Sensor &sensor)
void RequestFile(const std::string &name) const
void EnableForROS(const Sensor &sensor)
void RegisterAIController(const WalkerAIController &controller)
SharedPtr< LightManager > _light_manager
Definition Simulator.h:1000
std::vector< std::string > GetRequiredFiles(const std::string &folder="", const bool download=true) const
SharedPtr< Actor > MakeActor(rpc::Actor actor_description, GarbageCollectionPolicy gc=GarbageCollectionPolicy::Disabled)
Creates an actor instance out of a description of an existing actor.
Definition Simulator.h:421
bool IsEnabledForROS(const Sensor &sensor)
SharedPtr< BlueprintLibrary > GetBlueprintLibrary()
SharedPtr< Actor > SpawnActor(const ActorBlueprint &blueprint, const geom::Transform &transform, Actor *parent=nullptr, rpc::AttachmentType attachment_type=rpc::AttachmentType::Rigid, GarbageCollectionPolicy gc=GarbageCollectionPolicy::Inherit)
Spawns an actor into the simulation.
Simulator(const std::string &host, uint16_t port, size_t worker_threads=0u, bool enable_garbage_collection=false)
Definition Simulator.cpp:84
const GarbageCollectionPolicy _gc_policy
Definition Simulator.h:1004
rpc::VehicleLightStateList GetVehiclesLightStates()
Returns a list of pairs where the firts element is the vehicle ID and the second one is the light sta...
void UnSubscribeFromGBuffer(Actor &sensor, uint32_t gbuffer_id)
void SubscribeToSensor(const Sensor &sensor, std::function< void(SharedPtr< sensor::SensorData >)> callback)
void UnregisterAIController(const WalkerAIController &controller)
std::vector< uint8_t > GetCacheFile(const std::string &name, const bool request_otherwise) const
void ApplyColorTextureToObjects(const std::vector< std::string > &objects_name, const rpc::MaterialParameter &parameter, const rpc::TextureColor &Texture)
– Texture updating operations
std::shared_ptr< WalkerNavigation > GetNavigation()
bool SetFilesBaseFolder(const std::string &path)
SharedPtr< Actor > GetSpectator()
EpisodeProxy LoadOpenDriveEpisode(std::string opendrive, const rpc::OpendriveGenerationParameters &params, bool reset_settings=true)
void Send(const Sensor &sensor, const rpc::CustomV2XBytes &data)
void SetPedestriansCrossFactor(float percentage)
void FreezeAllTrafficLights(bool frozen)
uint64_t SetEpisodeSettings(const rpc::EpisodeSettings &settings)
void UnSubscribeFromSensor(Actor &sensor)
EpisodeProxy LoadEpisode(std::string map_name, bool reset_settings=true, rpc::MapLayer map_layers=rpc::MapLayer::All)
uint64_t Tick(time_duration timeout)
void SubscribeToGBuffer(Actor &sensor, uint32_t gbuffer_id, std::function< void(SharedPtr< sensor::SensorData >)> callback)
static void Delete(Simulator *simulator)
Deleter: on a pool thread, destroy on a background thread (~Simulator joins the pools).
std::vector< std::string > GetNamesOfAllObjects() const
SharedPtr< Map > GetCurrentMap()
std::optional< geom::Location > GetRandomLocationFromNavigation()
rpc::EpisodeSettings GetEpisodeSettings()
Definition Simulator.h:274
bool DestroyActor(Actor &actor)
void SetPedestriansSeed(unsigned int seed)
bool IsNavigationServerSide()
True when the current episode's navigation is hosted by the server (World-Partitioned navmesh); walke...
A rigid transform in CARLA's / Unreal's left-handed frame: x forward, y right, z up,...
uint64_t spawn_frame
Server frame counter when a spawn call created this actor: snapshots up to and including this frame p...
Definition rpc/Actor.h:58
Fixed-size binary payload carried by the custom V2X sensor (sensor.other.v2x_custom).
std::string name
Definition MapInfo.h:21
Positive time duration up to milliseconds resolution.
Definition Time.h:20
static time_duration milliseconds(size_t timeout)
Definition Time.h:27
constexpr auto to_chrono() const
Definition Time.h:54
static void ValidateVersions(Client &client)
Definition Simulator.cpp:49
EpisodeProxyImpl< EpisodeProxyPointerType::Strong > EpisodeProxy
EpisodeProxyImpl< EpisodeProxyPointerType::Weak > WeakEpisodeProxy
static bool SynchronizeFrame(uint64_t frame, const Episode &episode, time_duration timeout)
Definition Simulator.cpp:61
Texture< sensor::data::Color > TextureColor
Definition Texture.h:66
Texture< FloatColor > TextureFloatColor
Definition Texture.h:67
std::vector< std::pair< ActorId, VehicleLightState::flag_type > > VehicleLightStateList
This file contains definitions of common data structures used in traffic manager.
std::shared_ptr< T > SharedPtr
Definition Memory.h:15
void throw_exception(const ExceptionT &e)
Templated on the static type so the thrown object keeps its dynamic type: taking a const std::excepti...
Definition Exception.h:44
Seting for map generation from opendrive without additional geometry.