ApplySettings now check the episode settings

This method now check that the episode settings have
effect in the server as expected.
This commit is contained in:
Daniel Santos-Olivan 2020-12-17 14:00:09 +01:00 committed by bernat
parent dde86b42bb
commit 78aa7cb1bc
3 changed files with 31 additions and 4 deletions

View File

@ -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<float>::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 {

View File

@ -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;

View File

@ -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<carla::ActorId> ids{
boost::python::stl_input_iterator<carla::ActorId>(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)