From 56c6528ff5d74e4131c2a082a82721094b22ebfb Mon Sep 17 00:00:00 2001 From: Rajat Singhal Date: Thu, 30 Apr 2020 07:13:12 +0530 Subject: [PATCH 1/3] Add simDisableActor API --- AirLib/include/api/RpcLibClientBase.hpp | 2 ++ AirLib/include/api/WorldSimApiBase.hpp | 2 ++ AirLib/src/api/RpcLibClientBase.cpp | 5 +++++ AirLib/src/api/RpcLibServerBase.cpp | 4 ++++ Unreal/Plugins/AirSim/Source/WorldSimApi.cpp | 18 ++++++++++++++++++ Unreal/Plugins/AirSim/Source/WorldSimApi.h | 2 ++ 6 files changed, 33 insertions(+) diff --git a/AirLib/include/api/RpcLibClientBase.hpp b/AirLib/include/api/RpcLibClientBase.hpp index 6dffae6222..f28eb325dd 100644 --- a/AirLib/include/api/RpcLibClientBase.hpp +++ b/AirLib/include/api/RpcLibClientBase.hpp @@ -106,6 +106,8 @@ class RpcLibClientBase { std::vector simSwapTextures(const std::string& tags, int tex_id = 0, int component_id = 0, int material_id = 0); + void simDisableActor(const std::string& object_name); + protected: void* getClient(); const void* getClient() const; diff --git a/AirLib/include/api/WorldSimApiBase.hpp b/AirLib/include/api/WorldSimApiBase.hpp index 035063e771..593c001690 100644 --- a/AirLib/include/api/WorldSimApiBase.hpp +++ b/AirLib/include/api/WorldSimApiBase.hpp @@ -58,6 +58,8 @@ class WorldSimApiBase { virtual std::unique_ptr> swapTextures(const std::string& tag, int tex_id = 0, int component_id = 0, int material_id = 0) = 0; virtual vector getMeshPositionVertexBuffers() const = 0; + + virtual void disableActor(const std::string& object_name) = 0; }; diff --git a/AirLib/src/api/RpcLibClientBase.cpp b/AirLib/src/api/RpcLibClientBase.cpp index 536f392f13..3fcd5f05e5 100644 --- a/AirLib/src/api/RpcLibClientBase.cpp +++ b/AirLib/src/api/RpcLibClientBase.cpp @@ -351,6 +351,11 @@ std::vector RpcLibClientBase::simSwapTextures(const std::string& ta return pimpl_->client.call("simSwapTextures", tags, tex_id, component_id, material_id).as>(); } +void RpcLibClientBase::simDisableActor(const std::string& object_name) +{ + pimpl_->client.call("simDisableActor", object_name); +} + msr::airlib::Pose RpcLibClientBase::simGetObjectPose(const std::string& object_name) const { return pimpl_->client.call("simGetObjectPose", object_name).as().to(); diff --git a/AirLib/src/api/RpcLibServerBase.cpp b/AirLib/src/api/RpcLibServerBase.cpp index 2cb514e0de..77fbe7541a 100644 --- a/AirLib/src/api/RpcLibServerBase.cpp +++ b/AirLib/src/api/RpcLibServerBase.cpp @@ -313,6 +313,10 @@ RpcLibServerBase::RpcLibServerBase(ApiProvider* api_provider, const std::string& return *getWorldSimApi()->swapTextures(tag, tex_id, component_id, material_id); }); + pimpl_->server.bind("simDisableActor", [&](const std::string& object_name) -> void { + getWorldSimApi()->disableActor(object_name); + }); + //if we don't suppress then server will bomb out for exceptions raised by any method pimpl_->server.suppress_exceptions(true); } diff --git a/Unreal/Plugins/AirSim/Source/WorldSimApi.cpp b/Unreal/Plugins/AirSim/Source/WorldSimApi.cpp index c9780e63a0..e9eae6e2f3 100644 --- a/Unreal/Plugins/AirSim/Source/WorldSimApi.cpp +++ b/Unreal/Plugins/AirSim/Source/WorldSimApi.cpp @@ -151,6 +151,24 @@ std::unique_ptr> WorldSimApi::swapTextures(const std::s }, true); return swappedObjectNames; } + +void WorldSimApi::disableActor(const std::string& object_name) +{ + UAirBlueprintLib::RunCommandOnGameThread([this, &object_name]() { + AActor* actor = UAirBlueprintLib::FindActor(simmode_, FString(object_name.c_str())); + if(actor) { + // Hides visible components + actor->SetActorHiddenInGame(true); + + // Disables collision components + actor->SetActorEnableCollision(false); + + // Stops the Actor from ticking + actor->SetActorTickEnabled(false); + } + }, true); +} + //----------- Plotting APIs ----------/ void WorldSimApi::simFlushPersistentMarkers() { diff --git a/Unreal/Plugins/AirSim/Source/WorldSimApi.h b/Unreal/Plugins/AirSim/Source/WorldSimApi.h index c5c7cf55bf..db498d974b 100644 --- a/Unreal/Plugins/AirSim/Source/WorldSimApi.h +++ b/Unreal/Plugins/AirSim/Source/WorldSimApi.h @@ -37,6 +37,8 @@ class WorldSimApi : public msr::airlib::WorldSimApiBase { 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 void disableActor(const std::string& object_name) 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 21e6ea8cdd45bdfadc963bc75fdd5c88ebb202c1 Mon Sep 17 00:00:00 2001 From: Rajat Singhal Date: Fri, 10 Apr 2020 10:12:46 +0530 Subject: [PATCH 2/3] [Unity] Add non-impl simDisableActor API function --- Unity/AirLibWrapper/AirsimWrapper/Source/WorldSimApi.cpp | 7 +++++++ Unity/AirLibWrapper/AirsimWrapper/Source/WorldSimApi.h | 1 + 2 files changed, 8 insertions(+) diff --git a/Unity/AirLibWrapper/AirsimWrapper/Source/WorldSimApi.cpp b/Unity/AirLibWrapper/AirsimWrapper/Source/WorldSimApi.cpp index 823c7f052f..3488d9cde3 100644 --- a/Unity/AirLibWrapper/AirsimWrapper/Source/WorldSimApi.cpp +++ b/Unity/AirLibWrapper/AirsimWrapper/Source/WorldSimApi.cpp @@ -80,6 +80,13 @@ bool WorldSimApi::setObjectPose(const std::string& object_name, const WorldSimAp return SetPose(airSimPose, false, object_name.c_str()); } +void WorldSimApi::disableActor(const std::string& object_name) +{ + unused(object_name); + throw std::invalid_argument(common_utils::Utils::stringf( + "simDisableActor is not supported on unity").c_str()); +} + void WorldSimApi::enableWeather(bool enable) { unused(enable); diff --git a/Unity/AirLibWrapper/AirsimWrapper/Source/WorldSimApi.h b/Unity/AirLibWrapper/AirsimWrapper/Source/WorldSimApi.h index 0acf3f26f0..b9e8e49761 100644 --- a/Unity/AirLibWrapper/AirsimWrapper/Source/WorldSimApi.h +++ b/Unity/AirLibWrapper/AirsimWrapper/Source/WorldSimApi.h @@ -32,6 +32,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 void disableActor(const std::string& object_name) override; //----------- Plotting APIs ----------/ virtual void simFlushPersistentMarkers() override; From 7e7e86514a3bdc2a0f469bf61ca782d68c37572b Mon Sep 17 00:00:00 2001 From: Rajat Singhal Date: Sat, 11 Apr 2020 15:47:11 +0530 Subject: [PATCH 3/3] [PythonClient] Add simDisableActor API --- PythonClient/airsim/client.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/PythonClient/airsim/client.py b/PythonClient/airsim/client.py index b8dde7f0f5..edddec5d14 100644 --- a/PythonClient/airsim/client.py +++ b/PythonClient/airsim/client.py @@ -268,6 +268,15 @@ def simGetMeshPositionVertexBuffers(self): responses_raw = self.client.call('simGetMeshPositionVertexBuffers') return [MeshPositionVertexBuffersResponse.from_msgpack(response_raw) for response_raw in responses_raw] + def simDisableActor(self, object_name): + """ + - Disables an actor from the simulation + + Args: + object_name (str): Name of the object(actor) to be disabled + """ + self.client.call('simDisableActor', object_name) + def simGetCollisionInfo(self, vehicle_name = ''): """ Args: