You've already forked LuckyWorld
FT - Primitive WebSocket Actuators Control
+ Optionally allow remote control of the robot + Direct set of actuators, this should pass by the layer controler for proper interpolation
This commit is contained in:
Binary file not shown.
@ -60,3 +60,7 @@ void URobotPilotComponent::SetRobotTarget(const FTransform& TargetTransformIn)
|
||||
void URobotPilotComponent::SetRobotCurrentRewardZone(const FTransform& RewardTransformIn)
|
||||
{
|
||||
}
|
||||
|
||||
void URobotPilotComponent::ReceiveRemoteCommand(const FRemoteControlPayload& RemoteRobotPayload)
|
||||
{
|
||||
}
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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<ULuckyDataTransferSubsystem>())
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
@ -40,4 +40,6 @@ public:
|
||||
URobotPilotComponent* RobotPilotComponent = nullptr;
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void InitPilotComponent(); // This should have Robot type as parameter?
|
||||
|
||||
void EnableRemoteControl();
|
||||
};
|
||||
|
Reference in New Issue
Block a user