From d156c5d14f5e1e0de94804ad148d07b8aadc1f50 Mon Sep 17 00:00:00 2001 From: Shital Shah Date: Sun, 8 Oct 2017 20:12:06 -0700 Subject: [PATCH] added ClockSpeed setting --- .../AirSim/Source/SimMode/SimModeBase.cpp | 22 +++++++++++++------ .../AirSim/Source/SimMode/SimModeBase.h | 2 +- docs/settings.md | 7 +++--- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/Unreal/Plugins/AirSim/Source/SimMode/SimModeBase.cpp b/Unreal/Plugins/AirSim/Source/SimMode/SimModeBase.cpp index 789b8725d2..0ed44a37e9 100644 --- a/Unreal/Plugins/AirSim/Source/SimMode/SimModeBase.cpp +++ b/Unreal/Plugins/AirSim/Source/SimMode/SimModeBase.cpp @@ -16,19 +16,24 @@ void ASimModeBase::BeginPlay() { Super::BeginPlay(); - setStencilIDs(); - - record_tick_count = 0; - setupInputBindings(); - - UAirBlueprintLib::LogMessage(TEXT("Press F1 to see help"), TEXT(""), LogDebugLevel::Informational); - try { readSettings(); } catch (std::exception& ex) { UAirBlueprintLib::LogMessageString("Error occured while reading the Settings: ", ex.what(), LogDebugLevel::Failure); } + + if (clock_speed != 1.0f) { + this->GetWorldSettings()->SetTimeDilation(clock_speed); + UAirBlueprintLib::LogMessageString("Clock Speed: ", std::to_string(clock_speed), LogDebugLevel::Informational); + } + + setStencilIDs(); + + record_tick_count = 0; + setupInputBindings(); + + UAirBlueprintLib::LogMessage(TEXT("Press F1 to see help"), TEXT(""), LogDebugLevel::Informational); } void ASimModeBase::setStencilIDs() @@ -66,6 +71,7 @@ void ASimModeBase::readSettings() enable_collision_passthrough = false; clock_type = ""; engine_sound = true; + clock_speed = 1.0f; typedef msr::airlib::Settings Settings; @@ -154,6 +160,8 @@ void ASimModeBase::readSettings() clock_type = "ScalableClock"; } + clock_speed = settings.getFloat("ClockSpeed", 1.0f); + Settings record_settings; if (settings.getChild("Recording", record_settings)) { recording_settings.record_on_move = record_settings.getBool("RecordOnMove", recording_settings.record_on_move); diff --git a/Unreal/Plugins/AirSim/Source/SimMode/SimModeBase.h b/Unreal/Plugins/AirSim/Source/SimMode/SimModeBase.h index edf84dd698..654521ccca 100644 --- a/Unreal/Plugins/AirSim/Source/SimMode/SimModeBase.h +++ b/Unreal/Plugins/AirSim/Source/SimMode/SimModeBase.h @@ -64,7 +64,7 @@ class AIRSIM_API ASimModeBase : public AActor float settings_version_actual; float settings_version_minimum = 1; bool engine_sound; - + float clock_speed; private: void readSettings(); diff --git a/docs/settings.md b/docs/settings.md index e1cf498151..4c5f19a644 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -28,6 +28,7 @@ Below are complete list of settings available along with their default values. I "DefaultVehicleConfig": "", "SimMode": "", "ClockType": "", + "ClockSpeed": "1", "LocalHostIp": "127.0.0.1", "RecordUIVisible": true, "LogMessagesVisible": true, @@ -168,7 +169,5 @@ The recording feature allows you to record data such as position, orientation, v * RecordInterval: specifies minimal interval in seconds between capturing two images. * RecordOnMove: specifies that do not record frame if there was vehicle's position or orientation hasn't changed - - - - +#### ClockSpeed +Determines the speed of simulation clock with respect to wall clock. For example, value of 5.0 would mean simulation clock has 5 seconds elapsed when wall clock has 1 second elapsed (i.e. simulation is running faster). The value of 0.1 means that simulation clock is 10X slower than wall clock. The value of 1 means simulation is running in real time. It is important to realize that quality of simuation may decrease as the simulation clock runs faster. You might see artifacts like object moving past obstacles because collison is not detected. However slowing down simulation clock (i.e. values < 1.0) generally improves the quality of simulation. \ No newline at end of file