Skip to content

Commit

Permalink
Add placeholders for Unity compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
saihv committed Dec 9, 2020
1 parent e41becf commit e5967a0
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 35 deletions.
72 changes: 37 additions & 35 deletions Unity/AirLibWrapper/AirsimWrapper/Source/AirSimStructs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ namespace AirSimUnity
z = vec.z();
}

AirSimVector operator+(const AirSimVector& V) const
AirSimVector operator+(const AirSimVector &V) const
{
return AirSimVector(x + V.x, y + V.y, z + V.z);
}

AirSimVector operator-(const AirSimVector& V) const
AirSimVector operator-(const AirSimVector &V) const
{
return AirSimVector(x - V.x, y - V.y, z - V.z);
}
Expand Down Expand Up @@ -101,33 +101,34 @@ namespace AirSimUnity

struct AirSimRCData
{
#ifdef _WIN32
_int64 timestamp = 0;
#elif defined(__linux__) || defined(__APPLE__)
int64_t timestamp = 0;
#endif
#ifdef _WIN32
_int64 timestamp = 0;
#elif defined(__linux__) || defined(__APPLE__)
int64_t timestamp = 0;
#endif
float pitch = 0, roll = 0, throttle = 0, yaw = 0;
float left_z = 0, right_z = 0;
unsigned int switch1 = 0, switch2 = 0, switch3 = 0, switch4 = 0,
switch5 = 0, switch6 = 0, switch7 = 0, switch8 = 0;
unsigned int switch1 = 0, switch2 = 0, switch3 = 0, switch4 = 0,
switch5 = 0, switch6 = 0, switch7 = 0, switch8 = 0;
bool is_initialized = false; //is RC connected?
bool is_valid = false; //must be true for data to be valid
bool is_valid = false; //must be true for data to be valid
};

struct AirSimCollisionInfo
{
bool has_collided = false;;
bool has_collided = false;
;
AirSimVector normal;
AirSimVector impact_point;
AirSimVector position;
float penetration_depth = 0.0f;
#ifdef _WIN32
_int64 time_stamp = 0;
#elif defined(__linux__) || defined(__APPLE__)
int64_t time_stamp = 0;
#endif
#ifdef _WIN32
_int64 time_stamp = 0;
#elif defined(__linux__) || defined(__APPLE__)
int64_t time_stamp = 0;
#endif
int collision_count = 0;
char* object_name;
char *object_name;
int object_id = -1;
};

Expand All @@ -138,18 +139,20 @@ namespace AirSimUnity
AirSimAccelerations accelerations;
};

struct AirSimImageRequest {
char* camera_name;
struct AirSimImageRequest
{
char *camera_name;
msr::airlib::ImageCaptureBase::ImageType image_type = static_cast<msr::airlib::ImageCaptureBase::ImageType>(0);
bool pixels_as_float = false;
bool compress = false;
};

struct AirSimImageResponse {
struct AirSimImageResponse
{
int image_uint_len = 0;
unsigned char* image_data_uint;
unsigned char *image_data_uint;
int image_float_len = 0;
float* image_data_float;
float *image_data_float;
AirSimVector camera_position;
AirSimQuaternion camera_orientation;
bool pixels_as_float = false;
Expand All @@ -171,12 +174,12 @@ namespace AirSimUnity
{
int gear = 0;
float speed = 0.0f;
#ifdef _WIN32
__int64 time_stamp = 0;
#elif defined(__linux__) || defined(__APPLE__)
int64_t timestamp = 0;
#endif
#ifdef _WIN32
__int64 time_stamp = 0;
#elif defined(__linux__) || defined(__APPLE__)
int64_t timestamp = 0;
#endif

float engineMaxRotationSpeed = 0;
float engineRotationSpeed = 0;
AirSimPose pose;
Expand All @@ -199,24 +202,23 @@ namespace AirSimUnity
AirSimVector Scale3D;

public:

UnityTransform()
{
Rotation = AirSimQuaternion(0, 0, 0, 1);
Position = AirSimVector(0, 0, 0);
Scale3D = AirSimVector(1, 1, 1);
}

UnityTransform(const UnityTransform& obj) :
Rotation(obj.Rotation),
Position(obj.Position),
Scale3D(obj.Scale3D)
{}
UnityTransform(const UnityTransform &obj) : Rotation(obj.Rotation),
Position(obj.Position),
Scale3D(obj.Scale3D)
{
}
};

struct RayCastHitResult
{
bool isHit = false;
float distance = 0.0f;
};
}
} // namespace AirSimUnity
6 changes: 6 additions & 0 deletions Unity/AirLibWrapper/AirsimWrapper/Source/PInvokeWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ AirSimCarState(*GetCarState)(const char* vehicleName);
AirSimCameraInfo(*GetCameraInfo)(const char* cameraName, const char* vehicleName);
bool(*SetCameraPose)(const char* cameraName, AirSimPose pose, const char* vehicleName);
bool(*SetCameraFoV)(const char* cameraName, const float fov_degrees, const char* vehicleName);
bool(*SetCameraDistortionParam)(const char* cameraName, const char* paramName, const float value, const char* vehicleName);
bool(*GetCameraDistortionParam)(const char* cameraName, const char* vehicleName);
bool(*SetSegmentationObjectId)(const char* meshName, int objectId, bool isNameRegex);
int(*GetSegmentationObjectId)(const char* meshName);
bool(*PrintLogMessage) (const char* message, const char* messageParam, const char* vehicleName, int severity);
Expand All @@ -35,6 +37,8 @@ void InitVehicleManager(
AirSimCameraInfo(*getCameraInfo)(const char* cameraName, const char* vehicleName),
bool(*setCameraPose)(const char* cameraName, AirSimPose pose, const char* vehicleName),
bool(*setCameraFoV)(const char* cameraName, const float fov_degrees, const char* vehicleName),
bool(*setDistortionParam)(const char* cameraName, const char* paramName, const float value, const char* vehicleName),
bool(*getDistortionParams)(const char* cameraName, const char* vehicleName),
bool(*setSegmentationObjectId)(const char* meshName, int objectId, bool isNameRegex),
int(*getSegmentationObjectId)(const char* meshName),
bool(*printLogMessage) (const char* message, const char* messageParam, const char* vehicleName, int severity),
Expand All @@ -57,6 +61,8 @@ void InitVehicleManager(
GetCameraInfo = getCameraInfo;
SetCameraPose = setCameraPose;
SetCameraFoV = setCameraFoV;
SetCameraDistortionParam = setDistortionParam;
GetCameraDistortionParams = getDistortionParams;
SetSegmentationObjectId = setSegmentationObjectId;
GetSegmentationObjectId = getSegmentationObjectId;
PrintLogMessage = printLogMessage;
Expand Down
4 changes: 4 additions & 0 deletions Unity/AirLibWrapper/AirsimWrapper/Source/PInvokeWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ extern AirSimCarState(*GetCarState)(const char* vehicleName);
extern AirSimCameraInfo(*GetCameraInfo)(const char* cameraName, const char* vehicleName);
extern bool(*SetCameraPose)(const char* cameraName, AirSimPose pose, const char* vehicleName);
extern bool(*SetCameraFoV)(const char* cameraName, const float fov_degrees, const char* vehicleName);
extern bool(*SetCameraDistortionParam)(const char* cameraName, const char* paramName, const float value, const char* vehicleName);
extern bool(*GetCameraDistortionParam)(const char* cameraName, const char* vehicleName);
extern bool(*SetSegmentationObjectId)(const char* meshName, int objectId, bool isNameRegex);
extern int(*GetSegmentationObjectId)(const char* meshName);
extern bool(*PrintLogMessage) (const char* message, const char* messageParam, const char* vehicleName, int severity);
Expand All @@ -51,6 +53,8 @@ extern "C" EXPORT void InitVehicleManager(
AirSimCameraInfo(*getCameraInfo)(const char* cameraName, const char* vehicleName),
bool(*setCameraPose)(const char* cameraName, AirSimPose pose, const char* vehicleName),
bool(*setCameraFoV)(const char* cameraName, const float fov_degrees, const char* vehicleName),
bool(*setDistortionParam)(const char* cameraName, const char* paramName, const float value, const char* vehicleName),
bool(*getDistortionParams)(const char* cameraName, const char* vehicleName),
bool(*setSegmentationObjectId)(const char* meshName, int objectId, bool isNameRegex),
int(*getSegmentationObjectId)(const char* meshName),
bool(*printLogMessage) (const char* message, const char* messageParam, const char* vehicleName, int severity),
Expand Down
11 changes: 11 additions & 0 deletions Unity/AirLibWrapper/AirsimWrapper/Source/PawnSimApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,17 @@ void PawnSimApi::setCameraFoV(const std::string& camera_name, float fov_degrees)
SetCameraFoV(camera_name.c_str(), fov_degrees, params_.vehicle_name.c_str());
}

void PawnSimApi::setDistortionParam(const std::string& camera_name, const std::string& param_name, float value)
{
// not implemented
}

std::vector<float> PawnSimApi::getDistortionParams(const std::string& camera_name)
{
// not implemented
}


//parameters in NED frame
PawnSimApi::Pose PawnSimApi::getPose() const
{
Expand Down
2 changes: 2 additions & 0 deletions Unity/AirLibWrapper/AirsimWrapper/Source/PawnSimApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class PawnSimApi : public msr::airlib::VehicleSimApiBase
virtual msr::airlib::CameraInfo getCameraInfo(const std::string& camera_name) const override;
virtual void setCameraPose(const std::string& camera_name, const Pose& pose) override;
virtual void setCameraFoV(const std::string& camera_name, float fov_degrees) override;
virtual void setDistortionParam(const std::string& camera_name, const std::string& param_name, float value) override;
virtual void getDistortionParams(const std::string& camera_name) override;
virtual CollisionInfo getCollisionInfo() const override;
virtual int getRemoteControlID() const override;
virtual msr::airlib::RCData getRCData() const override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ private static bool SetCameraFoV(string cameraName, float fov_degrees, string ve
return vehicle.VehicleInterface.SetCameraFoV(cameraName, fov_degrees);
}

private static bool SetDistortionParam(string cameraName, string paramName, float value, string vehicleName) {
var vehicle = Vehicles.Find(element => element.vehicleName == vehicleName);
return vehicle.VehicleInterface.SetDistortionParam(cameraName, fov_degrees);
}

private static bool PrintLogMessage(string message, string messageParams, string vehicleName, int severity) {
var vehicle = Vehicles.Find(element => element.vehicleName == vehicleName);
return vehicle.VehicleInterface.PrintLogMessage(message, messageParams, vehicleName, severity);
Expand Down

0 comments on commit e5967a0

Please sign in to comment.