diff --git a/Content/Levels/kitchenLevel/kitchenLevel1.umap b/Content/Levels/kitchenLevel/kitchenLevel1.umap index 62a4b7f5..471da775 100644 Binary files a/Content/Levels/kitchenLevel/kitchenLevel1.umap and b/Content/Levels/kitchenLevel/kitchenLevel1.umap differ diff --git a/Source/LuckyWorldV2/Private/Robot/PilotComponent/RobotPilotComponent.cpp b/Source/LuckyWorldV2/Private/Robot/PilotComponent/RobotPilotComponent.cpp index 26d2e9a2..5d796682 100644 --- a/Source/LuckyWorldV2/Private/Robot/PilotComponent/RobotPilotComponent.cpp +++ b/Source/LuckyWorldV2/Private/Robot/PilotComponent/RobotPilotComponent.cpp @@ -60,3 +60,7 @@ void URobotPilotComponent::SetRobotTarget(const FTransform& TargetTransformIn) void URobotPilotComponent::SetRobotCurrentRewardZone(const FTransform& RewardTransformIn) { } + +void URobotPilotComponent::ReceiveRemoteCommand(const FRemoteControlPayload& RemoteRobotPayload) +{ +} diff --git a/Source/LuckyWorldV2/Private/Robot/PilotComponent/RobotPilotSO100Component.cpp b/Source/LuckyWorldV2/Private/Robot/PilotComponent/RobotPilotSO100Component.cpp index 9ecd187d..38144155 100644 --- a/Source/LuckyWorldV2/Private/Robot/PilotComponent/RobotPilotSO100Component.cpp +++ b/Source/LuckyWorldV2/Private/Robot/PilotComponent/RobotPilotSO100Component.cpp @@ -1,4 +1,6 @@ #include "Robot/PilotComponent/RobotPilotSO100Component.h" + +#include "LuckyDataTransferSubsystem.h" #include "Actors/MujocoVolumeActor.h" #include "Kismet/KismetMathLibrary.h" #include "Robot/RobotPawn.h" @@ -85,6 +87,14 @@ void URobotPilotSO100Component::SetRobotCurrentRewardZone(const FTransform& Rewa bDropZoneIsRight = FVector::DotProduct(RobotOwner->RobotActor->GetActorRotation().Quaternion().GetRightVector(), DirectionToTarget) > 0.f; } +void URobotPilotSO100Component::ReceiveRemoteCommand(const FRemoteControlPayload& RemoteRobotPayload) +{ + for (const auto& [ActuatorName, ActuatorValue] : RemoteRobotPayload.Commands) + { + // Will print an error message if it doesn't exists + RobotOwner->PhysicsSceneProxy->SetActuatorValue(ActuatorName, ActuatorValue); + } +} void URobotPilotSO100Component::PrintCurrentActuators() const { diff --git a/Source/LuckyWorldV2/Private/Robot/RobotPawn.cpp b/Source/LuckyWorldV2/Private/Robot/RobotPawn.cpp index 8335967b..587adb17 100644 --- a/Source/LuckyWorldV2/Private/Robot/RobotPawn.cpp +++ b/Source/LuckyWorldV2/Private/Robot/RobotPawn.cpp @@ -1,5 +1,6 @@ #include "Robot/RobotPawn.h" +#include "LuckyDataTransferSubsystem.h" #include "LuckySensorPawnBase.h" #include "Kismet/GameplayStatics.h" #include "Kismet/KismetMathLibrary.h" @@ -69,3 +70,19 @@ void ARobotPawn::InitPilotComponent() } } +void ARobotPawn::EnableRemoteControl() +{ + // Get subsystem + if (ULuckyDataTransferSubsystem* DataTransfer = GetWorld()->GetSubsystem()) + { + // Connect first if necessary + if (!DataTransfer->Socket->IsConnected()) + { + DataTransfer->ConnectToWebsocket("ws://127.0.0.1:3000", ""); + } + + // TODO Should we wait for connection to be successful before binding OnCommandReady? + DataTransfer->OnCommandReady.AddDynamic(this->RobotPilotComponent, &URobotPilotComponent::ReceiveRemoteCommand); + } +} + diff --git a/Source/LuckyWorldV2/Public/Robot/PilotComponent/RobotPilotComponent.h b/Source/LuckyWorldV2/Public/Robot/PilotComponent/RobotPilotComponent.h index 4b610192..b1b82568 100644 --- a/Source/LuckyWorldV2/Public/Robot/PilotComponent/RobotPilotComponent.h +++ b/Source/LuckyWorldV2/Public/Robot/PilotComponent/RobotPilotComponent.h @@ -2,6 +2,8 @@ #include "CoreMinimal.h" #include "RobotPilotComponent.generated.h" +struct FRemoteControlPayload; + USTRUCT(BlueprintType) struct FRobotActuators { @@ -33,6 +35,9 @@ public: UFUNCTION(BlueprintCallable) virtual void SetRobotTarget(const FTransform& TargetTransformIn); virtual void SetRobotCurrentRewardZone(const FTransform& RewardTransformIn); + + UFUNCTION() + virtual void ReceiveRemoteCommand(const FRemoteControlPayload& RemoteRobotPayload); protected: // Child class need access diff --git a/Source/LuckyWorldV2/Public/Robot/PilotComponent/RobotPilotSO100Component.h b/Source/LuckyWorldV2/Public/Robot/PilotComponent/RobotPilotSO100Component.h index 14ae6c7c..768f7e47 100644 --- a/Source/LuckyWorldV2/Public/Robot/PilotComponent/RobotPilotSO100Component.h +++ b/Source/LuckyWorldV2/Public/Robot/PilotComponent/RobotPilotSO100Component.h @@ -3,6 +3,8 @@ #include "Robot/PilotComponent/RobotPilotComponent.h" #include "RobotPilotSO100Component.generated.h" +struct FRemoteControlPayload; + USTRUCT(BlueprintType) struct FSo100Actuators { @@ -42,6 +44,7 @@ public: virtual void SetRobotTarget(const FTransform& TargetTransformIn) override; virtual void SetRobotCurrentRewardZone(const FTransform& RewardTransformIn) override; + virtual void ReceiveRemoteCommand(const FRemoteControlPayload& RemoteRobotPayload) override; private: diff --git a/Source/LuckyWorldV2/Public/Robot/RobotPawn.h b/Source/LuckyWorldV2/Public/Robot/RobotPawn.h index 1d1df691..e2bd9240 100644 --- a/Source/LuckyWorldV2/Public/Robot/RobotPawn.h +++ b/Source/LuckyWorldV2/Public/Robot/RobotPawn.h @@ -40,4 +40,6 @@ public: URobotPilotComponent* RobotPilotComponent = nullptr; UFUNCTION(BlueprintCallable) void InitPilotComponent(); // This should have Robot type as parameter? + + void EnableRemoteControl(); };