From 9167f93e2738a88944a31ddff7c41db6c2b998fb Mon Sep 17 00:00:00 2001 From: Rajat Singhal Date: Thu, 3 Sep 2020 07:44:20 +0530 Subject: [PATCH 1/2] [UE] Run Weather APIs on Game thread --- Unreal/Plugins/AirSim/Source/WorldSimApi.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Unreal/Plugins/AirSim/Source/WorldSimApi.cpp b/Unreal/Plugins/AirSim/Source/WorldSimApi.cpp index c7195f8dde..6a880703d7 100644 --- a/Unreal/Plugins/AirSim/Source/WorldSimApi.cpp +++ b/Unreal/Plugins/AirSim/Source/WorldSimApi.cpp @@ -377,7 +377,10 @@ bool WorldSimApi::setObjectScale(const std::string& object_name, const Vector3r& void WorldSimApi::enableWeather(bool enable) { - UWeatherLib::setWeatherEnabled(simmode_->GetWorld(), enable); + UAirBlueprintLib::RunCommandOnGameThread([this, enable]() { + UWeatherLib::setWeatherEnabled(simmode_->GetWorld(), enable); + }, + true); } void WorldSimApi::setWeatherParameter(WeatherParameter param, float val) @@ -385,7 +388,10 @@ void WorldSimApi::setWeatherParameter(WeatherParameter param, float val) unsigned char param_n = static_cast(msr::airlib::Utils::toNumeric(param)); EWeatherParamScalar param_e = msr::airlib::Utils::toEnum(param_n); - UWeatherLib::setWeatherParamScalar(simmode_->GetWorld(), param_e, val); + UAirBlueprintLib::RunCommandOnGameThread([this, param_e, val]() { + UWeatherLib::setWeatherParamScalar(simmode_->GetWorld(), param_e, val); + }, + true); } std::unique_ptr> WorldSimApi::swapTextures(const std::string& tag, int tex_id, int component_id, int material_id) From c9cd185f7329c709d66a95025390006144f936c5 Mon Sep 17 00:00:00 2001 From: Rajat Singhal Date: Mon, 7 Sep 2020 17:05:43 +0530 Subject: [PATCH 2/2] [Pythonclient] Add missing setup_path.py in environment folder --- PythonClient/environment/setup_path.py | 52 ++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 PythonClient/environment/setup_path.py diff --git a/PythonClient/environment/setup_path.py b/PythonClient/environment/setup_path.py new file mode 100644 index 0000000000..362113fea8 --- /dev/null +++ b/PythonClient/environment/setup_path.py @@ -0,0 +1,52 @@ +# Import this module to automatically setup path to local airsim module +# This module first tries to see if airsim module is installed via pip +# If it does then we don't do anything else +# Else we look up grand-parent folder to see if it has airsim folder +# and if it does then we add that in sys.path + +import os,sys,inspect,logging + +#this class simply tries to see if airsim +class SetupPath: + @staticmethod + def getDirLevels(path): + path_norm = os.path.normpath(path) + return len(path_norm.split(os.sep)) + + @staticmethod + def getCurrentPath(): + cur_filepath = os.path.abspath(inspect.getfile(inspect.currentframe())) + return os.path.dirname(cur_filepath) + + @staticmethod + def getGrandParentDir(): + cur_path = SetupPath.getCurrentPath() + if SetupPath.getDirLevels(cur_path) >= 2: + return os.path.dirname(os.path.dirname(cur_path)) + return '' + + @staticmethod + def getParentDir(): + cur_path = SetupPath.getCurrentPath() + if SetupPath.getDirLevels(cur_path) >= 1: + return os.path.dirname(cur_path) + return '' + + @staticmethod + def addAirSimModulePath(): + # if airsim module is installed then don't do anything else + #import pkgutil + #airsim_loader = pkgutil.find_loader('airsim') + #if airsim_loader is not None: + # return + + parent = SetupPath.getParentDir() + if parent != '': + airsim_path = os.path.join(parent, 'airsim') + client_path = os.path.join(airsim_path, 'client.py') + if os.path.exists(client_path): + sys.path.insert(0, parent) + else: + logging.warning("airsim module not found in parent folder. Using installed package (pip install airsim).") + +SetupPath.addAirSimModulePath()