Skip to content

Commit

Permalink
Add Recording APIs (microsoft#2834)
Browse files Browse the repository at this point in the history
* Add Recording APIs

startRecording(), stopRecording(), isRecording()

* [Unity] Add non-impl placeholder Recording API methods
  • Loading branch information
rajat2004 authored Jul 21, 2020
1 parent 680a62f commit f5691f9
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 1 deletion.
5 changes: 5 additions & 0 deletions AirLib/include/api/RpcLibClientBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ class RpcLibClientBase {

std::vector<std::string> simSwapTextures(const std::string& tags, int tex_id = 0, int component_id = 0, int material_id = 0);

// Recording APIs
void startRecording();
void stopRecording();
bool isRecording();

protected:
void* getClient();
const void* getClient() const;
Expand Down
5 changes: 5 additions & 0 deletions AirLib/include/api/WorldSimApiBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ 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;

// Recording APIs
virtual void startRecording() = 0;
virtual void stopRecording() = 0;
virtual bool isRecording() const = 0;
};


Expand Down
15 changes: 15 additions & 0 deletions AirLib/src/api/RpcLibClientBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,21 @@ RpcLibClientBase* RpcLibClientBase::waitOnLastTask(bool* task_result, float time
return this;
}

void RpcLibClientBase::startRecording()
{
pimpl_->client.call("startRecording");
}

void RpcLibClientBase::stopRecording()
{
pimpl_->client.call("stopRecording");
}

bool RpcLibClientBase::isRecording()
{
return pimpl_->client.call("isRecording").as<bool>();
}

void* RpcLibClientBase::getClient()
{
return &pimpl_->client;
Expand Down
12 changes: 12 additions & 0 deletions AirLib/src/api/RpcLibServerBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,18 @@ RpcLibServerBase::RpcLibServerBase(ApiProvider* api_provider, const std::string&
return *getWorldSimApi()->swapTextures(tag, tex_id, component_id, material_id);
});

pimpl_->server.bind("startRecording", [&]() -> void {
getWorldSimApi()->startRecording();
});

pimpl_->server.bind("stopRecording", [&]() -> void {
getWorldSimApi()->stopRecording();
});

pimpl_->server.bind("isRecording", [&]() -> bool {
return getWorldSimApi()->isRecording();
});

//if we don't suppress then server will bomb out for exceptions raised by any method
pimpl_->server.suppress_exceptions(true);
}
Expand Down
24 changes: 24 additions & 0 deletions PythonClient/airsim/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,30 @@ def waitOnLastTask(self, timeout_sec = float('nan')):
"""
return self.client.call('waitOnLastTask', timeout_sec)

# Recording APIs
def startRecording(self):
"""
Start Recording
Recording will be done according to the settings
"""
self.client.call('startRecording')

def stopRecording(self):
"""
Stop Recording
"""
self.client.call('stopRecording')

def isRecording(self):
"""
Whether Recording is running or not
Returns:
bool: True if Recording, else False
"""
return self.client.call('isRecording')

# ----------------------------------- Multirotor APIs ---------------------------------------------
class MultirotorClient(VehicleClient, object):
def __init__(self, ip = "", port = 41451, timeout_value = 3600):
Expand Down
20 changes: 20 additions & 0 deletions Unity/AirLibWrapper/AirsimWrapper/Source/WorldSimApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,24 @@ std::vector<WorldSimApi::MeshPositionVertexBuffersResponse> WorldSimApi::getMesh
return result;
}

// Recording APIs
void WorldSimApi::startRecording()
{
throw std::invalid_argument(common_utils::Utils::stringf(
"startRecording is not supported on unity").c_str());
}

void WorldSimApi::stopRecording()
{
throw std::invalid_argument(common_utils::Utils::stringf(
"stopRecording is not supported on unity").c_str());
}

bool WorldSimApi::isRecording() const
{
throw std::invalid_argument(common_utils::Utils::stringf(
"isRecording is not supported on unity").c_str());
return false;
}

#pragma endregion
5 changes: 5 additions & 0 deletions Unity/AirLibWrapper/AirsimWrapper/Source/WorldSimApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class WorldSimApi : public msr::airlib::WorldSimApiBase
virtual void simPlotTransformsWithNames(const std::vector<Pose>& poses, const std::vector<std::string>& names, float tf_scale, float tf_thickness, float text_scale, const std::vector<float>& text_color_rgba, float duration) override;
virtual std::vector<MeshPositionVertexBuffersResponse> getMeshPositionVertexBuffers() const override;

// Recording APIs
virtual void startRecording() override;
virtual void stopRecording() override;
virtual bool isRecording() const override;

private:
SimModeBase * simmode_;
std::string vehicle_name_;
Expand Down
18 changes: 17 additions & 1 deletion Unreal/Plugins/AirSim/Source/WorldSimApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,20 @@ std::vector<WorldSimApi::MeshPositionVertexBuffersResponse> WorldSimApi::getMesh
responses = UAirBlueprintLib::GetStaticMeshComponents();
}, true);
return responses;
}
}

// Recording APIs
void WorldSimApi::startRecording()
{
simmode_->startRecording();
}

void WorldSimApi::stopRecording()
{
simmode_->stopRecording();
}

bool WorldSimApi::isRecording() const
{
return simmode_->isRecording();
}
5 changes: 5 additions & 0 deletions Unreal/Plugins/AirSim/Source/WorldSimApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ class WorldSimApi : public msr::airlib::WorldSimApiBase {
virtual void simPlotTransformsWithNames(const std::vector<Pose>& poses, const std::vector<std::string>& names, float tf_scale, float tf_thickness, float text_scale, const std::vector<float>& text_color_rgba, float duration) override;
virtual std::vector<MeshPositionVertexBuffersResponse> getMeshPositionVertexBuffers() const override;

// Recording APIs
virtual void startRecording() override;
virtual void stopRecording() override;
virtual bool isRecording() const override;

private:
ASimModeBase* simmode_;
};
14 changes: 14 additions & 0 deletions docs/apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,20 @@ Please note that `Roadwetness`, `RoadSnow` and `RoadLeaf` effects requires addin

Please see [example code](https://github.com/Microsoft/AirSim/blob/master/PythonClient/computer_vision/weather.py) for more details.

### Recording APIs

Recording APIs can be used to start recording data through APIs. Data to be recorded can be specified using [settings](settings.md#recording). To start recording, use -

```
client.startRecording()
```

Similarly, to stop recording, use `client.stopRecording()`. To check whether Recording is running, call `client.isRecording()`, returns a `bool`.

This API works alongwith toggling Recording using R button, therefore if it's enabled using R key, `isRecording()` will return `True`, and recording can be stopped via API using `stopRecording()`. Similarly, recording started using API will be stopped if R key is pressed in Viewport. LogMessage will also appear in the top-left of the viewport if recording is started or stopped using API.

Note that this will only save the data as specfied in the settings. For full freedom in storing data such as certain sensor information, or in a different format or layout, use the other APIs to fetch the data and save as desired.

### Lidar APIs
AirSim offers API to retrieve point cloud data from Lidar sensors on vehicles. You can set the number of channels, points per second, horizontal and vertical FOV, etc parameters in [settings.json](settings.md).

Expand Down

0 comments on commit f5691f9

Please sign in to comment.