From 78aa7cb1bcb7f5a04c04a7a6100787153951dd72 Mon Sep 17 00:00:00 2001 From: Daniel Santos-Olivan Date: Thu, 17 Dec 2020 14:00:09 +0100 Subject: [PATCH] ApplySettings now check the episode settings This method now check that the episode settings have effect in the server as expected. --- LibCarla/source/carla/client/World.cpp | 26 +++++++++++++++++++++-- LibCarla/source/carla/client/World.h | 2 +- PythonAPI/carla/source/libcarla/World.cpp | 7 +++++- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/LibCarla/source/carla/client/World.cpp b/LibCarla/source/carla/client/World.cpp index 90f0d0b87..f72641db2 100644 --- a/LibCarla/source/carla/client/World.cpp +++ b/LibCarla/source/carla/client/World.cpp @@ -50,8 +50,30 @@ namespace client { return _episode.Lock()->GetEpisodeSettings(); } - uint64_t World::ApplySettings(const rpc::EpisodeSettings &settings) { - return _episode.Lock()->SetEpisodeSettings(settings); + uint64_t World::ApplySettings(const rpc::EpisodeSettings &settings, time_duration timeout) { + rpc::EpisodeSettings new_settings = settings; + uint64_t id = _episode.Lock()->SetEpisodeSettings(settings); + if (settings.synchronous_mode) { + using namespace std::literals::chrono_literals; + + const auto number_of_attemps = 15u; + int tics_correct = 0; + for (auto i = 0u; i < number_of_attemps; i++) { + const auto curr_snapshot = GetSnapshot(); + + const double error = abs(new_settings.fixed_delta_seconds.get() - curr_snapshot.GetTimestamp().delta_seconds); + if (error < std::numeric_limits::epsilon()) + tics_correct++; + + if (tics_correct >= 2) + return id; + + Tick(timeout); + } + + log_warning("World::ApplySettings: After", number_of_attemps, ", the settings were not correctly setted. Please check that everything is consistent."); + } + return id; } rpc::WeatherParameters World::GetWeather() const { diff --git a/LibCarla/source/carla/client/World.h b/LibCarla/source/carla/client/World.h index 0f9deda88..2c90ea44d 100644 --- a/LibCarla/source/carla/client/World.h +++ b/LibCarla/source/carla/client/World.h @@ -81,7 +81,7 @@ namespace client { rpc::EpisodeSettings GetSettings() const; /// @return The id of the frame when the settings were applied. - uint64_t ApplySettings(const rpc::EpisodeSettings &settings); + uint64_t ApplySettings(const rpc::EpisodeSettings &settings, time_duration timeout); /// Retrieve the weather parameters currently active in the world. rpc::WeatherParameters GetWeather() const; diff --git a/PythonAPI/carla/source/libcarla/World.cpp b/PythonAPI/carla/source/libcarla/World.cpp index 4e8dff14f..a2bf93f27 100644 --- a/PythonAPI/carla/source/libcarla/World.cpp +++ b/PythonAPI/carla/source/libcarla/World.cpp @@ -69,6 +69,11 @@ static auto Tick(carla::client::World &world, double seconds) { return world.Tick(TimeDurationFromSeconds(seconds)); } +static auto ApplySettings(carla::client::World &world, carla::rpc::EpisodeSettings settings, double seconds) { + carla::PythonUtil::ReleaseGIL unlock; + return world.ApplySettings(settings, TimeDurationFromSeconds(seconds)); +} + static auto GetActorsById(carla::client::World &self, const boost::python::list &actor_ids) { std::vector ids{ boost::python::stl_input_iterator(actor_ids), @@ -262,7 +267,7 @@ void export_world() { .def("get_random_location_from_navigation", CALL_RETURNING_OPTIONAL_WITHOUT_GIL(cc::World, GetRandomLocationFromNavigation)) .def("get_spectator", CONST_CALL_WITHOUT_GIL(cc::World, GetSpectator)) .def("get_settings", CONST_CALL_WITHOUT_GIL(cc::World, GetSettings)) - .def("apply_settings", CALL_WITHOUT_GIL_1(cc::World, ApplySettings, cr::EpisodeSettings), arg("settings")) + .def("apply_settings", &ApplySettings, (arg("settings"), arg("seconds")=10.0)) .def("get_weather", CONST_CALL_WITHOUT_GIL(cc::World, GetWeather)) .def("set_weather", &cc::World::SetWeather) .def("get_snapshot", &cc::World::GetSnapshot)