42 "Version mismatch detected: You are trying to connect to a simulator",
43 "that might be incompatible with this API");
51 auto start = std::chrono::system_clock::now();
52 while (frame > episode.
GetState()->GetTimestamp().frame) {
53 std::this_thread::yield();
54 auto end = std::chrono::system_clock::now();
55 auto diff = std::chrono::duration_cast<std::chrono::milliseconds>(end-start);
73 const std::string &host,
75 const size_t worker_threads,
76 const bool enable_garbage_collection)
78 _client(host, port, worker_threads),
80 _gc_policy(enable_garbage_collection ?
100 for (
auto i = 0u; i < number_of_attempts; ++i) {
101 using namespace std::literals::chrono_literals;
108 if (episode.GetId() != id) {
112 throw_exception(std::runtime_error(
"failed to connect to newly created map"));
116 std::string opendrive,
121 constexpr
auto custom_opendrive_map =
"OpenDriveMap";
123 return LoadEpisode(custom_opendrive_map, reset_settings);
133 _episode = std::make_shared<Episode>(
_client, std::weak_ptr<Simulator>(shared_from_this()));
161 std::string map_name;
162 std::string map_base_path;
163 bool fill_base_string =
false;
164 for (
int i = map_info.
name.size() - 1; i >= 0; --i) {
165 if (fill_base_string ==
false && map_info.
name[i] !=
'/') {
166 map_name += map_info.
name[i];
168 map_base_path += map_info.
name[i];
169 fill_base_string =
true;
173 std::reverse(map_base_path.begin(), map_base_path.end());
174 std::string XODRFolder = map_base_path +
"/OpenDrive/" + map_name +
".xodr";
214 auto result =
_episode->WaitForState(timeout);
215 if (!result.has_value()) {
244 return MakeShared<BlueprintLibrary>(std::move(defs));
258 "synchronous mode enabled with variable delta seconds. It is highly " 259 "recommended to set 'fixed_delta_seconds' when running on synchronous mode.");
264 "synchronous mode and substepping are enabled but the number of substeps is not valid. " 265 "Please be aware that this value needs to be in the range [1-16].");
269 if (n_substeps > static_cast<double>(settings.
max_substeps)) {
271 "synchronous mode and substepping are enabled but the values for the simulation are not valid. " 272 "The values should fulfil fixed_delta_seconds <= max_substep_delta_time * max_substeps. " 273 "Be very careful about that, the time deltas are not guaranteed.");
278 using namespace std::literals::chrono_literals;
290 auto nav =
_episode->CreateNavigationIfMissing();
297 auto nav =
_episode->CreateNavigationIfMissing();
303 if (walker ==
nullptr) {
308 auto nav =
_episode->CreateNavigationIfMissing();
309 nav->RegisterWalker(walker->GetId(), controller.
GetId());
314 if (walker ==
nullptr) {
319 auto nav =
_episode->CreateNavigationIfMissing();
320 nav->UnregisterWalker(walker->GetId(), controller.
GetId());
325 auto nav =
_episode->CreateNavigationIfMissing();
326 return nav->GetRandomLocation();
331 auto nav =
_episode->CreateNavigationIfMissing();
332 nav->SetPedestriansCrossFactor(percentage);
337 auto nav =
_episode->CreateNavigationIfMissing();
338 nav->SetPedestriansSeed(seed);
352 if (parent !=
nullptr) {
368 result->GetDisplayId(),
371 "garbage collection");
398 [cb=std::move(callback), ep=
WeakEpisodeProxy{shared_from_this()}](
auto buffer) {
400 data->_episode = ep.TryLock();
427 [cb=std::move(callback), ep=
WeakEpisodeProxy{shared_from_this()}](
auto buffer) {
429 data->_episode = ep.TryLock();
447 const std::vector<std::string> &objects_name,
454 const std::vector<std::string> &objects_name,
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::shared_ptr< Episode > _episode
bool DestroyActor(Actor &actor)
streaming::Token GetStreamToken() const
Seting for map generation from opendrive without additional geometry.
static SharedPtr< SensorData > Deserialize(Buffer &&buffer)
static time_duration milliseconds(size_t timeout)
bool SetFilesBaseFolder(const std::string &path)
Holds the current episode, and the current episode state.
void SubscribeToGBuffer(rpc::ActorId ActorId, uint32_t GBufferId, std::function< void(Buffer)> callback)
bool SetFilesBaseFolder(const std::string &path)
static void ValidateVersions(Client &client)
std::vector< rpc::ActorDefinition > GetActorDefinitions()
std::string GetClientVersion()
bool IsEnabledForROS(const streaming::Token &token)
std::shared_ptr< WalkerNavigation > GetNavigation()
time_duration GetTimeout() const
rpc::MapInfo GetMapInfo()
void throw_exception(const std::exception &e)
void FreezeAllTrafficLights(bool frozen)
void reverse(I begin, I end)
bool IsEnabledForROS(const Sensor &sensor)
std::vector< std::string > GetNamesOfAllObjects() const
void CopyOpenDriveToServer(std::string opendrive, const rpc::OpendriveGenerationParameters ¶ms)
std::vector< std::string > GetNamesOfAllObjects() const
std::vector< uint8_t > GetCacheFile(const std::string &name, const bool request_otherwise) const
std::vector< uint8_t > GetCacheFile(const std::string &name, const bool request_otherwise=true) const
static SharedPtr< Actor > MakeActor(EpisodeProxy episode, rpc::Actor actor_description, GarbageCollectionPolicy garbage_collection_policy)
Create an Actor based on the provided actor_description.
std::vector< std::string > GetRequiredFiles(const std::string &folder="", const bool download=true) const
boost::shared_ptr< T > SharedPtr
Use this SharedPtr (boost::shared_ptr) to keep compatibility with boost::python, but it would be nice...
SharedPtr< LightManager > _light_manager
std::vector< std::pair< ActorId, VehicleLightState::flag_type > > VehicleLightStateList
This file contains definitions of common data structures used in traffic manager. ...
const GarbageCollectionPolicy _gc_policy
rpc::EpisodeSettings GetEpisodeSettings()
SharedPtr< Actor > GetSpectator()
std::vector< std::string > GetRequiredFiles(const std::string &folder="", const bool download=true) const
EpisodeProxy & GetEpisode()
boost::optional< geom::Location > GetRandomLocationFromNavigation()
void RequestFile(const std::string &name) const
void SubscribeToStream(const streaming::Token &token, std::function< void(Buffer)> callback)
EpisodeProxy GetCurrentEpisode()
rpc::VehicleLightStateList GetVehiclesLightStates()
Returns a list of pairs where the firts element is the vehicle ID and the second one is the light sta...
static void log_debug(Args &&...)
void EnableForROS(const Sensor &sensor)
const std::string & GetDisplayId() const
boost::optional< double > fixed_delta_seconds
SharedPtr< Map > _cached_map
void DisableForROS(const streaming::Token &token)
uint64_t SetEpisodeSettings(const rpc::EpisodeSettings &settings)
#define DEBUG_ASSERT(predicate)
#define LIBCARLA_INITIALIZE_LIFETIME_PROFILER(display_name)
rpc::EpisodeSettings GetEpisodeSettings()
void ApplyColorTextureToObjects(const std::vector< std::string > &objects_name, const rpc::MaterialParameter ¶meter, const rpc::TextureColor &Texture)
void EnableForROS(const streaming::Token &token)
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.
static bool SynchronizeFrame(uint64_t frame, const Episode &episode, time_duration timeout)
void FreezeAllTrafficLights(bool frozen)
void LoadEpisode(std::string map_name, bool reset_settings=true, rpc::MapLayer map_layer=rpc::MapLayer::All)
EpisodeProxy LoadEpisode(std::string map_name, bool reset_settings=true, rpc::MapLayer map_layers=rpc::MapLayer::All)
void ApplyColorTextureToObjects(const std::vector< std::string > &objects_name, const rpc::MaterialParameter ¶meter, const rpc::TextureColor &Texture)
– Texture updating operations
std::string GetServerVersion()
void GetReadyCurrentEpisode()
rpc::Actor GetSpectator()
auto GetId() const noexcept
void SubscribeToSensor(const Sensor &sensor, std::function< void(SharedPtr< sensor::SensorData >)> callback)
std::string GetMapData() const
double max_substep_delta_time
void UnSubscribeFromSensor(Actor &sensor)
static void log_warning(Args &&... args)
SharedPtr< Actor > MakeActor(rpc::Actor actor_description, GarbageCollectionPolicy gc=GarbageCollectionPolicy::Disabled)
Creates an actor instance out of a description of an existing actor.
std::shared_ptr< const EpisodeState > GetState() const
Provides communication with the rpc and streaming servers of a CARLA simulator.
rpc::Actor SpawnActorWithParent(const rpc::ActorDescription &description, const geom::Transform &transform, rpc::ActorId parent, rpc::AttachmentType attachment_type)
void UnregisterAIController(const WalkerAIController &controller)
void DisableForROS(const Sensor &sensor)
SharedPtr< Actor > GetParent() const
uint64_t Tick(time_duration timeout)
rpc::Actor SpawnActor(const rpc::ActorDescription &description, const geom::Transform &transform)
SharedPtr< Map > GetCurrentMap()
bool DestroyActor(rpc::ActorId actor)
EpisodeProxy LoadOpenDriveEpisode(std::string opendrive, const rpc::OpendriveGenerationParameters ¶ms, bool reset_settings=true)
rpc::ActorDescription MakeActorDescription() const
Represents an actor in the simulation.
void RequestFile(const std::string &name) const
Positive time duration up to milliseconds resolution.
void UnSubscribeFromStream(const streaming::Token &token)
Contains all the necessary information for spawning an Actor.
void RegisterAIController(const WalkerAIController &controller)
void SetPedestriansCrossFactor(float percentage)
void UnSubscribeFromGBuffer(rpc::ActorId ActorId, uint32_t GBufferId)
void SubscribeToGBuffer(Actor &sensor, uint32_t gbuffer_id, std::function< void(SharedPtr< sensor::SensorData >)> callback)
SharedPtr< BlueprintLibrary > GetBlueprintLibrary()
constexpr auto to_chrono() const
EpisodeProxyImpl< EpisodeProxyPointerType::Weak > WeakEpisodeProxy
void UnSubscribeFromGBuffer(Actor &sensor, uint32_t gbuffer_id)
bool ShouldUpdateMap(rpc::MapInfo &map_info)
const std::string GetEndpoint() const
static bool FileExists(std::string file)
void SetPedestriansSeed(unsigned int seed)
WorldSnapshot WaitForTick(time_duration timeout)
std::string _open_drive_file
const rpc::Actor & GetActorDescription() const
uint64_t SetEpisodeSettings(const rpc::EpisodeSettings &settings)