From 208c3cbfded0e0761ff37d1490e9a50f89e72f77 Mon Sep 17 00:00:00 2001 From: Rajat Singhal Date: Thu, 4 Feb 2021 19:58:45 +0530 Subject: [PATCH] Use Pose instead of NED values, fix missing override --- AirLib/include/api/RpcLibClientBase.hpp | 2 +- AirLib/include/api/WorldSimApiBase.hpp | 2 +- AirLib/src/api/RpcLibClientBase.cpp | 4 ++-- AirLib/src/api/RpcLibServerBase.cpp | 21 +++----------------- PythonClient/airsim/client.py | 10 ++++------ Unreal/Plugins/AirSim/Source/WorldSimApi.cpp | 11 +++++++++- Unreal/Plugins/AirSim/Source/WorldSimApi.h | 2 +- 7 files changed, 22 insertions(+), 30 deletions(-) diff --git a/AirLib/include/api/RpcLibClientBase.hpp b/AirLib/include/api/RpcLibClientBase.hpp index ef9cdc8415..56e9ce567a 100644 --- a/AirLib/include/api/RpcLibClientBase.hpp +++ b/AirLib/include/api/RpcLibClientBase.hpp @@ -97,7 +97,7 @@ class RpcLibClientBase { vector simGetImage(const std::string& camera_name, ImageCaptureBase::ImageType type, const std::string& vehicle_name = ""); vector simGetMeshPositionVertexBuffers(); - bool simAddVehicle(const std::string& vehicle_name, const std::string& vehicle_type, const std::string& pawn_path, float north, float east, float down); + bool simAddVehicle(const std::string& vehicle_name, const std::string& vehicle_type, const Pose& pose, const std::string& pawn_path = ""); CollisionInfo simGetCollisionInfo(const std::string& vehicle_name = "") const; diff --git a/AirLib/include/api/WorldSimApiBase.hpp b/AirLib/include/api/WorldSimApiBase.hpp index 5cd4c5257c..541aa36ca3 100644 --- a/AirLib/include/api/WorldSimApiBase.hpp +++ b/AirLib/include/api/WorldSimApiBase.hpp @@ -47,7 +47,7 @@ class WorldSimApiBase { 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 bool createVehicleAtRuntime(AirSimSettings::VehicleSetting& vehicle_setting) = 0; + virtual bool createVehicleAtRuntime(const std::string& vehicle_name, const std::string& vehicle_type, const Pose& pose, const std::string& pawn_path = "") = 0; virtual void printLogMessage(const std::string& message, const std::string& message_param = "", unsigned char severity = 0) = 0; diff --git a/AirLib/src/api/RpcLibClientBase.cpp b/AirLib/src/api/RpcLibClientBase.cpp index 448635573b..50beb9987e 100644 --- a/AirLib/src/api/RpcLibClientBase.cpp +++ b/AirLib/src/api/RpcLibClientBase.cpp @@ -243,9 +243,9 @@ vector RpcLibClientBase::simGetMeshPositionVe return RpcLibAdapatorsBase::MeshPositionVertexBuffersResponse::to(response_adaptor); } -bool RpcLibClientBase::simAddVehicle(const std::string& vehicle_name, const std::string& vehicle_type, const std::string& pawn_path, float north, float east, float down) +bool RpcLibClientBase::simAddVehicle(const std::string& vehicle_name, const std::string& vehicle_type, const Pose& pose, const std::string& pawn_path) { - return pimpl_->client.call("simAddVehicle", vehicle_name, vehicle_type, pawn_path, north, east, down).as(); + return pimpl_->client.call("simAddVehicle", vehicle_name, vehicle_type, RpcLibAdapatorsBase::Pose(pose), pawn_path).as(); } void RpcLibClientBase::simPrintLogMessage(const std::string& message, std::string message_param, unsigned char severity) diff --git a/AirLib/src/api/RpcLibServerBase.cpp b/AirLib/src/api/RpcLibServerBase.cpp index f56c97b454..16fcd5337e 100644 --- a/AirLib/src/api/RpcLibServerBase.cpp +++ b/AirLib/src/api/RpcLibServerBase.cpp @@ -153,24 +153,9 @@ RpcLibServerBase::RpcLibServerBase(ApiProvider* api_provider, const std::string& return RpcLibAdapatorsBase::MeshPositionVertexBuffersResponse::from(response); }); - pimpl_->server.bind("simAddVehicle", [&](const std::string& vehicle_name, const std::string& vehicle_type, const std::string& pawn_path, float north, float east, float down) -> bool { - - AirSimSettings::VehicleSetting vehicle_setting; - - // TODO expose other VehicleSettings fields - vehicle_setting.vehicle_name = vehicle_name; - vehicle_setting.vehicle_type = vehicle_type; - vehicle_setting.pawn_path = pawn_path; - - vehicle_setting.position[0] = north; - vehicle_setting.position[1] = east; - vehicle_setting.position[2] = down; - - vehicle_setting.rotation.yaw = 0; - vehicle_setting.rotation.pitch = 0; - vehicle_setting.rotation.roll = 0; - - return getWorldSimApi()->createVehicleAtRuntime(vehicle_setting); + pimpl_->server.bind("simAddVehicle", [&](const std::string& vehicle_name, const std::string& vehicle_type, + const RpcLibAdapatorsBase::Pose& pose, const std::string& pawn_path) -> bool { + return getWorldSimApi()->createVehicleAtRuntime(vehicle_name, vehicle_type, pose.to(), pawn_path); }); pimpl_->server.bind("simSetVehiclePose", [&](const RpcLibAdapatorsBase::Pose &pose, bool ignore_collision, const std::string& vehicle_name) -> void { diff --git a/PythonClient/airsim/client.py b/PythonClient/airsim/client.py index b211a72c78..0d4026261d 100644 --- a/PythonClient/airsim/client.py +++ b/PythonClient/airsim/client.py @@ -857,22 +857,20 @@ def simCreateVoxelGrid(self, position, x, y, z, res, of): return self.client.call('simCreateVoxelGrid', position, x, y, z, res, of) # Add new vehicle via RPC - def simAddVehicle(self, vehicle_name, vehicle_type, pawn_path, north, east, down): + def simAddVehicle(self, vehicle_name, vehicle_type, pose, pawn_path = ""): """ Create vehicle at runtime Args: vehicle_name (str): Name of the vehicle being created vehicle_type (str): Type of vehicle, e.g. "simpleflight" - pawn_path (str): Vehicle blueprint path - north (float): Metres in North direction to spawn at vehicle at - east (float): Meters in East direction to spawn vehicle at - down (float): Metres below to spawn the vehicle at + pose (Pose): Initial pose of the vehicle + pawn_path (str): Vehicle blueprint path, default empty wbich uses the default blueprint for the vehicle type Returns: bool: Whether vehicle was created """ - return self.client.call('simAddVehicle', vehicle_name, vehicle_type, pawn_path, north, east, down) + return self.client.call('simAddVehicle', vehicle_name, vehicle_type, pose, pawn_path) # ----------------------------------- Multirotor APIs --------------------------------------------- class MultirotorClient(VehicleClient, object): diff --git a/Unreal/Plugins/AirSim/Source/WorldSimApi.cpp b/Unreal/Plugins/AirSim/Source/WorldSimApi.cpp index 25e29d2a00..58ca6c6fe7 100644 --- a/Unreal/Plugins/AirSim/Source/WorldSimApi.cpp +++ b/Unreal/Plugins/AirSim/Source/WorldSimApi.cpp @@ -268,8 +268,17 @@ void WorldSimApi::setTimeOfDay(bool is_enabled, const std::string& start_datetim celestial_clock_speed, update_interval_secs, move_sun); } -bool WorldSimApi::createVehicleAtRuntime(AirSimSettings::VehicleSetting& vehicle_setting) +bool WorldSimApi::createVehicleAtRuntime(const std::string& vehicle_name, const std::string& vehicle_type, const Pose& pose, const std::string& pawn_path) { + // Create settings object + AirSimSettings::VehicleSetting vehicle_setting; + + vehicle_setting.vehicle_name = vehicle_name; + vehicle_setting.vehicle_type = vehicle_type; + vehicle_setting.pawn_path = pawn_path; + vehicle_setting.position = pose.position; + VectorMath::toEulerianAngle(pose.orientation, vehicle_setting.rotation.pitch, vehicle_setting.rotation.roll, vehicle_setting.rotation.yaw); + bool result; // We need to run this code on the main game thread, since it iterates over actors diff --git a/Unreal/Plugins/AirSim/Source/WorldSimApi.h b/Unreal/Plugins/AirSim/Source/WorldSimApi.h index 6524538736..4072c33b3a 100644 --- a/Unreal/Plugins/AirSim/Source/WorldSimApi.h +++ b/Unreal/Plugins/AirSim/Source/WorldSimApi.h @@ -38,7 +38,7 @@ class WorldSimApi : public msr::airlib::WorldSimApiBase { virtual bool setSegmentationObjectID(const std::string& mesh_name, int object_id, bool is_name_regex = false) override; virtual int getSegmentationObjectID(const std::string& mesh_name) const override; - virtual bool createVehicleAtRuntime(msr::airlib::AirSimSettings::VehicleSetting& vehicle_setting); + virtual bool createVehicleAtRuntime(const std::string& vehicle_name, const std::string& vehicle_type, const Pose& pose, const std::string& pawn_path = "") override; virtual void printLogMessage(const std::string& message, const std::string& message_param = "", unsigned char severity = 0) override;