Skip to content

Commit

Permalink
API refactor, simSetPose, simGetPose, reset for drones
Browse files Browse the repository at this point in the history
  • Loading branch information
sytelus committed Oct 15, 2017
1 parent cc75906 commit 213ffe3
Show file tree
Hide file tree
Showing 35 changed files with 577 additions and 465 deletions.
9 changes: 7 additions & 2 deletions AirLib/AirLib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
<ClInclude Include="include\api\DebugApiServer.hpp" />
<ClInclude Include="include\api\RpcLibAdapatorsBase.hpp" />
<ClInclude Include="include\api\RpcLibClientBase.hpp" />
<ClInclude Include="include\api\RpcLibServerBase.hpp" />
<ClInclude Include="include\api\VehicleApiBase.hpp" />
<ClInclude Include="include\common\ClockBase.hpp" />
<ClInclude Include="include\common\Common.hpp" />
<ClInclude Include="include\common\CommonStructs.hpp" />
Expand Down Expand Up @@ -64,10 +66,12 @@
<ClInclude Include="include\common\VectorMath.hpp" />
<ClInclude Include="include\common\common_utils\AsyncTasker.hpp" />
<ClInclude Include="include\controllers\VehicleCameraBase.hpp" />
<ClInclude Include="include\controllers\VehicleConnectorBase.hpp" />
<ClInclude Include="include\vehicles\car\api\CarApiBase.hpp" />
<ClInclude Include="include\vehicles\multirotor\api\MultirotorRpcLibAdapators.hpp" />
<ClInclude Include="include\vehicles\multirotor\api\MultirotorRpcLibClient.hpp" />
<ClInclude Include="include\vehicles\multirotor\api\MultirotorRpcLibServer.hpp" />
<ClInclude Include="include\vehicles\multirotor\controllers\RealMultirotorConnector.hpp" />
<ClInclude Include="include\vehicles\multirotor\firmwares\ros_flight\AirSimRosFlightBoard.hpp" />
<ClInclude Include="include\vehicles\multirotor\firmwares\ros_flight\AirSimRosFlightCommLink.hpp" />
<ClInclude Include="include\vehicles\multirotor\firmwares\ros_flight\firmware\board.hpp" />
Expand Down Expand Up @@ -134,7 +138,7 @@
<ClInclude Include="include\vehicles\car\api\CarRpcLibClient.hpp" />
<ClInclude Include="include\vehicles\car\api\CarRpcLibServer.hpp" />
<ClInclude Include="include\safety\SafetyEval.hpp" />
<ClInclude Include="include\vehicles\multirotor\controllers\DroneControllerCancelable.hpp" />
<ClInclude Include="include\vehicles\multirotor\api\DroneApi.hpp" />
<ClInclude Include="include\controllers\Settings.hpp" />
<ClInclude Include="include\safety\SphereGeoFence.hpp" />
<ClInclude Include="include\controllers\VehicleControllerBase.hpp" />
Expand Down Expand Up @@ -172,7 +176,8 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\api\RpcLibClientBase.cpp" />
<ClCompile Include="src\controllers\DroneControllerBase.cpp" />
<ClCompile Include="src\api\RpcLibServerBase.cpp" />
<ClCompile Include="src\vehicles\multirotor\controllers\DroneControllerBase.cpp" />
<ClCompile Include="src\safety\ObstacleMap.cpp" />
<ClCompile Include="src\safety\SafetyEval.cpp" />
<ClCompile Include="src\common\common_utils\FileSystem.cpp" />
Expand Down
25 changes: 20 additions & 5 deletions AirLib/AirLib.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,6 @@
<ClInclude Include="include\vehicles\multirotor\controllers\DroneControllerBase.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\vehicles\multirotor\controllers\DroneControllerCancelable.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\vehicles\multirotor\controllers\MavLinkDroneController.hpp">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down Expand Up @@ -456,6 +453,21 @@
<ClInclude Include="include\api\RpcLibClientBase.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\vehicles\multirotor\api\DroneApi.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\api\VehicleApiBase.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\api\RpcLibServerBase.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\controllers\VehicleConnectorBase.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\vehicles\multirotor\controllers\RealMultirotorConnector.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\safety\ObstacleMap.cpp">
Expand All @@ -479,10 +491,13 @@
<ClCompile Include="src\vehicles\multirotor\api\MultirotorRpcLibClient.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\controllers\DroneControllerBase.cpp">
<ClCompile Include="src\api\RpcLibClientBase.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\api\RpcLibClientBase.cpp">
<ClCompile Include="src\api\RpcLibServerBase.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\vehicles\multirotor\controllers\DroneControllerBase.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions AirLib/include/api/RpcLibClientBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class RpcLibClientBase {
void confirmConnection();
bool isApiControlEnabled();
void enableApiControl(bool is_enabled);
void reset();

virtual ~RpcLibClientBase(); //required for pimpl

Expand Down
34 changes: 34 additions & 0 deletions AirLib/include/api/RpcLibServerBase.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#ifndef air_RpcLibServerBase_hpp
#define air_RpcLibServerBase_hpp

#include "common/Common.hpp"
#include "api/ControlServerBase.hpp"
#include "api/VehicleApiBase.hpp"


namespace msr { namespace airlib {


class RpcLibServerBase : public ControlServerBase {
public:
RpcLibServerBase(VehicleApiBase* vehicle, string server_address, uint16_t port);
virtual void start(bool block = false) override;
virtual void stop() override;
virtual ~RpcLibServerBase() override;

protected:
void* getServer();
VehicleApiBase* getVehicleApi();

private:
VehicleApiBase* vehicle_;
struct impl;
std::unique_ptr<impl> pimpl_;
};


}} //namespace
#endif
31 changes: 31 additions & 0 deletions AirLib/include/api/VehicleApiBase.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#ifndef air_VehicleApiBase_hpp
#define air_VehicleApiBase_hpp

#include "common/CommonStructs.hpp"
#include "controllers/VehicleCameraBase.hpp"

namespace msr { namespace airlib {


class VehicleApiBase {
public:
virtual GeoPoint getHomeGeoPoint() = 0;
virtual void enableApiControl(bool is_enabled) = 0;
virtual bool isApiControlEnabled() = 0;
virtual void reset() = 0;

virtual vector<VehicleCameraBase::ImageResponse> simGetImages(const vector<VehicleCameraBase::ImageRequest>& request) = 0;
virtual vector<uint8_t> simGetImage(uint8_t camera_id, VehicleCameraBase::ImageType image_type) = 0;

virtual void simSetPose(const Pose& pose, bool ignore_collison) = 0;
virtual Pose simGetPose() = 0;

virtual ~VehicleApiBase() = default;
};


}} //namespace
#endif
89 changes: 45 additions & 44 deletions AirLib/include/controllers/VehicleCameraBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,57 @@
#include "common/common_utils/EnumFlags.hpp"

namespace msr { namespace airlib {
// This is an abstraction for cameras associated with a vehicle. Each camera has a unique id.
class VehicleCameraBase
{
public: //types
enum class ImageType : uint { //this indexes to array
Scene = 0,
DepthPlanner,
DepthPerspective,
DepthVis,
DisparityNormalized,
Segmentation,
SurfaceNormals,
Count //must be last
};

struct ImageRequest {
uint8_t camera_id;
VehicleCameraBase::ImageType image_type;
bool pixels_as_float;
bool compress;
// This is an abstraction for cameras associated with a vehicle. Each camera has a unique id.
class VehicleCameraBase
{
public: //types
enum class ImageType : uint { //this indexes to array
Scene = 0,
DepthPlanner,
DepthPerspective,
DepthVis,
DisparityNormalized,
Segmentation,
SurfaceNormals,
Count //must be last
};

struct ImageRequest {
uint8_t camera_id;
VehicleCameraBase::ImageType image_type;
bool pixels_as_float;
bool compress;

ImageRequest()
{}
ImageRequest()
{}

ImageRequest(uint8_t camera_id_val, VehicleCameraBase::ImageType image_type_val, bool pixels_as_float_val = false, bool compress_val = true)
{
camera_id = camera_id_val;
image_type = image_type_val;
pixels_as_float = pixels_as_float_val;
compress = compress_val;
}
};
ImageRequest(uint8_t camera_id_val, VehicleCameraBase::ImageType image_type_val, bool pixels_as_float_val = false, bool compress_val = true)
{
camera_id = camera_id_val;
image_type = image_type_val;
pixels_as_float = pixels_as_float_val;
compress = compress_val;
}
};

struct ImageResponse {
vector<uint8_t> image_data_uint8;
vector<float> image_data_float;
struct ImageResponse {
vector<uint8_t> image_data_uint8;
vector<float> image_data_float;

Vector3r camera_position = Vector3r::Zero();
Quaternionr camera_orientation = Quaternionr::Identity();
TTimePoint time_stamp = 0;
std::string message;
bool pixels_as_float = false;
bool compress = true;
int width = 0, height = 0;
ImageType image_type;
};
Vector3r camera_position = Vector3r::Zero();
Quaternionr camera_orientation = Quaternionr::Identity();
TTimePoint time_stamp = 0;
std::string message;
bool pixels_as_float = false;
bool compress = true;
int width = 0, height = 0;
ImageType image_type;
};

public: //methods
virtual ImageResponse getImage(ImageType image_type, bool pixels_as_float, bool compress) = 0;
};
public: //methods
virtual ImageResponse getImage(ImageType image_type, bool pixels_as_float, bool compress) = 0;
};


}} //namespace
Expand Down
35 changes: 35 additions & 0 deletions AirLib/include/controllers/VehicleConnectorBase.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#ifndef air_VehicleConnectorBase_hpp
#define air_VehicleConnectorBase_hpp

#include "VehicleControllerBase.hpp"
#include "VehicleCameraBase.hpp"
#include "common/UpdatableObject.hpp"

namespace msr { namespace airlib {

class VehicleConnectorBase : public UpdatableObject
{
public:
//pure abstract methods in addition to UpdatableObject

//called when physics gets updated (must be fast, avoid rendering)
virtual void updateRenderedState() = 0;
//called when render changes are required
virtual void updateRendering(float dt) = 0;

//opens up channel to talk to vehicle via APIs
virtual void startApiServer() = 0;
virtual void stopApiServer() = 0;
virtual bool isApiServerStarted() = 0;
virtual VehicleControllerBase* getController() = 0;
virtual VehicleCameraBase* getCamera(unsigned int index) = 0;
virtual void setPose(const Pose& pose, bool ignore_collison) = 0;
virtual Pose getPose() = 0;
};


}} //namespace
#endif
11 changes: 2 additions & 9 deletions AirLib/include/vehicles/car/api/CarApiBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
#include "controllers/VehicleCameraBase.hpp"
#include "common/VectorMath.hpp"
#include "common/CommonStructs.hpp"
#include "api/VehicleApiBase.hpp"

namespace msr { namespace airlib {

class CarApiBase {
class CarApiBase : public VehicleApiBase {
public:
struct CarControls {
float throttle = 0; /* 1 to -1 */
Expand Down Expand Up @@ -62,16 +63,8 @@ class CarApiBase {
}
};

virtual vector<VehicleCameraBase::ImageResponse> simGetImages(const vector<VehicleCameraBase::ImageRequest>& request) = 0;
virtual vector<uint8_t> simGetImage(uint8_t camera_id, VehicleCameraBase::ImageType image_type) = 0;
virtual void setCarControls(const CarControls& controls) = 0;
virtual CarState getCarState() = 0;
virtual GeoPoint getHomeGeoPoint() = 0;
virtual void enableApiControl(bool is_enabled) = 0;
virtual bool isApiControlEnabled() = 0;
virtual void reset() = 0;
virtual void simSetPose(const Pose& pose, bool ignore_collison) = 0;
virtual Pose simGetPose() = 0;
virtual ~CarApiBase() = default;
};

Expand Down
12 changes: 4 additions & 8 deletions AirLib/include/vehicles/car/api/CarRpcLibServer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,18 @@

#include "common/Common.hpp"
#include <functional>
#include "api/ControlServerBase.hpp"
#include "api/RpcLibServerBase.hpp"
#include "vehicles/car/api/CarApiBase.hpp"

namespace msr { namespace airlib {

class CarRpcLibServer : public ControlServerBase {
class CarRpcLibServer : public RpcLibServerBase {
public:
CarRpcLibServer(CarApiBase* vehicle, string server_address, uint16_t port = 42451);
virtual void start(bool block = false) override;
virtual void stop() override;
virtual ~CarRpcLibServer() override;
virtual ~CarRpcLibServer();

private:
CarApiBase* vehicle_;
struct impl;
std::unique_ptr<impl> pimpl_;
CarApiBase* getCarApi();
};

}} //namespace
Expand Down
Loading

0 comments on commit 213ffe3

Please sign in to comment.