From 9d4169f2861c3356d52bfe8a1354aac52b2011d9 Mon Sep 17 00:00:00 2001 From: Nicholas Gyde Date: Sat, 2 May 2020 14:05:55 -0700 Subject: [PATCH 01/10] double fixed build.cmd --- build.cmd | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/build.cmd b/build.cmd index 7d4b81d191..2b7e4b6632 100644 --- a/build.cmd +++ b/build.cmd @@ -8,14 +8,14 @@ set "noFullPolyCar=" set "buildMode=" REM //check VS version -if "%VisualStudioVersion%"=="" ( +if "%VisualStudioVersion%" == "" ( echo( - echo oh oh... You need to run this command from x64 Native Tools Command Prompt for VS 2017. + echo oh oh... You need to run this command from x64 Native Tools Command Prompt for VS 2019. goto :buildfailed_nomsg ) -if "%VisualStudioVersion%"=="14.0" ( +if "%VisualStudioVersion%" lss "16.0" ( echo( - echo Hello there! We just upgraded AirSim to Unreal Engine 4.18 and Visual Studio 2017. + echo Hello there! We just upgraded AirSim to Unreal Engine 4.24 and Visual Studio 2019. echo Here are few easy steps for upgrade so everything is new and shiny: echo https://github.com/Microsoft/AirSim/blob/master/docs/unreal_upgrade.md goto :buildfailed_nomsg @@ -78,7 +78,7 @@ ECHO Starting cmake to build rpclib... IF NOT EXIST external\rpclib\rpclib-2.2.1\build mkdir external\rpclib\rpclib-2.2.1\build cd external\rpclib\rpclib-2.2.1\build REM cmake -G"Visual Studio 14 2015 Win64" .. -cmake -G"Visual Studio 15 2017 Win64" .. +cmake -G"Visual Studio 16 2019" .. if "%buildMode%" == "--Debug" ( cmake --build . --config Debug @@ -143,7 +143,7 @@ IF NOT EXIST Unreal\Plugins\AirSim\Content\VehicleAdv\SUV\v1.2.0 ( REM //---------- get Eigen library ---------- IF NOT EXIST AirLib\deps mkdir AirLib\deps IF NOT EXIST AirLib\deps\eigen3 ( - powershell -command "& { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; iwr http://bitbucket.org/eigen/eigen/get/3.3.2.zip -OutFile eigen3.zip }" + powershell -command "& { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; iwr https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.zip -OutFile eigen3.zip }" powershell -command "& { Expand-Archive -Path eigen3.zip -DestinationPath AirLib\deps }" powershell -command "& { Move-Item -Path AirLib\deps\eigen* -Destination AirLib\deps\del_eigen }" REM move AirLib\deps\eigen* AirLib\deps\del_eigen From 72d771cb6b1755e1b531e283837e225b7c594b3e Mon Sep 17 00:00:00 2001 From: Nicholas Gyde Date: Tue, 1 Sep 2020 12:55:55 -0700 Subject: [PATCH 02/10] Created API for running console commands. Unreal has many useful console commands, and user can create their own in the level blueprint. --- AirLib/AirSim.props | 6 ++++++ AirLib/include/api/RpcLibClientBase.hpp | 2 ++ AirLib/include/api/WorldSimApiBase.hpp | 1 + AirLib/src/api/RpcLibClientBase.cpp | 5 +++++ AirLib/src/api/RpcLibServerBase.cpp | 4 ++++ PythonClient/airsim/client.py | 3 +++ Unreal/Plugins/AirSim/Source/AirBlueprintLib.cpp | 8 ++++++++ Unreal/Plugins/AirSim/Source/AirBlueprintLib.h | 3 +++ Unreal/Plugins/AirSim/Source/WorldSimApi.cpp | 10 ++++++++++ Unreal/Plugins/AirSim/Source/WorldSimApi.h | 1 + 10 files changed, 43 insertions(+) create mode 100644 AirLib/AirSim.props diff --git a/AirLib/AirSim.props b/AirLib/AirSim.props new file mode 100644 index 0000000000..d4487d889c --- /dev/null +++ b/AirLib/AirSim.props @@ -0,0 +1,6 @@ + + + $([System.String]::Copy('$(WindowsSDKVersion)').Replace('\','')) + $(AirSimTargetPlatformVersion) + + \ No newline at end of file diff --git a/AirLib/include/api/RpcLibClientBase.hpp b/AirLib/include/api/RpcLibClientBase.hpp index 7f98072743..09616a4336 100644 --- a/AirLib/include/api/RpcLibClientBase.hpp +++ b/AirLib/include/api/RpcLibClientBase.hpp @@ -78,6 +78,8 @@ class RpcLibClientBase { msr::airlib::GeoPoint getHomeGeoPoint(const std::string& vehicle_name = "") const; + bool simRunConsoleCommand(const std::string& command); + // sensor APIs msr::airlib::LidarData getLidarData(const std::string& lidar_name = "", const std::string& vehicle_name = "") const; msr::airlib::ImuBase::Output getImuData(const std::string& imu_name = "", const std::string& vehicle_name = "") const; diff --git a/AirLib/include/api/WorldSimApiBase.hpp b/AirLib/include/api/WorldSimApiBase.hpp index 8607c44ba1..7a7979a1e4 100644 --- a/AirLib/include/api/WorldSimApiBase.hpp +++ b/AirLib/include/api/WorldSimApiBase.hpp @@ -61,6 +61,7 @@ class WorldSimApiBase { virtual Pose getObjectPose(const std::string& object_name) const = 0; virtual Vector3r getObjectScale(const std::string& object_name) const = 0; virtual bool setObjectPose(const std::string& object_name, const Pose& pose, bool teleport) = 0; + virtual bool runConsoleCommand(const std::string& command) = 0; virtual bool setObjectScale(const std::string& object_name, const Vector3r& scale) = 0; virtual std::unique_ptr> swapTextures(const std::string& tag, int tex_id = 0, int component_id = 0, int material_id = 0) = 0; diff --git a/AirLib/src/api/RpcLibClientBase.cpp b/AirLib/src/api/RpcLibClientBase.cpp index be9c01fe80..50095e6b45 100644 --- a/AirLib/src/api/RpcLibClientBase.cpp +++ b/AirLib/src/api/RpcLibClientBase.cpp @@ -405,6 +405,11 @@ void RpcLibClientBase::cancelLastTask(const std::string& vehicle_name) pimpl_->client.call("cancelLastTask", vehicle_name); } +bool RpcLibClientBase::simRunConsoleCommand(const std::string& command) +{ + return pimpl_->client.call("simRunConsoleCommand", command).as(); +} + //return value of last task. It should be true if task completed without //cancellation or timeout RpcLibClientBase* RpcLibClientBase::waitOnLastTask(bool* task_result, float timeout_sec) diff --git a/AirLib/src/api/RpcLibServerBase.cpp b/AirLib/src/api/RpcLibServerBase.cpp index 3123e95f18..9368e1b79e 100644 --- a/AirLib/src/api/RpcLibServerBase.cpp +++ b/AirLib/src/api/RpcLibServerBase.cpp @@ -130,6 +130,10 @@ RpcLibServerBase::RpcLibServerBase(ApiProvider* api_provider, const std::string& return getVehicleApi(vehicle_name)->armDisarm(arm); }); + pimpl_->server.bind("simRunConsoleCommand", [&](const std::string& command) -> bool { + return getWorldSimApi()->runConsoleCommand(command); + }); + pimpl_->server.bind("simGetImages", [&](const std::vector& request_adapter, const std::string& vehicle_name) -> vector { const auto& response = getVehicleSimApi(vehicle_name)->getImages(RpcLibAdapatorsBase::ImageRequest::to(request_adapter)); diff --git a/PythonClient/airsim/client.py b/PythonClient/airsim/client.py index a6553093bd..115a332ad8 100644 --- a/PythonClient/airsim/client.py +++ b/PythonClient/airsim/client.py @@ -255,6 +255,9 @@ def simGetImages(self, requests, vehicle_name = ''): responses_raw = self.client.call('simGetImages', requests, vehicle_name) return [ImageResponse.from_msgpack(response_raw) for response_raw in responses_raw] + def simRunConsoleCommand(self, command): + return self.client.call('simRunConsoleCommand', command) + # gets the static meshes in the unreal scene def simGetMeshPositionVertexBuffers(self): """ diff --git a/Unreal/Plugins/AirSim/Source/AirBlueprintLib.cpp b/Unreal/Plugins/AirSim/Source/AirBlueprintLib.cpp index 58a8ea4f53..8f55ce3bb9 100644 --- a/Unreal/Plugins/AirSim/Source/AirBlueprintLib.cpp +++ b/Unreal/Plugins/AirSim/Source/AirBlueprintLib.cpp @@ -575,6 +575,14 @@ UObject* UAirBlueprintLib::GetMeshFromRegistry(const std::string& load_object) return LoadObject; } +bool UAirBlueprintLib::RunConsoleCommand(const AActor* context, const FString& command) +{ + auto* playerController = UGameplayStatics::GetPlayerController(context->GetWorld(), 0);; + if (playerController != nullptr) + playerController->ConsoleCommand(command, true); + return playerController != nullptr; +} + bool UAirBlueprintLib::HasObstacle(const AActor* actor, const FVector& start, const FVector& end, const AActor* ignore_actor, ECollisionChannel collision_channel) { FCollisionQueryParams trace_params; diff --git a/Unreal/Plugins/AirSim/Source/AirBlueprintLib.h b/Unreal/Plugins/AirSim/Source/AirBlueprintLib.h index bddcff4dbb..4081e4133f 100644 --- a/Unreal/Plugins/AirSim/Source/AirBlueprintLib.h +++ b/Unreal/Plugins/AirSim/Source/AirBlueprintLib.h @@ -86,6 +86,9 @@ class UAirBlueprintLib : public UBlueprintFunctionLibrary static TArray ListWorldsInRegistry(); static UObject* GetMeshFromRegistry(const std::string& load_object); + UFUNCTION(BlueprintCallable, Category = "AirSim") + static bool RunConsoleCommand(const AActor* context, const FString& command); + static bool HasObstacle(const AActor* actor, const FVector& start, const FVector& end, const AActor* ignore_actor = nullptr, ECollisionChannel collision_channel = ECC_Visibility); static bool GetObstacle(const AActor* actor, const FVector& start, const FVector& end, diff --git a/Unreal/Plugins/AirSim/Source/WorldSimApi.cpp b/Unreal/Plugins/AirSim/Source/WorldSimApi.cpp index 4a60712435..886e75c082 100644 --- a/Unreal/Plugins/AirSim/Source/WorldSimApi.cpp +++ b/Unreal/Plugins/AirSim/Source/WorldSimApi.cpp @@ -200,6 +200,16 @@ std::vector WorldSimApi::listSceneObjects(const std::string& name_r return result; } +bool WorldSimApi::runConsoleCommand(const std::string& command) +{ + bool succeeded = false; + UAirBlueprintLib::RunCommandOnGameThread([this, &command, &succeeded]() { + FString fStringCommand(command.c_str()); + succeeded = UAirBlueprintLib::RunConsoleCommand(simmode_, fStringCommand); + }, true); + return succeeded; +} + WorldSimApi::Pose WorldSimApi::getObjectPose(const std::string& object_name) const { Pose result; diff --git a/Unreal/Plugins/AirSim/Source/WorldSimApi.h b/Unreal/Plugins/AirSim/Source/WorldSimApi.h index a3aef5861c..6b7dcd0317 100644 --- a/Unreal/Plugins/AirSim/Source/WorldSimApi.h +++ b/Unreal/Plugins/AirSim/Source/WorldSimApi.h @@ -44,6 +44,7 @@ class WorldSimApi : public msr::airlib::WorldSimApiBase { virtual std::vector listSceneObjects(const std::string& name_regex) const override; virtual Pose getObjectPose(const std::string& object_name) const override; virtual bool setObjectPose(const std::string& object_name, const Pose& pose, bool teleport) override; + virtual bool runConsoleCommand(const std::string& command) override; virtual Vector3r getObjectScale(const std::string& object_name) const override; virtual bool setObjectScale(const std::string& object_name, const Vector3r& scale) override; From fa0fc6a3246b949862c75c0d79a8dbd6bd60a819 Mon Sep 17 00:00:00 2001 From: Ratnesh Madaan Date: Tue, 1 Sep 2020 15:05:05 -0700 Subject: [PATCH 03/10] Delete AirSim.props --- AirLib/AirSim.props | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 AirLib/AirSim.props diff --git a/AirLib/AirSim.props b/AirLib/AirSim.props deleted file mode 100644 index d4487d889c..0000000000 --- a/AirLib/AirSim.props +++ /dev/null @@ -1,6 +0,0 @@ - - - $([System.String]::Copy('$(WindowsSDKVersion)').Replace('\','')) - $(AirSimTargetPlatformVersion) - - \ No newline at end of file From 0463f6c408c380c1360136ec91704e1f60a0e5d0 Mon Sep 17 00:00:00 2001 From: Nicholas Gyde Date: Wed, 2 Sep 2020 14:16:17 -0700 Subject: [PATCH 04/10] Added docstring and example script. --- PythonClient/airsim/client.py | 5 ++++- PythonClient/environment/ConsoleCommands.py | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 PythonClient/environment/ConsoleCommands.py diff --git a/PythonClient/airsim/client.py b/PythonClient/airsim/client.py index 115a332ad8..1728f98441 100644 --- a/PythonClient/airsim/client.py +++ b/PythonClient/airsim/client.py @@ -254,7 +254,10 @@ def simGetImages(self, requests, vehicle_name = ''): """ responses_raw = self.client.call('simGetImages', requests, vehicle_name) return [ImageResponse.from_msgpack(response_raw) for response_raw in responses_raw] - + + #Allows the client to execute a command in Unreal's native console, via an API. + #Affords access to the countless built-in commands such as "stat unit", "stat fps", "open [map]", adjust any config settings, etc. etc. + #Allows the user to create bespoke APIs very easily, by adding a custom event to the level blueprint, and then calling the console command "ce MyEventName [args]". No recompilation of AirSim needed! def simRunConsoleCommand(self, command): return self.client.call('simRunConsoleCommand', command) diff --git a/PythonClient/environment/ConsoleCommands.py b/PythonClient/environment/ConsoleCommands.py new file mode 100644 index 0000000000..1f2347d069 --- /dev/null +++ b/PythonClient/environment/ConsoleCommands.py @@ -0,0 +1,16 @@ +import airsim + +def EstablishClientConnection(): + c = airsim.client.MultirotorClient() + c.confirmConnection() + return c + +def TogglePerformanceInfo(client): + client.simRunConsoleCommand('stat fps') + client.simRunConsoleCommand('stat unit') + client.simRunConsoleCommand('stat unitGraph') + + +if __name__ == "__main__": + client = EstablishClientConnection() + TogglePerformanceInfo(client) \ No newline at end of file From 104403cb897e2b2d6be3d170e1df2b4b47f7611d Mon Sep 17 00:00:00 2001 From: madratman Date: Wed, 2 Sep 2020 14:29:07 -0700 Subject: [PATCH 05/10] add collision view to consol cmd script, move weather and markers to environment/ dir --- PythonClient/environment/plot_markers.py | 63 +++++++++++++++++++ ...Commands.py => unreal_console_commands.py} | 3 +- PythonClient/environment/weather.py | 34 ++++++++++ 3 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 PythonClient/environment/plot_markers.py rename PythonClient/environment/{ConsoleCommands.py => unreal_console_commands.py} (81%) create mode 100644 PythonClient/environment/weather.py diff --git a/PythonClient/environment/plot_markers.py b/PythonClient/environment/plot_markers.py new file mode 100644 index 0000000000..d005ff8338 --- /dev/null +++ b/PythonClient/environment/plot_markers.py @@ -0,0 +1,63 @@ +import setup_path +import airsim +from airsim import Vector3r, Quaternionr, Pose +from airsim.utils import to_quaternion +import numpy as np +import time + +client = airsim.VehicleClient() +client.confirmConnection() + +# plot red arrows for 30 seconds +client.simPlotArrows(points_start = [Vector3r(x,y,0) for x, y in zip(np.linspace(0,10,20), np.linspace(0,0,20))], + points_end = [Vector3r(x,y,0) for x, y in zip(np.linspace(0,10,20), np.linspace(10,10,20))], + color_rgba = [1.0, 0.0, 1.0, 1.0], duration = 30.0, arrow_size = 10, thickness = 1) + +# plot magenta arrows for 15 seconds +client.simPlotArrows(points_start = [Vector3r(x,y,-3) for x, y in zip(np.linspace(0,10,20), np.linspace(0,0,20))], + points_end = [Vector3r(x,y,-5) for x, y in zip(np.linspace(0,10,20), np.linspace(10,20,20))], + color_rgba = [1.0, 1.0, 0.0, 1.0], duration = 15.0, arrow_size = 20, thickness = 3) + +# plot red arrows for 10 seconds +client.simPlotArrows(points_start = [Vector3r(x,y,z) for x, y, z in zip(np.linspace(0,10,20), np.linspace(0,0,20), np.linspace(-3,-10, 20))], + points_end = [Vector3r(x,y,z) for x, y, z in zip(np.linspace(0,10,20), np.linspace(10,20,20), np.linspace(-5,-8, 20))], + color_rgba = [1.0, 0.0, 0.0, 1.0], duration = 10.0, arrow_size = 100, thickness = 5) + +# plot 2 white arrows which are persistent +client.simPlotArrows(points_start = [Vector3r(x,y,-2) for x, y in zip(np.linspace(0,10,20), np.linspace(0,20,20))], + points_end = [Vector3r(x,y,-5) for x, y in zip(np.linspace(3,17,20), np.linspace(5,28,20))], + color_rgba = [1.0, 1.0, 1.0, 1.0], duration = 5.0, arrow_size = 100, thickness = 1, is_persistent = True) + +# plot points +client.simPlotPoints(points = [Vector3r(x,y,-5) for x, y in zip(np.linspace(0,-10,20), np.linspace(0,-20,20))], color_rgba=[1.0, 0.0, 0.0, 1.0], size = 25, duration = 20.0, is_persistent = False) +client.simPlotPoints(points = [Vector3r(x,y,z) for x, y, z in zip(np.linspace(0,-10,20), np.linspace(0,-20,20), np.linspace(0,-5,20))], color_rgba=[0.0, 0.0, 1.0, 1.0], size = 10, duration = 20.0, is_persistent = False) +client.simPlotPoints(points = [Vector3r(x,y,z) for x, y, z in zip(np.linspace(0,10,20), np.linspace(0,-20,20), np.linspace(0,-7,20))], color_rgba=[1.0, 0.0, 1.0, 1.0], size = 15, duration = 20.0, is_persistent = False) + +# plot line strip. 0-1, 1-2, 2-3 +client.simPlotLineStrip(points = [Vector3r(x,y,-5) for x, y in zip(np.linspace(0,-10,10), np.linspace(0,-20,10))], color_rgba=[1.0, 0.0, 0.0, 1.0], thickness = 5, duration = 30.0, is_persistent = False) + +# plot line list. 0-1, 2-3, 4-5. Must be even. +client.simPlotLineList(points = [Vector3r(x,y,-7) for x, y in zip(np.linspace(0,-10,10), np.linspace(0,-20,10))], color_rgba=[1.0, 0.0, 0.0, 1.0], thickness = 5, duration = 30.0, is_persistent = False) + +# plot transforms +client.simPlotStrings(strings = ["Microsoft AirSim" for i in range(5)], positions = [Vector3r(x,y,-1) for x, y in zip(np.linspace(0,5,5), np.linspace(0,0,5))], + scale = 1, color_rgba=[1.0, 1.0, 1.0, 1.0], duration = 1200.0) + +# client.simPlotTransforms(poses = [Pose(position_val=Vector3r(x,y,0), orientation_val=to_quaternion(pitch=0.0, roll=0.0, yaw=yaw)) for x, y, yaw in zip(np.linspace(0,10,10), np.linspace(0,0,10), np.linspace(0,np.pi,10))], +# scale = 35, thickness = 5, duration = 1200.0, is_persistent = False) + +# client.simPlotTransforms(poses = [Pose(position_val=Vector3r(x,y,0), orientation_val=to_quaternion(pitch=0.0, roll=roll, yaw=0.0)) for x, y, roll in zip(np.linspace(0,10,10), np.linspace(1,1,10), np.linspace(0,np.pi,10))], +# scale = 35, thickness = 5, duration = 1200.0, is_persistent = False) + +client.simPlotTransformsWithNames(poses = [Pose(position_val=Vector3r(x,y,0), orientation_val=to_quaternion(pitch=0.0, roll=0.0, yaw=yaw)) for x, y, yaw in zip(np.linspace(0,10,10), np.linspace(0,0,10), np.linspace(0,np.pi,10))], + names=["tf_yaw_" + str(idx) for idx in range(10)], tf_scale = 35, tf_thickness = 5, text_scale = 1, text_color_rgba = [1.0, 1.0, 1.0, 1.0], duration = 1200.0) + +client.simPlotTransformsWithNames(poses = [Pose(position_val=Vector3r(x,y,0), orientation_val=to_quaternion(pitch=0.0, roll=roll, yaw=0.0)) for x, y, roll in zip(np.linspace(0,10,10), np.linspace(1,1,10), np.linspace(0,np.pi,10))], + names=["tf_roll_" + str(idx) for idx in range(10)], tf_scale = 35, tf_thickness = 5, text_scale = 1, text_color_rgba = [1.0, 1.0, 1.0, 1.0], duration = 1200.0) + +client.simPlotTransformsWithNames(poses = [Pose(position_val=Vector3r(x,y,0), orientation_val=to_quaternion(pitch=pitch, roll=0.0, yaw=0.0)) for x, y, pitch in zip(np.linspace(0,10,10), np.linspace(-1,-1,10), np.linspace(0,np.pi,10))], + names=["tf_pitch_" + str(idx) for idx in range(10)], tf_scale = 35, tf_thickness = 5, text_scale = 1, text_color_rgba = [1.0, 1.0, 1.0, 1.0], duration = 1200.0) + +time.sleep(20.0) + +client.simFlushPersistentMarkers() \ No newline at end of file diff --git a/PythonClient/environment/ConsoleCommands.py b/PythonClient/environment/unreal_console_commands.py similarity index 81% rename from PythonClient/environment/ConsoleCommands.py rename to PythonClient/environment/unreal_console_commands.py index 1f2347d069..53de9cca5a 100644 --- a/PythonClient/environment/ConsoleCommands.py +++ b/PythonClient/environment/unreal_console_commands.py @@ -9,7 +9,8 @@ def TogglePerformanceInfo(client): client.simRunConsoleCommand('stat fps') client.simRunConsoleCommand('stat unit') client.simRunConsoleCommand('stat unitGraph') - + client.simRunConsoleCommand('show COLLISION') + client.simRunConsoleCommand('stat game') if __name__ == "__main__": client = EstablishClientConnection() diff --git a/PythonClient/environment/weather.py b/PythonClient/environment/weather.py new file mode 100644 index 0000000000..21f598c717 --- /dev/null +++ b/PythonClient/environment/weather.py @@ -0,0 +1,34 @@ +import setup_path +import airsim + + +client = airsim.VehicleClient() +client.confirmConnection() + +client.simEnableWeather(True) + +airsim.wait_key('Press any key to enable rain at 25%') +client.simSetWeatherParameter(airsim.WeatherParameter.Rain, 0.25); + +airsim.wait_key('Press any key to enable rain at 75%') +client.simSetWeatherParameter(airsim.WeatherParameter.Rain, 0.75); + +airsim.wait_key('Press any key to enable snow at 50%') +client.simSetWeatherParameter(airsim.WeatherParameter.Snow, 0.50); + +airsim.wait_key('Press any key to enable maple leaves at 50%') +client.simSetWeatherParameter(airsim.WeatherParameter.MapleLeaf, 0.50); + +airsim.wait_key('Press any key to set all effects to 0%') +client.simSetWeatherParameter(airsim.WeatherParameter.Rain, 0.0); +client.simSetWeatherParameter(airsim.WeatherParameter.Snow, 0.0); +client.simSetWeatherParameter(airsim.WeatherParameter.MapleLeaf, 0.0); + +airsim.wait_key('Press any key to enable dust at 50%') +client.simSetWeatherParameter(airsim.WeatherParameter.Dust, 0.50); + +airsim.wait_key('Press any key to enable fog at 50%') +client.simSetWeatherParameter(airsim.WeatherParameter.Fog, 0.50); + +airsim.wait_key('Press any key to disable all weather effects') +client.simEnableWeather(False) From 3223dfa0e3f906abf410f0fa4bb18ebfd55aa8af Mon Sep 17 00:00:00 2001 From: madratman Date: Wed, 2 Sep 2020 14:29:26 -0700 Subject: [PATCH 06/10] bla --- PythonClient/computer_vision/plot_markers.py | 63 -------------------- PythonClient/computer_vision/weather.py | 34 ----------- 2 files changed, 97 deletions(-) delete mode 100644 PythonClient/computer_vision/plot_markers.py delete mode 100644 PythonClient/computer_vision/weather.py diff --git a/PythonClient/computer_vision/plot_markers.py b/PythonClient/computer_vision/plot_markers.py deleted file mode 100644 index d005ff8338..0000000000 --- a/PythonClient/computer_vision/plot_markers.py +++ /dev/null @@ -1,63 +0,0 @@ -import setup_path -import airsim -from airsim import Vector3r, Quaternionr, Pose -from airsim.utils import to_quaternion -import numpy as np -import time - -client = airsim.VehicleClient() -client.confirmConnection() - -# plot red arrows for 30 seconds -client.simPlotArrows(points_start = [Vector3r(x,y,0) for x, y in zip(np.linspace(0,10,20), np.linspace(0,0,20))], - points_end = [Vector3r(x,y,0) for x, y in zip(np.linspace(0,10,20), np.linspace(10,10,20))], - color_rgba = [1.0, 0.0, 1.0, 1.0], duration = 30.0, arrow_size = 10, thickness = 1) - -# plot magenta arrows for 15 seconds -client.simPlotArrows(points_start = [Vector3r(x,y,-3) for x, y in zip(np.linspace(0,10,20), np.linspace(0,0,20))], - points_end = [Vector3r(x,y,-5) for x, y in zip(np.linspace(0,10,20), np.linspace(10,20,20))], - color_rgba = [1.0, 1.0, 0.0, 1.0], duration = 15.0, arrow_size = 20, thickness = 3) - -# plot red arrows for 10 seconds -client.simPlotArrows(points_start = [Vector3r(x,y,z) for x, y, z in zip(np.linspace(0,10,20), np.linspace(0,0,20), np.linspace(-3,-10, 20))], - points_end = [Vector3r(x,y,z) for x, y, z in zip(np.linspace(0,10,20), np.linspace(10,20,20), np.linspace(-5,-8, 20))], - color_rgba = [1.0, 0.0, 0.0, 1.0], duration = 10.0, arrow_size = 100, thickness = 5) - -# plot 2 white arrows which are persistent -client.simPlotArrows(points_start = [Vector3r(x,y,-2) for x, y in zip(np.linspace(0,10,20), np.linspace(0,20,20))], - points_end = [Vector3r(x,y,-5) for x, y in zip(np.linspace(3,17,20), np.linspace(5,28,20))], - color_rgba = [1.0, 1.0, 1.0, 1.0], duration = 5.0, arrow_size = 100, thickness = 1, is_persistent = True) - -# plot points -client.simPlotPoints(points = [Vector3r(x,y,-5) for x, y in zip(np.linspace(0,-10,20), np.linspace(0,-20,20))], color_rgba=[1.0, 0.0, 0.0, 1.0], size = 25, duration = 20.0, is_persistent = False) -client.simPlotPoints(points = [Vector3r(x,y,z) for x, y, z in zip(np.linspace(0,-10,20), np.linspace(0,-20,20), np.linspace(0,-5,20))], color_rgba=[0.0, 0.0, 1.0, 1.0], size = 10, duration = 20.0, is_persistent = False) -client.simPlotPoints(points = [Vector3r(x,y,z) for x, y, z in zip(np.linspace(0,10,20), np.linspace(0,-20,20), np.linspace(0,-7,20))], color_rgba=[1.0, 0.0, 1.0, 1.0], size = 15, duration = 20.0, is_persistent = False) - -# plot line strip. 0-1, 1-2, 2-3 -client.simPlotLineStrip(points = [Vector3r(x,y,-5) for x, y in zip(np.linspace(0,-10,10), np.linspace(0,-20,10))], color_rgba=[1.0, 0.0, 0.0, 1.0], thickness = 5, duration = 30.0, is_persistent = False) - -# plot line list. 0-1, 2-3, 4-5. Must be even. -client.simPlotLineList(points = [Vector3r(x,y,-7) for x, y in zip(np.linspace(0,-10,10), np.linspace(0,-20,10))], color_rgba=[1.0, 0.0, 0.0, 1.0], thickness = 5, duration = 30.0, is_persistent = False) - -# plot transforms -client.simPlotStrings(strings = ["Microsoft AirSim" for i in range(5)], positions = [Vector3r(x,y,-1) for x, y in zip(np.linspace(0,5,5), np.linspace(0,0,5))], - scale = 1, color_rgba=[1.0, 1.0, 1.0, 1.0], duration = 1200.0) - -# client.simPlotTransforms(poses = [Pose(position_val=Vector3r(x,y,0), orientation_val=to_quaternion(pitch=0.0, roll=0.0, yaw=yaw)) for x, y, yaw in zip(np.linspace(0,10,10), np.linspace(0,0,10), np.linspace(0,np.pi,10))], -# scale = 35, thickness = 5, duration = 1200.0, is_persistent = False) - -# client.simPlotTransforms(poses = [Pose(position_val=Vector3r(x,y,0), orientation_val=to_quaternion(pitch=0.0, roll=roll, yaw=0.0)) for x, y, roll in zip(np.linspace(0,10,10), np.linspace(1,1,10), np.linspace(0,np.pi,10))], -# scale = 35, thickness = 5, duration = 1200.0, is_persistent = False) - -client.simPlotTransformsWithNames(poses = [Pose(position_val=Vector3r(x,y,0), orientation_val=to_quaternion(pitch=0.0, roll=0.0, yaw=yaw)) for x, y, yaw in zip(np.linspace(0,10,10), np.linspace(0,0,10), np.linspace(0,np.pi,10))], - names=["tf_yaw_" + str(idx) for idx in range(10)], tf_scale = 35, tf_thickness = 5, text_scale = 1, text_color_rgba = [1.0, 1.0, 1.0, 1.0], duration = 1200.0) - -client.simPlotTransformsWithNames(poses = [Pose(position_val=Vector3r(x,y,0), orientation_val=to_quaternion(pitch=0.0, roll=roll, yaw=0.0)) for x, y, roll in zip(np.linspace(0,10,10), np.linspace(1,1,10), np.linspace(0,np.pi,10))], - names=["tf_roll_" + str(idx) for idx in range(10)], tf_scale = 35, tf_thickness = 5, text_scale = 1, text_color_rgba = [1.0, 1.0, 1.0, 1.0], duration = 1200.0) - -client.simPlotTransformsWithNames(poses = [Pose(position_val=Vector3r(x,y,0), orientation_val=to_quaternion(pitch=pitch, roll=0.0, yaw=0.0)) for x, y, pitch in zip(np.linspace(0,10,10), np.linspace(-1,-1,10), np.linspace(0,np.pi,10))], - names=["tf_pitch_" + str(idx) for idx in range(10)], tf_scale = 35, tf_thickness = 5, text_scale = 1, text_color_rgba = [1.0, 1.0, 1.0, 1.0], duration = 1200.0) - -time.sleep(20.0) - -client.simFlushPersistentMarkers() \ No newline at end of file diff --git a/PythonClient/computer_vision/weather.py b/PythonClient/computer_vision/weather.py deleted file mode 100644 index 21f598c717..0000000000 --- a/PythonClient/computer_vision/weather.py +++ /dev/null @@ -1,34 +0,0 @@ -import setup_path -import airsim - - -client = airsim.VehicleClient() -client.confirmConnection() - -client.simEnableWeather(True) - -airsim.wait_key('Press any key to enable rain at 25%') -client.simSetWeatherParameter(airsim.WeatherParameter.Rain, 0.25); - -airsim.wait_key('Press any key to enable rain at 75%') -client.simSetWeatherParameter(airsim.WeatherParameter.Rain, 0.75); - -airsim.wait_key('Press any key to enable snow at 50%') -client.simSetWeatherParameter(airsim.WeatherParameter.Snow, 0.50); - -airsim.wait_key('Press any key to enable maple leaves at 50%') -client.simSetWeatherParameter(airsim.WeatherParameter.MapleLeaf, 0.50); - -airsim.wait_key('Press any key to set all effects to 0%') -client.simSetWeatherParameter(airsim.WeatherParameter.Rain, 0.0); -client.simSetWeatherParameter(airsim.WeatherParameter.Snow, 0.0); -client.simSetWeatherParameter(airsim.WeatherParameter.MapleLeaf, 0.0); - -airsim.wait_key('Press any key to enable dust at 50%') -client.simSetWeatherParameter(airsim.WeatherParameter.Dust, 0.50); - -airsim.wait_key('Press any key to enable fog at 50%') -client.simSetWeatherParameter(airsim.WeatherParameter.Fog, 0.50); - -airsim.wait_key('Press any key to disable all weather effects') -client.simEnableWeather(False) From a9cf6084b6dc4d90cb581b8c61795ffb98e40527 Mon Sep 17 00:00:00 2001 From: madratman Date: Wed, 2 Sep 2020 14:44:37 -0700 Subject: [PATCH 07/10] more collision cmds in example script --- .../environment/unreal_console_commands.py | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/PythonClient/environment/unreal_console_commands.py b/PythonClient/environment/unreal_console_commands.py index 53de9cca5a..7090ea4377 100644 --- a/PythonClient/environment/unreal_console_commands.py +++ b/PythonClient/environment/unreal_console_commands.py @@ -1,17 +1,29 @@ import airsim +import time -def EstablishClientConnection(): - c = airsim.client.MultirotorClient() - c.confirmConnection() - return c +def RunConsoleCmd(client, cmd): + client.simRunConsoleCommand(cmd) + print(f"Running Unreal Console cmd '{cmd}' and sleeping for 1 second") + time.sleep(1.0) -def TogglePerformanceInfo(client): - client.simRunConsoleCommand('stat fps') - client.simRunConsoleCommand('stat unit') - client.simRunConsoleCommand('stat unitGraph') - client.simRunConsoleCommand('show COLLISION') - client.simRunConsoleCommand('stat game') +def RunCmdList(client): + RunConsoleCmd(client, 'stat fps') + RunConsoleCmd(client, 'stat unit') + RunConsoleCmd(client, 'stat unitGraph') + RunConsoleCmd(client, 'show COLLISION') + RunConsoleCmd(client, 'show CollisionVisibility') + RunConsoleCmd(client, 'stat game') + RunConsoleCmd(client, 'show COLLISION') + RunConsoleCmd(client, 'show CollisionVisibility') + RunConsoleCmd(client, 'stat game') + RunConsoleCmd(client, 'stat unitGraph') + RunConsoleCmd(client, 'stat unit') + RunConsoleCmd(client, 'stat fps') + +def main(): + client = airsim.client.MultirotorClient() + client.confirmConnection() + RunCmdList(client) if __name__ == "__main__": - client = EstablishClientConnection() - TogglePerformanceInfo(client) \ No newline at end of file + main() From 744b479bf00f0c5fbd82ee2bfcb24b45bc189fc2 Mon Sep 17 00:00:00 2001 From: Nicholas Gyde Date: Wed, 2 Sep 2020 14:53:28 -0700 Subject: [PATCH 08/10] Added stub for new API in Unity. --- Unity/AirLibWrapper/AirsimWrapper/Source/WorldSimApi.cpp | 7 +++++++ Unity/AirLibWrapper/AirsimWrapper/Source/WorldSimApi.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/Unity/AirLibWrapper/AirsimWrapper/Source/WorldSimApi.cpp b/Unity/AirLibWrapper/AirsimWrapper/Source/WorldSimApi.cpp index d352439ca0..acd14a5549 100644 --- a/Unity/AirLibWrapper/AirsimWrapper/Source/WorldSimApi.cpp +++ b/Unity/AirLibWrapper/AirsimWrapper/Source/WorldSimApi.cpp @@ -84,6 +84,13 @@ bool WorldSimApi::setObjectPose(const std::string& object_name, const WorldSimAp return SetPose(airSimPose, false, object_name.c_str()); } +bool WorldSimApi::runConsoleCommand(const std::string& command) +{ + throw std::invalid_argument(common_utils::Utils::stringf( + "simListSceneObject is not supported on unity").c_str()); + return false; +} + void WorldSimApi::enableWeather(bool enable) { unused(enable); diff --git a/Unity/AirLibWrapper/AirsimWrapper/Source/WorldSimApi.h b/Unity/AirLibWrapper/AirsimWrapper/Source/WorldSimApi.h index b81df7648b..9bf7293883 100644 --- a/Unity/AirLibWrapper/AirsimWrapper/Source/WorldSimApi.h +++ b/Unity/AirLibWrapper/AirsimWrapper/Source/WorldSimApi.h @@ -43,6 +43,8 @@ class WorldSimApi : public msr::airlib::WorldSimApiBase virtual bool setObjectPose(const std::string& object_name, const Pose& pose, bool teleport) override; virtual bool setObjectScale(const std::string& object_name, const Vector3r& scale) override; + virtual bool runConsoleCommand(const std::string& command) override; + //----------- Plotting APIs ----------/ virtual void simFlushPersistentMarkers() override; virtual void simPlotPoints(const std::vector& points, const std::vector& color_rgba, float size, float duration, bool is_persistent) override; From 775fa8bb7797e86f360e75d02b60f29de9dd0a5d Mon Sep 17 00:00:00 2001 From: madratman Date: Wed, 2 Sep 2020 15:00:28 -0700 Subject: [PATCH 09/10] fix typo in unity non impl --- Unity/AirLibWrapper/AirsimWrapper/Source/WorldSimApi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Unity/AirLibWrapper/AirsimWrapper/Source/WorldSimApi.cpp b/Unity/AirLibWrapper/AirsimWrapper/Source/WorldSimApi.cpp index acd14a5549..36d3d37ff3 100644 --- a/Unity/AirLibWrapper/AirsimWrapper/Source/WorldSimApi.cpp +++ b/Unity/AirLibWrapper/AirsimWrapper/Source/WorldSimApi.cpp @@ -87,7 +87,7 @@ bool WorldSimApi::setObjectPose(const std::string& object_name, const WorldSimAp bool WorldSimApi::runConsoleCommand(const std::string& command) { throw std::invalid_argument(common_utils::Utils::stringf( - "simListSceneObject is not supported on unity").c_str()); + "simrunConsoleCommand is not supported on unity").c_str()); return false; } From 09bf5487c39dea0b542a0d9a56d7adc6decc79b6 Mon Sep 17 00:00:00 2001 From: madratman Date: Wed, 2 Sep 2020 15:01:06 -0700 Subject: [PATCH 10/10] fix docstring syntax --- PythonClient/airsim/client.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/PythonClient/airsim/client.py b/PythonClient/airsim/client.py index 1728f98441..bee5b5350e 100644 --- a/PythonClient/airsim/client.py +++ b/PythonClient/airsim/client.py @@ -255,10 +255,18 @@ def simGetImages(self, requests, vehicle_name = ''): responses_raw = self.client.call('simGetImages', requests, vehicle_name) return [ImageResponse.from_msgpack(response_raw) for response_raw in responses_raw] - #Allows the client to execute a command in Unreal's native console, via an API. - #Affords access to the countless built-in commands such as "stat unit", "stat fps", "open [map]", adjust any config settings, etc. etc. - #Allows the user to create bespoke APIs very easily, by adding a custom event to the level blueprint, and then calling the console command "ce MyEventName [args]". No recompilation of AirSim needed! def simRunConsoleCommand(self, command): + """ + Allows the client to execute a command in Unreal's native console, via an API. + Affords access to the countless built-in commands such as "stat unit", "stat fps", "open [map]", adjust any config settings, etc. etc. + Allows the user to create bespoke APIs very easily, by adding a custom event to the level blueprint, and then calling the console command "ce MyEventName [args]". No recompilation of AirSim needed! + + Args: + command ([string]): Desired Unreal Engine Console command to run + + Returns: + [bool]: Success + """ return self.client.call('simRunConsoleCommand', command) # gets the static meshes in the unreal scene