Skip to content

Commit

Permalink
Plugin refactoring to sync with AirLib
Browse files Browse the repository at this point in the history
  • Loading branch information
sytelus committed Jun 1, 2018
1 parent ca7bf72 commit 6bc81a2
Show file tree
Hide file tree
Showing 54 changed files with 623 additions and 876 deletions.
2 changes: 1 addition & 1 deletion AirLib/AirLib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\api\ApiProvider.hpp" />
<ClInclude Include="include\api\ApiServerBase.hpp" />
<ClInclude Include="include\api\DebugApiServer.hpp" />
<ClInclude Include="include\api\RpcLibAdapatorsBase.hpp" />
<ClInclude Include="include\api\RpcLibClientBase.hpp" />
<ClInclude Include="include\api\RpcLibServerBase.hpp" />
Expand Down
6 changes: 3 additions & 3 deletions AirLib/AirLib.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,6 @@
<ClInclude Include="include\physics\DebugPhysicsBody.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\api\DebugApiServer.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\physics\PhysicsBodyWorld.hpp">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down Expand Up @@ -429,6 +426,9 @@
<ClInclude Include="include\vehicles\multirotor\api\MultirotorApiBase.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\api\ApiProvider.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\safety\ObstacleMap.cpp">
Expand Down
61 changes: 61 additions & 0 deletions AirLib/include/api/ApiProvider.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#ifndef air_ApiProvider_hpp
#define air_ApiProvider_hpp

#include "VehicleApiBase.hpp"
#include "VehicleSimApiBase.hpp"
#include "WorldSimApiBase.hpp"
#include <map>


namespace msr { namespace airlib {

class ApiProvider {
public:
ApiProvider(WorldSimApiBase * world_sim_api)
: world_sim_api_(world_sim_api)
{
}

//vehicle API
virtual VehicleApiBase* getVehicleApi(const std::string& vehicle_name = "")
{
return Utils::findOrDefault(vehicle_apis_, vehicle_name,
static_cast<VehicleApiBase*>(nullptr));
}

//world simulation API
virtual WorldSimApiBase* getWorldSimApi()
{
return world_sim_api_;
}

//vehicle simulation API
virtual VehicleSimApiBase* getVehicleSimApi(const std::string& vehicle_name = "")
{
return Utils::findOrDefault(vehicle_sim_apis_, vehicle_name,
static_cast<VehicleSimApiBase*>(nullptr));
}

size_t getVehicleCount() const
{
return vehicle_apis_.size();
}
void insert_or_assign(const std::string& vehicle_name, VehicleApiBase* vehicle_api, VehicleSimApiBase* vehicle_sim_api)
{
vehicle_apis_[vehicle_name] = vehicle_api;
vehicle_sim_apis_[vehicle_name] = vehicle_sim_api;
}


private:
WorldSimApiBase* world_sim_api_;
std::map<std::string, VehicleApiBase*> vehicle_apis_;
std::map<std::string, VehicleSimApiBase*> vehicle_sim_apis_;

};

}} //namespace
#endif
29 changes: 0 additions & 29 deletions AirLib/include/api/ApiServerBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

#include <functional>
#include "common/Common.hpp"
#include "VehicleApiBase.hpp"
#include "WorldSimApiBase.hpp"

namespace msr { namespace airlib {

Expand All @@ -16,33 +14,6 @@ class ApiServerBase {
virtual void start(bool block = false) = 0;
virtual void stop() = 0;

virtual const VehicleApiBase* getVehicleApi(const std::string& vehicle_name = "") const = 0;
virtual VehicleApiBase* getVehicleApi(const std::string& vehicle_name = "")
{
return const_cast<VehicleApiBase*>(getVehicleApi(vehicle_name));
}

virtual const WorldSimApiBase* getWorldSimApi() const = 0;
virtual WorldSimApiBase* getWorldSimApi()
{
return const_cast<WorldSimApiBase*>(getWorldSimApi());
}

virtual const VehicleSimApiBase* getVehicleSimApi(const std::string& vehicle_name = "") const
{
auto* world_sim_api = getWorldSimApi();
if (world_sim_api) {
auto* vehicle_sim_api = getWorldSimApi()->getVehicleSimApi(vehicle_name);
return vehicle_sim_api;
}
return nullptr;
}
virtual VehicleSimApiBase* getVehicleSimApi(const std::string& vehicle_name = "")
{
return const_cast<VehicleSimApiBase*>(getVehicleSimApi(vehicle_name));

}

virtual ~ApiServerBase() = default;
};

Expand Down
40 changes: 0 additions & 40 deletions AirLib/include/api/DebugApiServer.hpp

This file was deleted.

21 changes: 19 additions & 2 deletions AirLib/include/api/RpcLibServerBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

#include "common/Common.hpp"
#include "api/ApiServerBase.hpp"
#include "api/WorldSimApiBase.hpp"
#include "api/ApiProvider.hpp"


namespace msr { namespace airlib {


class RpcLibServerBase : public ApiServerBase {
public:
RpcLibServerBase(const std::string& server_address, uint16_t port);
RpcLibServerBase(ApiProvider* api_provider, const std::string& server_address, uint16_t port);
virtual ~RpcLibServerBase() override;

virtual void start(bool block = false) override;
Expand All @@ -23,7 +23,24 @@ class RpcLibServerBase : public ApiServerBase {
protected:
void* getServer() const;


virtual VehicleApiBase* getVehicleApi(const std::string& vehicle_name = "")
{
return api_provider_->getVehicleApi(vehicle_name);
}
virtual VehicleSimApiBase* getVehicleSimApi(const std::string& vehicle_name = "")
{
return api_provider_->getVehicleSimApi(vehicle_name);
}
virtual WorldSimApiBase* getWorldSimApi()
{
return api_provider_->getWorldSimApi();
}


private:
ApiProvider* api_provider_;

struct impl;
std::unique_ptr<impl> pimpl_;
};
Expand Down
49 changes: 0 additions & 49 deletions AirLib/include/api/VehicleConnectorBase.hpp

This file was deleted.

38 changes: 29 additions & 9 deletions AirLib/include/api/VehicleSimApiBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,49 @@
#define air_VehicleSimApiBase_hpp

#include "common/CommonStructs.hpp"
#include "common/UpdatableObject.hpp"
#include "common/ImageCaptureBase.hpp"
#include "physics/Kinematics.hpp"

namespace msr { namespace airlib {

class VehicleSimApiBase {
class VehicleSimApiBase : public msr::airlib::UpdatableObject {
public:
virtual ~VehicleSimApiBase() = default;

virtual void reset() = 0;
//this method is called at every render tick when we want to transfer state from
//physics engine to render engine. As physics engine is halted while
//this happens, this method should do minimal processing
virtual void updateRenderedState(float dt)
{
//derived class should override if needed
}
//called when render changes are required at every render tick
virtual void updateRendering(float dt)
{
//derived class should override if needed
}

virtual const ImageCaptureBase* getImageCapture() const = 0;
virtual ImageCaptureBase* getImageCapture()
{
return const_cast<ImageCaptureBase*>(getImageCapture());
}

virtual std::vector<ImageCaptureBase::ImageResponse> getImages(const std::vector<ImageCaptureBase::ImageRequest>& request) const = 0;
virtual std::vector<uint8_t> getImage(uint8_t camera_id, ImageCaptureBase::ImageType image_type) const = 0;

virtual vector<ImageCaptureBase::ImageResponse> getImages(const vector<ImageCaptureBase::ImageRequest>& request) const = 0;
virtual vector<uint8_t> getImage(uint8_t camera_id, ImageCaptureBase::ImageType image_type) const = 0;

virtual void setPose(const Pose& pose, bool ignore_collision) = 0;
virtual Pose getPose() const = 0;
virtual void setPose(const Pose& pose, bool ignore_collision) = 0;
virtual const Kinematics::State* getGroundTruthKinematics() const = 0;

virtual CameraInfo getCameraInfo(int camera_id) const = 0;
virtual void setCameraOrientation(int camera_id, const Quaternionr& orientation) = 0;

virtual CollisionInfo getCollisionInfo() const = 0;
virtual Kinematics::State getGroundTruthKinematics() const = 0;
virtual int getRemoteControlID() const { return -1; }
virtual RCData getRCData() const = 0; //get reading from RC from simulator

virtual CameraInfo getCameraInfo(int camera_id) const = 0;
virtual void setCameraOrientation(int camera_id, const Quaternionr& orientation) = 0;
};

} } //namespace
Expand Down
11 changes: 3 additions & 8 deletions AirLib/include/api/WorldSimApiBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#define air_WorldSimApiBase_hpp

#include "common/CommonStructs.hpp"
#include "VehicleSimApiBase.hpp"


namespace msr { namespace airlib {

Expand All @@ -19,18 +19,13 @@ class WorldSimApiBase {
virtual void pause(bool is_paused) = 0;
virtual void continueForTime(double seconds) = 0;

virtual const VehicleSimApiBase* getVehicleSimApi(const std::string& vehicle_name = "") const = 0;
virtual VehicleSimApiBase* getVehicleSimApi(const std::string& vehicle_name = "")
{
return const_cast<VehicleSimApiBase*>(getVehicleSimApi(vehicle_name));
}

virtual bool setSegmentationObjectID(const std::string& mesh_name, int object_id, bool is_name_regex = false) = 0;
virtual int getSegmentationObjectID(const std::string& mesh_name) const = 0;

virtual void printLogMessage(const std::string& message,
const std::string& message_param = "", unsigned char severity = 0) = 0;
virtual Pose getObjectPose(const std::string& object_name) const = 0;

virtual Pose getObjectPose(const std::string& object_name) const = 0;
};


Expand Down
2 changes: 1 addition & 1 deletion AirLib/include/common/ImageCaptureBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ImageCaptureBase
};

public: //methods
virtual void getImages(const std::vector<ImageRequest>& requests, std::vector<ImageResponse>& responses) = 0;
virtual void getImages(const std::vector<ImageRequest>& requests, std::vector<ImageResponse>& responses) const = 0;
};


Expand Down
9 changes: 9 additions & 0 deletions AirLib/include/common/common_utils/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ class Utils {
return s.size() <= prefix.size() && s.compare(0, prefix.size(), prefix) == 0;
}

template <template<class, class, class...> class TContainer, typename TKey, typename TVal, typename... Args>
static TVal findOrDefault(const TContainer<TKey, TVal, Args...>& m, TKey const& key, const TVal & default_val)
{
typename TContainer<TKey, TVal, Args...>::const_iterator it = m.find(key);
if (it == m.end())
return default_val;
return it->second;
}

static Logger* getSetLogger(Logger* logger = nullptr)
{
static Logger logger_default_;
Expand Down
2 changes: 1 addition & 1 deletion AirLib/include/physics/PhysicsWorld.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class PhysicsWorld {
}
}

std::string getReport()
std::string getDebugReport()
{
return reporter_.getOutput();
}
Expand Down
Loading

0 comments on commit 6bc81a2

Please sign in to comment.