Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simDisableActor API #2561

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions AirLib/include/api/RpcLibClientBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ class RpcLibClientBase {

std::vector<std::string> 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;
Expand Down
2 changes: 2 additions & 0 deletions AirLib/include/api/WorldSimApiBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class WorldSimApiBase {

virtual std::unique_ptr<std::vector<std::string>> swapTextures(const std::string& tag, int tex_id = 0, int component_id = 0, int material_id = 0) = 0;
virtual vector<MeshPositionVertexBuffersResponse> getMeshPositionVertexBuffers() const = 0;

virtual void disableActor(const std::string& object_name) = 0;
};


Expand Down
5 changes: 5 additions & 0 deletions AirLib/src/api/RpcLibClientBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,11 @@ std::vector<std::string> RpcLibClientBase::simSwapTextures(const std::string& ta
return pimpl_->client.call("simSwapTextures", tags, tex_id, component_id, material_id).as<vector<string>>();
}

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<RpcLibAdapatorsBase::Pose>().to();
Expand Down
4 changes: 4 additions & 0 deletions AirLib/src/api/RpcLibServerBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
9 changes: 9 additions & 0 deletions PythonClient/airsim/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions Unity/AirLibWrapper/AirsimWrapper/Source/WorldSimApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions Unity/AirLibWrapper/AirsimWrapper/Source/WorldSimApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class WorldSimApi : public msr::airlib::WorldSimApiBase
virtual std::vector<std::string> 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;
Expand Down
18 changes: 18 additions & 0 deletions Unreal/Plugins/AirSim/Source/WorldSimApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,24 @@ std::unique_ptr<std::vector<std::string>> 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<AActor>(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()
{
Expand Down
2 changes: 2 additions & 0 deletions Unreal/Plugins/AirSim/Source/WorldSimApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vector3r>& points, const std::vector<float>& color_rgba, float size, float duration, bool is_persistent) override;
Expand Down