Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement simSetObjectPose API #1161

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AirLib/include/api/RpcLibClientBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class RpcLibClientBase {
void simPrintLogMessage(const std::string& message, std::string message_param = "", unsigned char severity = 0);

Pose simGetObjectPose(const std::string& object_name);
void simSetObjectPose(const std::string& object_name, const Pose& pose);
CameraInfo getCameraInfo(int camera_id);
void setCameraOrientation(int camera_id, const Quaternionr& orientation);

Expand Down
1 change: 1 addition & 0 deletions AirLib/include/api/VehicleApiBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class VehicleApiBase {
virtual CollisionInfo getCollisionInfo() const = 0;

virtual Pose simGetObjectPose(const std::string& object_name) const = 0;
virtual void simSetObjectPose(const std::string& object_name, const Pose& pose) = 0;

virtual CameraInfo getCameraInfo(int camera_id) const = 0;
virtual void setCameraOrientation(int camera_id, const Quaternionr& orientation) = 0;
Expand Down
3 changes: 2 additions & 1 deletion AirLib/include/controllers/VehicleConnectorBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ class VehicleConnectorBase : public UpdatableObject
virtual int getSegmentationObjectID(const std::string& mesh_name) = 0;
virtual void printLogMessage(const std::string& message, std::string message_param = "", unsigned char severity = 0) = 0;
virtual Pose getActorPose(const std::string& actor_name) = 0;
virtual void setActorPose(const std::string& actor_name, const Pose& pose) = 0;
virtual Kinematics::State getTrueKinematics() = 0;
virtual CameraInfo getCameraInfo(int camera_id) const = 0;
virtual void setCameraOrientation(int camera_id, const Quaternionr& orientation) = 0;
};


}} //namespace
#endif
#endif
5 changes: 5 additions & 0 deletions AirLib/include/vehicles/multirotor/api/MultirotorApi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@ class MultirotorApi : public VehicleApiBase {
return vehicle_->getActorPose(actor_name);
}

virtual void simSetObjectPose(const std::string& actor_name, const Pose& pose) override
{
vehicle_->setActorPose(actor_name, pose);
}

virtual void simSetPose(const Pose& pose, bool ignore_collision) override
{
vehicle_->setPose(pose, ignore_collision);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ class RealMultirotorConnector : public VehicleConnectorBase
return msr::airlib::Pose();
}

virtual void setActorPose(const std::string& actor_name, const Pose& pose) override
{
unused(actor_name);
unused(pose);
}

virtual CameraInfo getCameraInfo(int camera_id) const override
{
unused(camera_id);
Expand All @@ -101,4 +107,4 @@ class RealMultirotorConnector : public VehicleConnectorBase


}} //namespace
#endif
#endif
4 changes: 4 additions & 0 deletions AirLib/src/api/RpcLibClientBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ msr::airlib::Pose RpcLibClientBase::simGetObjectPose(const std::string& object_n
return pimpl_->client.call("simGetObjectPose", object_name).as<RpcLibAdapatorsBase::Pose>().to();
}

void RpcLibClientBase::simSetObjectPose(const std::string& object_name, const Pose& pose)
{
pimpl_->client.call("simSetObjectPose", object_name, RpcLibAdapatorsBase::Pose(pose));
}

}} //namespace

Expand Down
4 changes: 4 additions & 0 deletions AirLib/src/api/RpcLibServerBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ RpcLibServerBase::RpcLibServerBase(SimModeApiBase* simmode_api, string server_ad
const auto& pose = getVehicleApi()->simGetObjectPose(object_name);
return RpcLibAdapatorsBase::Pose(pose);
});

pimpl_->server.bind("simSetObjectPose", [&](const std::string& object_name, const RpcLibAdapatorsBase::Pose &pose) {
getVehicleApi()->simSetObjectPose(object_name, pose.to());
});

pimpl_->server.bind("simPause", [&](bool is_paused) -> void {
getSimModeApi()->pause(is_paused);
Expand Down
2 changes: 2 additions & 0 deletions PythonClient/AirSimClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,8 @@ def simPrintLogMessage(self, message, message_param = "", severity = 0):
def simGetObjectPose(self, object_name):
pose = self.client.call('simGetObjectPose', object_name)
return Pose.from_msgpack(pose)
def simSetObjectPose(self, object_name, pose):
return self.client.call('simSetObjectPose', object_name, pose)


# camera control
Expand Down
7 changes: 7 additions & 0 deletions Unreal/Plugins/AirSim/Source/Car/CarPawnApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ msr::airlib::Pose CarPawnApi::simGetObjectPose(const std::string& actor_name) co
return pose;
}

void CarPawnApi::simSetObjectPose(const std::string& actor_name, const msr::airlib::Pose& pose)
{
UAirBlueprintLib::RunCommandOnGameThread([&pose, &actor_name, this]() {
pawn_->setActorPose(actor_name, pose);
}, true);
}

const CarApiBase::CarControls& CarPawnApi::getCarControls() const
{
return last_controls_;
Expand Down
3 changes: 2 additions & 1 deletion Unreal/Plugins/AirSim/Source/Car/CarPawnApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class CarPawnApi : public msr::airlib::CarApiBase {
virtual const CarApiBase::CarControls& getCarControls() const override;

virtual msr::airlib::Pose simGetObjectPose(const std::string& actor_name) const override;
virtual void simSetObjectPose(const std::string& actor_name, const msr::airlib::Pose& pose) override;
virtual msr::airlib::CameraInfo getCameraInfo(int camera_id) const override;
virtual void setCameraOrientation(int camera_id, const msr::airlib::Quaternionr& orientation) override;

Expand All @@ -57,4 +58,4 @@ class CarPawnApi : public msr::airlib::CarApiBase {
UWheeledVehicleMovementComponent* movement_;
bool api_control_enabled_ = false;
CarControls last_controls_;
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,13 @@ Pose MultiRotorConnector::getActorPose(const std::string& actor_name)
return pose;
}

void MultiRotorConnector::setActorPose(const std::string& actor_name, const Pose& pose)
{
UAirBlueprintLib::RunCommandOnGameThread([&pose, &actor_name, this]() {
wrapper_->setActorPose(actor_name, pose);
}, true);
}

bool MultiRotorConnector::setSegmentationObjectID(const std::string& mesh_name, int object_id,
bool is_name_regex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class MultiRotorConnector : public msr::airlib::VehicleConnectorBase

virtual void printLogMessage(const std::string& message, std::string message_param = "", unsigned char severity = 0) override;
virtual Pose getActorPose(const std::string& actor_name) override;
virtual void setActorPose(const std::string& actor_name, const Pose& pose) override;
virtual CameraInfo getCameraInfo(int camera_id) const override;
virtual void setCameraOrientation(int camera_id, const Quaternionr& orientation) override;

Expand Down
11 changes: 10 additions & 1 deletion Unreal/Plugins/AirSim/Source/VehiclePawnWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,4 +408,13 @@ msr::airlib::Pose VehiclePawnWrapper::getActorPose(std::string actor_name)
: Pose::nanPose();
}


void VehiclePawnWrapper::setActorPose(std::string actor_name, const msr::airlib::Pose& pose)
{
AActor* actor = UAirBlueprintLib::FindActor<AActor>(pawn_, FString(actor_name.c_str()));
if (actor)
{
FVector location = ned_transform_.toNeuUU(pose.position);
FQuat quat = ned_transform_.toFQuat(pose.orientation, true);
actor->SetActorLocationAndRotation(location, quat, false, nullptr, ETeleportType::TeleportPhysics);
}
}
1 change: 1 addition & 0 deletions Unreal/Plugins/AirSim/Source/VehiclePawnWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class VehiclePawnWrapper
const WrapperConfig& getConfig() const;

msr::airlib::Pose getActorPose(std::string actor_name);
void setActorPose(std::string actor_name, const msr::airlib::Pose& pose);
std::string getVehicleConfigName() const;

int getRemoteControlID() const;
Expand Down