diff --git a/AirLib/include/api/RpcLibClientBase.hpp b/AirLib/include/api/RpcLibClientBase.hpp index 7609fb175f..73ebfb3e0f 100644 --- a/AirLib/include/api/RpcLibClientBase.hpp +++ b/AirLib/include/api/RpcLibClientBase.hpp @@ -80,6 +80,8 @@ class RpcLibClientBase { vector simGetImages(vector request, const std::string& vehicle_name = ""); vector simGetImage(const std::string& camera_name, ImageCaptureBase::ImageType type, const std::string& vehicle_name = ""); + void simAddMarker(double lat, double lon, float alt, float radius, float lifetime); + CollisionInfo simGetCollisionInfo(const std::string& vehicle_name = "") const; CameraInfo simGetCameraInfo(const std::string& camera_name, const std::string& vehicle_name = "") const; diff --git a/AirLib/include/api/VehicleSimApiBase.hpp b/AirLib/include/api/VehicleSimApiBase.hpp index 766b2e696e..b562612cf6 100644 --- a/AirLib/include/api/VehicleSimApiBase.hpp +++ b/AirLib/include/api/VehicleSimApiBase.hpp @@ -52,6 +52,8 @@ class VehicleSimApiBase : public msr::airlib::UpdatableObject { virtual std::vector getImages(const std::vector& request) const = 0; virtual std::vector getImage(const std::string& camera_name, ImageCaptureBase::ImageType image_type) const = 0; + + virtual void simAddMarker(msr::airlib::GeoPoint lla, float radius, float lifetime) = 0; virtual Pose getPose() const = 0; virtual void setPose(const Pose& pose, bool ignore_collision) = 0; diff --git a/AirLib/src/api/RpcLibClientBase.cpp b/AirLib/src/api/RpcLibClientBase.cpp index cd15f72cb9..aff4256580 100644 --- a/AirLib/src/api/RpcLibClientBase.cpp +++ b/AirLib/src/api/RpcLibClientBase.cpp @@ -232,6 +232,12 @@ vector RpcLibClientBase::simGetImage(const std::string& camera_name, Im return result; } +void RpcLibClientBase::simAddMarker(double lat, double lon, float alt, float radius, float lifetime) +{ + float radiusCentimeters = radius * 100.0f; + pimpl_->client.call("simAddMarker", lat, lon, alt, radiusCentimeters, lifetime); +} + void RpcLibClientBase::simPrintLogMessage(const std::string& message, std::string message_param, unsigned char severity) { pimpl_->client.call("simPrintLogMessage", message, message_param, severity); diff --git a/AirLib/src/api/RpcLibServerBase.cpp b/AirLib/src/api/RpcLibServerBase.cpp index 067a2270b1..1f79eff4ba 100644 --- a/AirLib/src/api/RpcLibServerBase.cpp +++ b/AirLib/src/api/RpcLibServerBase.cpp @@ -101,6 +101,11 @@ RpcLibServerBase::RpcLibServerBase(ApiProvider* api_provider, const std::string& return getVehicleApi(vehicle_name)->armDisarm(arm); }); + pimpl_->server.bind("simAddMarker", [&](double lat, double lon, float alt, float radius, float lifetime) -> void { + GeoPoint lla(lat, lon, alt); + return getVehicleSimApi("")->simAddMarker(lla, radius, lifetime); + }); + pimpl_->server.bind("simGetImages", [&](const std::vector& request_adapter, const std::string& vehicle_name) -> vector { const auto& response = getVehicleSimApi(vehicle_name)->getImages(RpcLibAdapatorsBase::ImageRequest::to(request_adapter)); diff --git a/Unreal/Plugins/AirSim/Source/PawnSimApi.cpp b/Unreal/Plugins/AirSim/Source/PawnSimApi.cpp index 0543c18faa..79a72cb809 100644 --- a/Unreal/Plugins/AirSim/Source/PawnSimApi.cpp +++ b/Unreal/Plugins/AirSim/Source/PawnSimApi.cpp @@ -1,4 +1,5 @@ #include "PawnSimApi.h" +#include "DrawDebugHelpers.h" #include "Engine/World.h" #include "Kismet/KismetSystemLibrary.h" #include "Kismet/GameplayStatics.h" @@ -287,6 +288,28 @@ int PawnSimApi::getCameraCount() return cameras_.valsSize(); } +void PawnSimApi::simAddMarker(msr::airlib::GeoPoint lla, float radius, float lifetime) +{ + NedTransform zero_based_ned_transform(FTransform::Identity, UAirBlueprintLib::GetWorldToMetersScale(getPawn())); + msr::airlib::Vector3r calculatedNed = msr::airlib::EarthUtils::GeodeticToNedFast(lla, AirSimSettings::singleton().origin_geopoint.home_geo_point); + FVector targetLocation = zero_based_ned_transform.fromGlobalNed(calculatedNed); + + DrawDebugSphere + ( + getPawn()->GetWorld(), + targetLocation, + radius, + 32, + FColor(255, 255, 255), + false, + lifetime + /*, + uint8 DepthPriority, + float Thickness + */ + ); +} + void PawnSimApi::reset() { VehicleSimApiBase::reset(); diff --git a/Unreal/Plugins/AirSim/Source/PawnSimApi.h b/Unreal/Plugins/AirSim/Source/PawnSimApi.h index ca1bad591a..98f7b11fa6 100644 --- a/Unreal/Plugins/AirSim/Source/PawnSimApi.h +++ b/Unreal/Plugins/AirSim/Source/PawnSimApi.h @@ -109,7 +109,10 @@ class PawnSimApi : public msr::airlib::VehicleSimApiBase { APIPCamera* getCamera(const std::string& camera_name); int getCameraCount(); - //if enabled, this would show some flares + // Add a basic spherical marker to the scene + void simAddMarker(msr::airlib::GeoPoint lla, float radius, float lifetime); + + //if enabled, this would show some flares void displayCollisionEffect(FVector hit_location, const FHitResult& hit); //return the attached pawn diff --git a/docs/apis.md b/docs/apis.md index 866ee36377..fdb6f4badd 100644 --- a/docs/apis.md +++ b/docs/apis.md @@ -135,6 +135,9 @@ AirSim allows to pause and continue the simulation through `pause(is_paused)` AP ### Collision API The collision information can be obtained using `simGetCollisionInfo` API. This call returns a struct that has information not only whether collision occurred but also collision position, surface normal, penetration depth and so on. +### Debug Marker API +You can add spherical markers in the sim using simAddMarker(lat, lon, alt, radius, lifetime). + ### Time of Day API AirSim assumes there exist sky sphere of class `EngineSky/BP_Sky_Sphere` in your environment with [ADirectionalLight actor](https://github.com/Microsoft/AirSim/blob/master/Unreal/Plugins/AirSim/Source/SimMode/SimModeBase.cpp#L156). By default, the position of the sun in the scene doesn't move with time. You can use [settings](settings.md#timeofday) to set up latitude, longitude, date and time which AirSim uses to compute the position of sun in the scene.