Skip to content

Instantly share code, notes, and snippets.

@oppne
Last active November 12, 2017 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oppne/3ea4a720b83a00c2e086040398acb059 to your computer and use it in GitHub Desktop.
Save oppne/3ea4a720b83a00c2e086040398acb059 to your computer and use it in GitHub Desktop.
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "UObject/NoExportTypes.h"
#include "vehicles/multirotor/api/MultirotorRpcLibClient.hpp"
#include "LeController.generated.h"
//some flight functions require enums/structs from DroneCommon.hpp but accessible to BP
UENUM(BlueprintType)
enum class EDrivetrainType : uint8
{
MaxDegreeOfFreedom = 0,
ForwardOnly
};
//USTRUCT(immutable, noexport, BlueprintType)
USTRUCT(BlueprintType)
struct AIRSIM_API FYawMode {
GENERATED_USTRUCT_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Drone")
bool is_rate = true;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Drone")
float yaw_or_rate = 0.0f;
FYawMode()
{}
FYawMode(bool is_rate_val, float yaw_or_rate_val)
{
is_rate = is_rate_val;
yaw_or_rate = yaw_or_rate_val;
}
static FYawMode Zero()
{
return FYawMode(true, 0);
}
void setZeroRate()
{
is_rate = true;
yaw_or_rate = 0;
}
};
/**
* helper class that exposes flight API to blue prints
*/
UCLASS(Blueprintable)
class AIRSIM_API ALeController : public AActor
{
GENERATED_BODY()
protected:
msr::airlib::MultirotorRpcLibClient client;
public:
ALeController(const FObjectInitializer& ObjectInitializer);
UFUNCTION(BlueprintCallable, Category = "Drone")
bool armDisarm(bool arm);
UFUNCTION(BlueprintCallable, Category = "Drone")
void enableApiControl(bool enable);
UFUNCTION(BlueprintCallable, Category = "Drone")
bool goHome();
UFUNCTION(BlueprintCallable, Category = "Drone")
bool hover();
UFUNCTION(BlueprintCallable, Category = "Drone")
bool land(float max_wait_seconds);
UFUNCTION(BlueprintCallable, Category = "Drone")
void setSimulationMode(bool is_set);
UFUNCTION(BlueprintCallable, Category = "Drone")
bool takeoff(float max_wait_ms);
UFUNCTION(BlueprintCallable, Category = "Drone")
bool moveByAngle(float pitch, float roll, float z, float yaw, float duration);
UFUNCTION(BlueprintCallable, Category = "Drone")
bool moveByVelocity(float vx, float vy, float vz, float duration);
UFUNCTION(BlueprintCallable, Category = "Drone")
bool moveByVelocityEx(float vx, float vy, float vz, float duration,
EDrivetrainType drivetrain, UPARAM(ref) FYawMode& yaw_mode);
UFUNCTION(BlueprintCallable, Category = "Drone")
bool moveByVelocityZ(float vx, float vy, float z, float duration);
UFUNCTION(BlueprintCallable, Category = "Drone")
bool moveByVelocityZEx(float vx, float vy, float z, float duration,
EDrivetrainType drivetrain, UPARAM(ref) FYawMode& yaw_mode);
UFUNCTION(BlueprintCallable, Category = "Drone")
bool moveOnPath(UPARAM(ref) TArray<FVector>& path, float velocity, float max_wait_seconds,
EDrivetrainType drivetrain, UPARAM(ref) FYawMode& yaw_mode, float lookahead, float adaptive_lookahead);
UFUNCTION(BlueprintCallable, Category = "Drone")
bool moveToPosition(float x, float y, float z, float velocity);
UFUNCTION(BlueprintCallable, Category = "Drone")
bool moveToPositionEx(float x, float y, float z, float velocity, float max_wait_seconds,
EDrivetrainType drivetrain, UPARAM(ref) FYawMode& yaw_mode, float lookahead, float adaptive_lookahead);
UFUNCTION(BlueprintCallable, Category = "Drone")
bool moveToZ(float z, float velocity);
UFUNCTION(BlueprintCallable, Category = "Drone")
bool moveToZEx(float z, float velocity, float max_wait_seconds,
UPARAM(ref) FYawMode& yaw_mode, float lookahead, float adaptive_lookahead);
UFUNCTION(BlueprintCallable, Category = "Drone")
bool moveByManual(float vx_max, float vy_max, float z_min, float duration);
UFUNCTION(BlueprintCallable, Category = "Drone")
bool moveByManualEx(float vx_max, float vy_max, float z_min, float duration,
EDrivetrainType drivetrain, UPARAM(ref) FYawMode& yaw_mode);
UFUNCTION(BlueprintCallable, Category = "Drone")
bool rotateToYaw(float yaw);
UFUNCTION(BlueprintCallable, Category = "Drone")
bool rotateToYawEx(float yaw, float max_wait_seconds, float margin);
UFUNCTION(BlueprintCallable, Category = "Drone")
bool rotateByYawRate(float yaw_rate, float duration);
//getters
UFUNCTION(BlueprintCallable, Category = "Drone")
FVector getPosition();
UFUNCTION(BlueprintCallable, Category = "Drone")
FVector getVelocity();
UFUNCTION(BlueprintCallable, Category = "Drone")
FQuat getOrientation();
UFUNCTION(BlueprintCallable, Category = "Drone")
FVector getGpsLocation();
UFUNCTION(BlueprintCallable, Category = "Drone")
bool isSimulationMode();
UFUNCTION(BlueprintCallable, Category = "Drone")
FString getDebugInfo();
///getLandedState returns true if copter has landed, false otherwise
UFUNCTION(BlueprintCallable, Category = "Drone")
bool getLandedState();
UFUNCTION(BlueprintCallable, Category = "Drone")
int timestampNow();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment