Skip to content

Commit

Permalink
Use Pose instead of NED values, fix missing override
Browse files Browse the repository at this point in the history
  • Loading branch information
rajat2004 committed Mar 5, 2021
1 parent 4489b90 commit 208c3cb
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 30 deletions.
2 changes: 1 addition & 1 deletion AirLib/include/api/RpcLibClientBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class RpcLibClientBase {
vector<uint8_t> simGetImage(const std::string& camera_name, ImageCaptureBase::ImageType type, const std::string& vehicle_name = "");

vector<MeshPositionVertexBuffersResponse> 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;

Expand Down
2 changes: 1 addition & 1 deletion AirLib/include/api/WorldSimApiBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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 @@ -243,9 +243,9 @@ vector<MeshPositionVertexBuffersResponse> 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<bool>();
return pimpl_->client.call("simAddVehicle", vehicle_name, vehicle_type, RpcLibAdapatorsBase::Pose(pose), pawn_path).as<bool>();
}

void RpcLibClientBase::simPrintLogMessage(const std::string& message, std::string message_param, unsigned char severity)
Expand Down
21 changes: 3 additions & 18 deletions AirLib/src/api/RpcLibServerBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 4 additions & 6 deletions PythonClient/airsim/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
11 changes: 10 additions & 1 deletion Unreal/Plugins/AirSim/Source/WorldSimApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Unreal/Plugins/AirSim/Source/WorldSimApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 208c3cb

Please sign in to comment.