Skip to content

Commit

Permalink
Add getCameraInfo API for external cameras
Browse files Browse the repository at this point in the history
  • Loading branch information
rajat2004 committed Jan 19, 2021
1 parent 3c71e12 commit e6f6069
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 9 deletions.
2 changes: 1 addition & 1 deletion AirLib/include/api/RpcLibClientBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class RpcLibClientBase {

CollisionInfo simGetCollisionInfo(const std::string& vehicle_name = "") const;

CameraInfo simGetCameraInfo(const std::string& camera_name, const std::string& vehicle_name = "") const;
CameraInfo simGetCameraInfo(const std::string& camera_name, const std::string& vehicle_name = "", bool external = false) const;
void simSetDistortionParam(const std::string& camera_name, const std::string& param_name, float value, const std::string& vehicle_name = "");
std::vector<float> simGetDistortionParams(const std::string& camera_name, const std::string& vehicle_name = "");
void simSetCameraPose(const std::string& camera_name, const Pose& pose, const std::string& vehicle_name = "");
Expand Down
4 changes: 4 additions & 0 deletions AirLib/include/api/WorldSimApiBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ class WorldSimApiBase {
virtual bool isRecording() const = 0;

virtual void setWind(const Vector3r& wind) const = 0;

// Image APIs
virtual CameraInfo getCameraInfo(const std::string& camera_name, const std::string& vehicle_name="", bool external=false) const = 0;

};


Expand Down
4 changes: 2 additions & 2 deletions AirLib/src/api/RpcLibClientBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,9 @@ bool RpcLibClientBase::simSetObjectScale(const std::string& object_name, const m
return pimpl_->client.call("simSetObjectScale", object_name, RpcLibAdapatorsBase::Vector3r(scale)).as<bool>();
}

CameraInfo RpcLibClientBase::simGetCameraInfo(const std::string& camera_name, const std::string& vehicle_name) const
CameraInfo RpcLibClientBase::simGetCameraInfo(const std::string& camera_name, const std::string& vehicle_name, bool external) const
{
return pimpl_->client.call("simGetCameraInfo", camera_name, vehicle_name).as<RpcLibAdapatorsBase::CameraInfo>().to();
return pimpl_->client.call("simGetCameraInfo", camera_name, vehicle_name, external).as<RpcLibAdapatorsBase::CameraInfo>().to();
}

void RpcLibClientBase::simSetCameraPose(const std::string& camera_name, const Pose& pose, const std::string& vehicle_name)
Expand Down
5 changes: 3 additions & 2 deletions AirLib/src/api/RpcLibServerBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,9 @@ RpcLibServerBase::RpcLibServerBase(ApiProvider* api_provider, const std::string&
return RpcLibAdapatorsBase::DistanceSensorData(distance_sensor_data);
});

pimpl_->server.bind("simGetCameraInfo", [&](const std::string& camera_name, const std::string& vehicle_name) -> RpcLibAdapatorsBase::CameraInfo {
const auto& camera_info = getVehicleSimApi(vehicle_name)->getCameraInfo(camera_name);
pimpl_->server.bind("simGetCameraInfo", [&](const std::string& camera_name, const std::string& vehicle_name, bool external) -> RpcLibAdapatorsBase::CameraInfo {
// const auto& camera_info = getVehicleSimApi(vehicle_name)->getCameraInfo(camera_name);
const auto& camera_info = getWorldSimApi()->getCameraInfo(camera_name, vehicle_name, external);
return RpcLibAdapatorsBase::CameraInfo(camera_info);
});

Expand Down
4 changes: 2 additions & 2 deletions PythonClient/airsim/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ def simPrintLogMessage(self, message, message_param = "", severity = 0):
"""
self.client.call('simPrintLogMessage', message, message_param, severity)

def simGetCameraInfo(self, camera_name, vehicle_name = ''):
def simGetCameraInfo(self, camera_name, vehicle_name = '', external=False):
"""
Get details about the camera
Expand All @@ -480,7 +480,7 @@ def simGetCameraInfo(self, camera_name, vehicle_name = ''):
CameraInfo:
"""
# TODO: below str() conversion is only needed for legacy reason and should be removed in future
return CameraInfo.from_msgpack(self.client.call('simGetCameraInfo', str(camera_name), vehicle_name))
return CameraInfo.from_msgpack(self.client.call('simGetCameraInfo', str(camera_name), vehicle_name, external))

def simGetDistortionParams(self, camera_name, vehicle_name = ''):
"""
Expand Down
3 changes: 1 addition & 2 deletions Unreal/Plugins/AirSim/Source/PawnSimApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,7 @@ void PawnSimApi::plot(std::istream& s, FColor color, const Vector3r& offset)

msr::airlib::CameraInfo PawnSimApi::getCameraInfo(const std::string& camera_name) const
{
const APIPCamera* camera = getCamera(camera_name);
return camera->getCameraInfo();
return getCamera(camera_name)->getCameraInfo();
}

void PawnSimApi::setCameraPose(const std::string& camera_name, const msr::airlib::Pose& pose)
Expand Down
8 changes: 8 additions & 0 deletions Unreal/Plugins/AirSim/Source/SimMode/SimModeBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,14 @@ bool ASimModeBase::isRecording() const
return FRecordingThread::isRecording();
}

msr::airlib::CameraInfo ASimModeBase::getCameraInfo(const std::string& camera_name, const std::string& vehicle_name, bool external) const
{
if (external)
return getExternalCamera(camera_name)->getCameraInfo();
else
return getVehicleSimApi(vehicle_name)->getCameraInfo(camera_name);
}

//API server start/stop
void ASimModeBase::startApiServer()
{
Expand Down
13 changes: 13 additions & 0 deletions Unreal/Plugins/AirSim/Source/SimMode/SimModeBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class AIRSIM_API ASimModeBase : public AActor
virtual void stopRecording();
virtual bool isRecording() const;

virtual msr::airlib::CameraInfo getCameraInfo(const std::string& camera_name, const std::string& vehicle_name, bool external) const;

void startApiServer();
void stopApiServer();
bool isApiServerStarted();
Expand All @@ -89,6 +91,17 @@ class AIRSIM_API ASimModeBase : public AActor
return static_cast<PawnSimApi*>(api_provider_->getVehicleSimApi(vehicle_name));
}

const APIPCamera* getExternalCamera(const std::string& camera_name) const
{
return external_cameras_.findOrDefault(camera_name, nullptr);
}

APIPCamera* getExternalCamera(const std::string& camera_name)
{
return const_cast<APIPCamera*>(
static_cast<const ASimModeBase*>(this)->getExternalCamera(camera_name));
}

TMap<FString, FAssetData> asset_map;
TMap<FString, AActor*> scene_object_map;

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 @@ -558,3 +558,13 @@ void WorldSimApi::setWind(const Vector3r& wind) const
{
simmode_->setWind(wind);
}

CameraInfo WorldSimApi::getCameraInfo(const std::string& camera_name, const std::string& vehicle_name, bool external) const
{
CameraInfo info;
UAirBlueprintLib::RunCommandOnGameThread([this, &camera_name, &vehicle_name, external, &info]() {
info = simmode_->getCameraInfo(camera_name, vehicle_name, external);
}, true);

return info;
}
5 changes: 5 additions & 0 deletions Unreal/Plugins/AirSim/Source/WorldSimApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ class WorldSimApi : public msr::airlib::WorldSimApiBase {
virtual void setWind(const Vector3r& wind) const override;
virtual bool createVoxelGrid(const Vector3r& position, const int& x_size, const int& y_size, const int& z_size, const float& res, const std::string& output_file) override;

// Image APIs
virtual msr::airlib::CameraInfo getCameraInfo(const std::string& camera_name, const std::string& vehicle_name = "",
bool external = false) 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 e6f6069

Please sign in to comment.