Skip to content

Commit

Permalink
Merge with upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
saihv committed Apr 17, 2017
2 parents dc92d49 + c52e24f commit a15f8ec
Show file tree
Hide file tree
Showing 24 changed files with 247 additions and 277 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ deps/

/boost
/eigen
/Eigen3
/build_debug
/cmake/CPackSourceConfig.cmake
/cmake/CPackConfig.cmake
Expand All @@ -309,3 +310,5 @@ deps/
/AirLib/include/controllers/latex
/Eigen3
/AirLib/lib/libAirLib.a


Binary file not shown.
Binary file modified Unreal/Plugins/AirSim/Content/Blueprints/BP_FlyingPawn.uasset
Binary file not shown.
Binary file modified Unreal/Plugins/AirSim/Content/Blueprints/BP_PIPCamera.uasset
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Unreal/Plugins/AirSim/Content/HUDAssets/DepthRenderTarget.uasset
Binary file not shown.
Binary file not shown.
5 changes: 2 additions & 3 deletions Unreal/Plugins/AirSim/Source/AirBlueprintLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,9 @@ void UAirBlueprintLib::FollowActor(AActor* follower, const AActor* followee, con

template<class UserClass>
FInputActionBinding& UAirBlueprintLib::BindActionToKey(const FName action_name, const FKey in_key, UserClass* actor,
typename FInputActionHandlerSignature::TUObjectMethodDelegate<UserClass>::FMethodPtr func,
bool shift_key, bool control_key, bool alt_key, bool command_key)
typename FInputActionHandlerSignature::TUObjectMethodDelegate<UserClass>::FMethodPtr func)
{
FInputActionKeyMapping action(action_name, in_key, shift_key, control_key, alt_key, command_key);
FInputActionKeyMapping action(action_name, in_key);

APlayerController* controller = actor->GetWorld()->GetFirstPlayerController();

Expand Down
3 changes: 1 addition & 2 deletions Unreal/Plugins/AirSim/Source/AirBlueprintLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ class UAirBlueprintLib : public UBlueprintFunctionLibrary

template<class UserClass>
static FInputActionBinding& BindActionToKey(const FName action_name, const FKey in_key, UserClass* actor,
typename FInputActionHandlerSignature::TUObjectMethodDelegate< UserClass >::FMethodPtr func,
bool shift_key = false, bool control_key = false, bool alt_key = false, bool command_key = false);
typename FInputActionHandlerSignature::TUObjectMethodDelegate< UserClass >::FMethodPtr func);

template<class UserClass>
static FInputAxisBinding& BindAxisToKey(const FName axis_name, const FKey in_key, UserClass* actor,
Expand Down
2 changes: 1 addition & 1 deletion Unreal/Plugins/AirSim/Source/AirSim.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private void SetupCompileMode(CompileMode mode, TargetInfo Target)
public AirSim(TargetInfo Target)
{
UEBuildConfiguration.bForceEnableExceptions = true;
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "RenderCore" });
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "RenderCore", "RHI" });
PrivateDependencyModuleNames.AddRange(new string[] { "UMG", "Slate", "SlateCore" });

//suppress VC++ proprietary warnings
Expand Down
1 change: 1 addition & 0 deletions Unreal/Plugins/AirSim/Source/CameraDirector.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<<<<<<< HEAD
#include "AirSim.h"
#include "CameraDirector.h"
#include "AirBlueprintLib.h"
Expand Down
38 changes: 0 additions & 38 deletions Unreal/Plugins/AirSim/Source/CameraDirector.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@
#include "GameFramework/Actor.h"
#include "CameraDirector.generated.h"


UENUM(BlueprintType)
enum class ECameraDirectorMode : uint8
{
CAMERA_DIRECTOR_MODE_FPV = 1 UMETA(DisplayName="FPV"),
CAMERA_DIRECTOR_MODE_GROUND_OBSERVER = 2 UMETA(DisplayName="GroundObserver"),
CAMERA_DIRECTOR_MODE_FLY_WITH_ME = 3 UMETA(DisplayName="FlyWithMe"),
CAMERA_DIRECTOR_MODE_MANUAL = 4 UMETA(DisplayName="Manual")
};

UCLASS()
class AIRSIM_API ACameraDirector : public AActor
{
Expand All @@ -31,8 +21,6 @@ class AIRSIM_API ACameraDirector : public AActor
void InputEventFpvView();
UFUNCTION(BlueprintImplementableEvent, meta = (DisplayName = "InputEventGroundView"))
void InputEventGroundView();
UFUNCTION(BlueprintImplementableEvent, meta = (DisplayName = "InputEventManualView"))
void InputEventManualView();
UFUNCTION(BlueprintImplementableEvent, meta = (DisplayName = "InputEventFlyWithView"))
void InputEventFlyWithView();

Expand All @@ -53,33 +41,7 @@ class AIRSIM_API ACameraDirector : public AActor
virtual void BeginPlay() override;
virtual void Tick( float DeltaSeconds ) override;

UFUNCTION(BlueprintCallable, Category = "Modes")
ECameraDirectorMode getMode();
UFUNCTION(BlueprintCallable, Category = "Modes")
void setMode(ECameraDirectorMode mode);

private:
void setupInputBindings();
bool checkCameraRefs();
void enableManualBindings(bool enable);

void inputManualLeft(float val);
void inputManualRight(float val);
void inputManualForward(float val);
void inputManualBackward(float val);
void inputManualMoveUp(float val);
void inputManualDown(float val);
void inputManualLeftYaw(float val);
void inputManualUpPitch(float val);
void inputManualRightYaw(float val);
void inputManualDownPitch(float val);

private:
ECameraDirectorMode mode_;
FInputAxisBinding *left_binding_, *right_binding_, *up_binding_, *down_binding_;
FInputAxisBinding *forward_binding_, *backward_binding_, *left_yaw_binding_, *up_pitch_binding_;
FInputAxisBinding *right_yaw_binding_, *down_pitch_binding_;

FVector camera_location_manual_;
FRotator camera_rotation_manual_;
};
147 changes: 90 additions & 57 deletions Unreal/Plugins/AirSim/Source/FlyingPawn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,87 +8,120 @@

void AFlyingPawn::initialize()
{
Super::initialize();
Super::initialize();
}

void AFlyingPawn::initializeForPlay()
{
//get references of components so we can use later
setupComponentReferences();
//get references of components so we can use later
setupComponentReferences();

//set stencil IDs
setStencilIDs();
//set stencil IDs
setStencilIDs();

setupInputBindings();
setupInputBindings();

detectUsbRc();
detectUsbRc();
}

void AFlyingPawn::detectUsbRc()
{
joystick_.getJoyStickState(0, joystick_state_);

rc_data_.is_connected = joystick_state_.is_connected;

if (rc_data_.is_connected)
UAirBlueprintLib::LogMessage(TEXT("RC Controller on USB: "), "Detected", LogDebugLevel::Informational);
else
UAirBlueprintLib::LogMessage(TEXT("RC Controller on USB: "), "Not detected", LogDebugLevel::Informational);
std::string vehicleName = AFlyingPawn::getVehicleName();

if (vehicleName.compare(std::string("Quad1")) == 0)
{
joystick_.getJoyStickState(0, joystick_state_);
rc_data_.is_connected = joystick_state_.is_connected;

if (rc_data_.is_connected)
UAirBlueprintLib::LogMessage(TEXT("RC Controller on USB for vehicle 1: "), "Detected", LogDebugLevel::Informational);
else
UAirBlueprintLib::LogMessage(TEXT("RC Controller on USB: "), "Not detected", LogDebugLevel::Informational);
}

if (vehicleName.compare(std::string("Quad2")) == 0)
{
joystick_.getJoyStickState(1, joystick_state_);
rc_data_.is_connected = joystick_state_.is_connected;

if (rc_data_.is_connected)
UAirBlueprintLib::LogMessage(TEXT("RC Controller on USB for vehicle 2: "), "Detected", LogDebugLevel::Informational);
else
UAirBlueprintLib::LogMessage(TEXT("RC Controller on USB: "), "Not detected", LogDebugLevel::Informational);
}

if (vehicleName.compare(std::string("Quad3")) == 0)
{
joystick_.getJoyStickState(2, joystick_state_);
rc_data_.is_connected = joystick_state_.is_connected;

if (rc_data_.is_connected)
UAirBlueprintLib::LogMessage(TEXT("RC Controller on USB for vehicle 3: "), "Detected", LogDebugLevel::Informational);
else
UAirBlueprintLib::LogMessage(TEXT("RC Controller on USB for vehicle 3: "), "Not detected", LogDebugLevel::Informational);
}
}

void AFlyingPawn::setStencilIDs()
{
TArray<AActor*> foundActors;
UAirBlueprintLib::FindAllActor<AActor>(this, foundActors);
TArray<UStaticMeshComponent*> components;
int stencil = 0;
for (AActor* actor : foundActors) {
actor->GetComponents(components);
if (components.Num() == 1) {
components[0]->SetRenderCustomDepth(true);
components[0]->CustomDepthStencilValue = (stencil++) % 256;
components[0]->MarkRenderStateDirty();
}
}
TArray<AActor*> foundActors;
UAirBlueprintLib::FindAllActor<AActor>(this, foundActors);
TArray<UStaticMeshComponent*> components;
int stencil = 0;
for (AActor* actor : foundActors) {
actor->GetComponents(components);
if (components.Num() == 1) {
components[0]->SetRenderCustomDepth(true);
components[0]->CustomDepthStencilValue = (stencil++) % 256;
components[0]->MarkRenderStateDirty();
}
}
}

const AFlyingPawn::RCData& AFlyingPawn::getRCData()
{
joystick_.getJoyStickState(0, joystick_state_);
std::string vehicleName = AFlyingPawn::getVehicleName();

rc_data_.is_connected = joystick_state_.is_connected;
if (vehicleName.compare(std::string("Quad1")) == 0)
joystick_.getJoyStickState(0, joystick_state_);
else if (vehicleName.compare(std::string("Quad2")) == 0)
joystick_.getJoyStickState(1, joystick_state_);
else if (vehicleName.compare(std::string("Quad3")) == 0)
joystick_.getJoyStickState(2, joystick_state_);

if (rc_data_.is_connected) {
rc_data_.throttle = joyStickToRC(joystick_state_.left_y);
rc_data_.yaw = joyStickToRC(joystick_state_.left_x);
rc_data_.roll = joyStickToRC(joystick_state_.right_x);
rc_data_.pitch = joyStickToRC(joystick_state_.right_y);
rc_data_.is_connected = joystick_state_.is_connected;

rc_data_.switch1 = joystick_state_.left_trigger ? 1 : 0;
rc_data_.switch2 = joystick_state_.right_trigger ? 1 : 0;
}
//else don't waste time

return rc_data_;
if (rc_data_.is_connected) {
rc_data_.throttle = joyStickToRC(joystick_state_.left_y);
rc_data_.yaw = joyStickToRC(joystick_state_.left_x);
rc_data_.roll = joyStickToRC(joystick_state_.right_x);
rc_data_.pitch = joyStickToRC(joystick_state_.right_y);

rc_data_.switch1 = joystick_state_.left_trigger ? 1 : 0;
rc_data_.switch2 = joystick_state_.right_trigger ? 1 : 0;
}
//else don't waste time

return rc_data_;
}

float AFlyingPawn::joyStickToRC(int16_t val)
{
float valf = static_cast<float>(val);
return (valf - Utils::min<int16_t>()) / Utils::max<uint16_t>();
float valf = static_cast<float>(val);
return (valf) / (Utils::max<uint16_t>()/2);
}

void AFlyingPawn::reset()
{
Super::reset();
Super::reset();

rc_data_ = RCData();
rc_data_ = RCData();
}


APIPCamera* AFlyingPawn::getFpvCamera()
{
return fpv_camera_;
return fpv_camera_;
}

void AFlyingPawn::setRotorSpeed(int rotor_index, float radsPerSec)
Expand All @@ -103,27 +136,27 @@ void AFlyingPawn::setRotorSpeed(int rotor_index, float radsPerSec)

std::string AFlyingPawn::getVehicleName()
{
return std::string(TCHAR_TO_UTF8(*VehicleName));
return std::string(TCHAR_TO_UTF8(*VehicleName));
}

void AFlyingPawn::setupComponentReferences()
{
fpv_camera_ = Cast<APIPCamera>(
(UAirBlueprintLib::GetActorComponent<UChildActorComponent>(this, TEXT("LeftPIPCamera")))->GetChildActor());
fpv_camera_ = Cast<APIPCamera>(
(UAirBlueprintLib::GetActorComponent<UChildActorComponent>(this, TEXT("LeftPIPCamera")))->GetChildActor());

for (auto i = 0; i < 4; ++i) {
rotating_movements_[i] = UAirBlueprintLib::GetActorComponent<URotatingMovementComponent>(this, TEXT("Rotation") + FString::FromInt(i));
}
for (auto i = 0; i < 4; ++i) {
rotating_movements_[i] = UAirBlueprintLib::GetActorComponent<URotatingMovementComponent>(this, TEXT("Rotation") + FString::FromInt(i));
}
}


void AFlyingPawn::setupInputBindings()
{
//this->EnableInput(this->GetWorld()->GetFirstPlayerController());
//this->EnableInput(this->GetWorld()->GetFirstPlayerController());

//UAirBlueprintLib::BindAxisToKey("InputEventThrottle", EKeys::Gamepad_LeftY, this, &AFlyingPawn::inputEventThrottle);
//UAirBlueprintLib::BindAxisToKey("InputEventYaw", EKeys::Gamepad_LeftX, this, &AFlyingPawn::inputEventYaw);
//UAirBlueprintLib::BindAxisToKey("InputEventPitch", EKeys::Gamepad_RightY, this, &AFlyingPawn::inputEventPitch);
//UAirBlueprintLib::BindAxisToKey("InputEventRoll", EKeys::Gamepad_RightX, this, &AFlyingPawn::inputEventRoll);
//UAirBlueprintLib::BindActionToKey("InputEventArmDisArm", EKeys::Gamepad_LeftTrigger, this, &AFlyingPawn::inputEventArmDisArm);
//UAirBlueprintLib::BindAxisToKey("InputEventThrottle", EKeys::Gamepad_LeftY, this, &AFlyingPawn::inputEventThrottle);
//UAirBlueprintLib::BindAxisToKey("InputEventYaw", EKeys::Gamepad_LeftX, this, &AFlyingPawn::inputEventYaw);
//UAirBlueprintLib::BindAxisToKey("InputEventPitch", EKeys::Gamepad_RightY, this, &AFlyingPawn::inputEventPitch);
//UAirBlueprintLib::BindAxisToKey("InputEventRoll", EKeys::Gamepad_RightX, this, &AFlyingPawn::inputEventRoll);
//UAirBlueprintLib::BindActionToKey("InputEventArmDisArm", EKeys::Gamepad_LeftTrigger, this, &AFlyingPawn::inputEventArmDisArm);
}
32 changes: 16 additions & 16 deletions Unreal/Plugins/AirSim/Source/FlyingPawn.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ class AIRSIM_API AFlyingPawn : public AVehiclePawnBase
GENERATED_BODY()

public: //interface
typedef msr::airlib::RCData RCData;
typedef msr::airlib::RCData RCData;

void setRotorSpeed(int rotor_index, float radsPerSec);
std::string getVehicleName();
std::string getVehicleName();

const RCData& getRCData();
const RCData& getRCData();

public:
//overrides from VehiclePawnBase
virtual APIPCamera* getFpvCamera() override;
virtual void initialize() override;
virtual void reset() override;
//overrides from VehiclePawnBase
virtual APIPCamera* getFpvCamera() override;
virtual void initialize() override;
virtual void reset() override;

public: //blueprint
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Debugging")
Expand All @@ -33,23 +33,23 @@ class AIRSIM_API AFlyingPawn : public AVehiclePawnBase
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HIL")
FString VehicleName = "Pixhawk";

UFUNCTION(BlueprintCallable, Category = "Init")
void initializeForPlay();
UFUNCTION(BlueprintCallable, Category = "Init")
void initializeForPlay();

private: //methods
void setupComponentReferences();
void setStencilIDs();
void setupInputBindings();
void detectUsbRc();
static float joyStickToRC(int16_t val);
void setupInputBindings();
void detectUsbRc();
static float joyStickToRC(int16_t val);

private: //variables
//Unreal components
static constexpr size_t rotor_count = 4;
UPROPERTY() APIPCamera* fpv_camera_;
UPROPERTY() URotatingMovementComponent* rotating_movements_[rotor_count];

SimJoyStick joystick_;
SimJoyStick::State joystick_state_;
RCData rc_data_;
};
SimJoyStick joystick_;
SimJoyStick::State joystick_state_;
RCData rc_data_;
};
Loading

0 comments on commit a15f8ec

Please sign in to comment.