Skip to content

Commit

Permalink
Add API for list of vehicle names
Browse files Browse the repository at this point in the history
  • Loading branch information
rajat2004 committed Aug 15, 2020
1 parent bd8ee6b commit 3a90233
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions AirLib/include/api/RpcLibClientBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ class RpcLibClientBase {
void stopRecording();
bool isRecording();

vector<string> listVehicles();

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 @@ -70,6 +70,8 @@ class WorldSimApiBase {
virtual void startRecording() = 0;
virtual void stopRecording() = 0;
virtual bool isRecording() const = 0;

virtual vector<string> listVehicles() const = 0;
};


Expand Down
9 changes: 9 additions & 0 deletions AirLib/include/common/common_utils/UniqueValueMap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ class UniqueValueMap {
return vals_.size();
}

std::vector<TKey> keys() const
{
std::vector<TKey> ret;
for (const auto& element: map_) {
ret.push_back(element.first);
}
return ret;
}

//TODO: add erase methods

private:
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 @@ -432,6 +432,11 @@ bool RpcLibClientBase::isRecording()
return pimpl_->client.call("isRecording").as<bool>();
}

vector<string> RpcLibClientBase::listVehicles()
{
return pimpl_->client.call("listVehicles").as<vector<string>>();
}

void* RpcLibClientBase::getClient()
{
return &pimpl_->client;
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 @@ -366,6 +366,10 @@ RpcLibServerBase::RpcLibServerBase(ApiProvider* api_provider, const std::string&
return getWorldSimApi()->isRecording();
});

pimpl_->server.bind("listVehicles", [&]() -> vector<string> {
return getWorldSimApi()->listVehicles();
});

//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 @@ -750,6 +750,15 @@ def isRecording(self):
"""
return self.client.call('isRecording')

def listVehicles(self):
"""
Lists the names of current vehicles
Returns:
list[str]: List containing names of all vehicles
"""
return self.client.call('listVehicles')

# ----------------------------------- Multirotor APIs ---------------------------------------------
class MultirotorClient(VehicleClient, object):
def __init__(self, ip = "", port = 41451, timeout_value = 3600):
Expand Down
10 changes: 10 additions & 0 deletions Unreal/Plugins/AirSim/Source/WorldSimApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,3 +410,13 @@ bool WorldSimApi::isRecording() const
{
return simmode_->isRecording();
}

std::vector<std::string> WorldSimApi::listVehicles() const
{
auto vehicle_names = (simmode_->getApiProvider()->getVehicleSimApis()).keys();
// Remove '' from the list, representing default vehicle
auto position = std::find(vehicle_names.begin(), vehicle_names.end(), "");
if (position != vehicle_names.end())
vehicle_names.erase(position);
return vehicle_names;
}
2 changes: 2 additions & 0 deletions Unreal/Plugins/AirSim/Source/WorldSimApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class WorldSimApi : public msr::airlib::WorldSimApiBase {
virtual void stopRecording() override;
virtual bool isRecording() const override;

virtual std::vector<std::string> listVehicles() const override;

private:
AActor* createNewActor(const FActorSpawnParameters& spawn_params, const FTransform& actor_transform, const Vector3r& scale, UStaticMesh* static_mesh);
void spawnPlayer();
Expand Down

0 comments on commit 3a90233

Please sign in to comment.