Agrarsense
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
APIDDrone Class Reference

#include <PIDDrone.h>

Inheritance diagram for APIDDrone:
Inheritance graph
[legend]
Collaboration diagram for APIDDrone:
Collaboration graph
[legend]

Public Member Functions

 APIDDrone ()
 
virtual EVehicleTypes GetVehicleType () const override
 
virtual FTransform GetInteractableWorldTransform_Implementation () const override
 
void SetDroneAction (EDroneAction mode)
 Set drone's action (roaming, manual) More...
 
EDroneAction GetDroneAction () const
 Get drone's action (roaming, manual) More...
 
FDroneParameters GetDroneParameters () const
 
void ChangeDroneParameters (const FDroneParameters &newParameters)
 
void AddWayPoint (FVector Waypoint)
 
float GetDroneDistanceToNextPoint ()
 
float GetDroneSpeed () const
 
void ClearWaypoints ()
 
void SetFlightpath ()
 Called in tick function for drone roaming through points. More...
 
void SetManualControl (bool value)
 
void MoveDroneToPosition (const FTransform Transform)
 Override all drone roaming points and continue towards this position. More...
 
TArray< FTransform > GenerateRoamingPoints (float radius, int32 roamingPoints)
 Generates a roadming points array for the drone in radius. More...
 
float GetYawRotationDifference (USkeletalMeshComponent *DroneSkeletalMesh, UStaticMeshComponent *DesiredLocation)
 Get wanted waypoint target rotation. More...
 
virtual void SetCurrentTransformToMovedFromGarageTransform () override
 
void SetShowForwardArrow (bool Show)
 
void SetDrawDebugPoints (bool show)
 
bool GetShowForwardArrow () const
 
USkeletalMeshComponent * GetDroneSkeletalMesh () const
 
- Public Member Functions inherited from AVehicle
 AVehicle ()
 
virtual EVehicleTypes GetVehicleType () const
 
void TogglePhysics (bool isOn)
 
void SetVehicleMeshVisibility (bool Visible)
 
void TeleportVehicleTo (FVector NewLocation, FRotator NewRotation)
 
virtual void TeleportVehicleTo_Implementation (FVector NewLocation, FRotator NewRotation)
 
void ResetCamera ()
 
void ToggleLights (bool isOn)
 
void SetVisualizeVehicleOverlapArea (bool Visible)
 
FString ExportToJsonFile (const FString &FileName)
 
void SetVehicleIsInGarage (bool VehicleIsInGarage)
 
bool IsVehicleInGarage () const
 
USensorsManagerComponent * GetSensorsManager () const
 
ACollisionSensorGetCollisionSensor () const
 
ATransformSensorGetTransformSensor () const
 
AOverlapSensorGetOverlapSensor () const
 
FTransform GetMovedFromGarageTransform () const
 
virtual void SetCurrentTransformToMovedFromGarageTransform ()
 
virtual FText GetInteractableName_Implementation () const override
 
virtual FTransform GetInteractableWorldTransform_Implementation () const override
 
virtual FString GetActorID_Implementation () const override
 
virtual FString GetActorName_Implementation () const override
 
virtual FString GetActorInformation_Implementation () const override
 
virtual void SetActorName_Implementation (const FString &NewActorName) override
 
virtual void SetActorIDAndName_Implementation (const FString &NewActorName, const FString &NewID) override
 
void SetVehicleParameters (FWheeledVehicleParameters NewParameters)
 
FWheeledVehicleParameters GetVehicleParameters () const
 
void ApplyVehicleParameters (FWheeledVehicleParameters CurrentParameters)
 
virtual void PossessedBy (AController *NewController) override
 
- Public Member Functions inherited from IInteractable
FText GetInteractableName () const
 
FTransform GetInteractableWorldTransform () const
 
- Public Member Functions inherited from IActorInformation
FString GetActorID () const
 
FString GetActorName () const
 
FString GetActorInformation () const
 
void SetActorName (const FString &NewActorName)
 
void SetActorIDAndName (const FString &NewActorName, const FString &NewID)
 

Public Attributes

FDroneFinished OnDroneFinished
 
- Public Attributes inherited from AVehicle
FText InteractableName
 
FVehicleGarageChangedDelegate OnVehicleGarageChanged
 

Protected Member Functions

void ROSBridgeStateChanged (EROSState ROSState) override
 
virtual void BeginPlay () override
 
virtual void EndPlay (const EEndPlayReason::Type EndPlayReason) override
 
virtual void ROSBridgeStateChanged (EROSState ROSState)
 

Protected Attributes

UTopic * ROSTopic = nullptr
 
TSharedPtr< ROSMessages::std_msgs::Float32 > ROSMessage
 
- Protected Attributes inherited from AVehicle
FWheeledVehicleParameters VehicleParameters
 
TObjectPtr< USensorsManagerComponent > SensorsManager
 
ACollisionSensorCollisionSensor = nullptr
 
ATransformSensorTransformSensor = nullptr
 
AOverlapSensorOverlapSensor = nullptr
 
UNiagaraComponent * NiagaraComponent = nullptr
 
TArray< UStaticMeshComponent * > ExtraTransformSensorPositions
 
FString ActorName
 
FString ActorID
 
FTransform OriginalCameraTransform
 
FTransform MovedFromGarageTransform
 
bool VehicleInGarage = false
 
TArray< ATransformSensor * > ExtraTransformSensors
 

Private Member Functions

virtual void BeginPlay () override
 
virtual void Tick (float DeltaTime) override
 
virtual void EndPlay (const EEndPlayReason::Type EndPlayReason) override
 
void CreateTopic ()
 
void DestroyTopic ()
 
void HandleDestroy ()
 
void AutoPilot (const float DeltaTime)
 
void DrawDebugPoints ()
 
void AssignRoamingPoints (const TArray< FTransform > Points)
 
void SetDroneRotation (USkeletalMeshComponent *target, FRotator rotator)
 
void UpdateGroundHeight ()
 
bool IsRoaming () const
 
void SetDesiredLocationMesh (UStaticMeshComponent *meshcomponent)
 
FVector GetCurrentWaypointTarget ()
 
FTransform GetCurrentWaypointTarget_Transform ()
 

Private Attributes

FDroneParameters DroneParameters
 
EFlightMode flightmode = EFlightMode::Roaming
 
UWorld * World = nullptr
 
FVector StartingPosition
 
USkeletalMeshComponent * DroneSkeletalMesh = nullptr
 
UStaticMeshComponent * PositionMesh = nullptr
 
AOverlapSensorInnerOverlapSensor = nullptr
 
TArray< FVector > WayPoints
 
bool waypointReached = false
 
bool manualControl = false
 
bool ShowForwardArrow = false
 
bool drawDebugPoints = false
 
int32 passedWaypoints = 0
 
float DroneHeightFromGround = 0.0f
 
float distanceToNextPoint = 0.0f
 
TArray< FTransform > dronePath
 
FTimerHandle DestroyHandle
 

Additional Inherited Members

- Static Public Member Functions inherited from IActorInformation
static void SetAndValidateActorIDAndName (FString &ActorName, FString &ActorID, TWeakObjectPtr< AActor > Actor)
 
static bool DestroyActorByID (const FString &ID)
 
static AActor * GetActorByID (const FString &ID)
 
template<typename T >
static TArray< T * > GetActorsWithInterface ()
 
static void PrintAllIds ()
 

Detailed Description

Definition at line 25 of file PIDDrone.h.

Constructor & Destructor Documentation

◆ APIDDrone()

APIDDrone::APIDDrone ( )

Definition at line 28 of file PIDDrone.cpp.

28 : Super()
29{
30 PrimaryActorTick.bCanEverTick = true;
31 InteractableName = NSLOCTEXT("Agrarsense", "DroneInteractableName", "Drone");
32}
FText InteractableName
Definition: Vehicle.h:261

References AVehicle::InteractableName.

Member Function Documentation

◆ AddWayPoint()

void APIDDrone::AddWayPoint ( FVector  Waypoint)
inline

Definition at line 83 of file PIDDrone.h.

84 {
85 FTransform transform;
86 transform.SetLocation(Waypoint);
87
88 DroneParameters.Points.Add(transform);
89 }
FDroneParameters DroneParameters
Definition: PIDDrone.h:244
TArray< FTransform > Points

References FDroneParameters::Points.

◆ AssignRoamingPoints()

void APIDDrone::AssignRoamingPoints ( const TArray< FTransform >  Points)
private

Definition at line 354 of file PIDDrone.cpp.

355{
357
358 for (const FTransform& point : Points)
359 {
360 WayPoints.Add(point.GetLocation());
361 }
362}
TArray< FVector > WayPoints
Definition: PIDDrone.h:264
void ClearWaypoints()
Definition: PIDDrone.h:115

References ClearWaypoints(), and WayPoints.

◆ AutoPilot()

void APIDDrone::AutoPilot ( const float  DeltaTime)
private

Definition at line 186 of file PIDDrone.cpp.

187{
189 {
190 return;
191 }
192
194}
void SetFlightpath()
Called in tick function for drone roaming through points.
Definition: PIDDrone.cpp:246
EDroneAction DroneAction

References FDroneParameters::DroneAction, DroneParameters, SetFlightpath(), and Stationary.

Referenced by Tick().

◆ BeginPlay()

void APIDDrone::BeginPlay ( )
overrideprivatevirtual

Reimplemented from AVehicle.

Definition at line 90 of file PIDDrone.cpp.

91{
92 Super::BeginPlay();
93
94 World = GetWorld();
95
96 ROSMessage.Reset();
97 ROSMessage = MakeShared<ROSMessages::std_msgs::Float32>();
98
100
101 // These should be setup in BP_Drone_PID blueprint.
102 DroneSkeletalMesh = Cast<USkeletalMeshComponent>(GetComponentByClass(USkeletalMeshComponent::StaticClass()));
103 PositionMesh = Cast<UStaticMeshComponent>(GetComponentByClass(UStaticMeshComponent::StaticClass()));
104
105 StartingPosition = GetActorLocation();
106 FTransform ActorTransform = GetActorTransform();
107
109 {
110 // Create Transform sensor for forwarder and harvester
112 Params.SaveTransformDataToDisk = true;
113 Params.OwningActor = this;
114 Params.UseOwningActorTransform = false;
115 Params.PrimitiveComponent = Cast<UPrimitiveComponent>(DroneSkeletalMesh);
116
117 FString VehicleTransformSensorID = ActorID + "/transform";
118 TransformSensor = USensorFactory::SpawnTransformSensor(ActorTransform, Params, VehicleTransformSensorID, "transform", true, this);
119 }
120
121 if (!OverlapSensor)
122 {
123 // Create OverlapSensor
125 Params.OwningActor = this;
126 Params.Size = FVector(25.0f, 25.0f, 25.0f);
127 Params.RelativePosition = FVector(0.0f, 0.0f, 0.0f);
128 FString OverlapSensorID = ActorID + "/overlap";
129 OverlapSensor = USensorFactory::SpawnOverlapSensor(ActorTransform, Params, OverlapSensorID, "overlap", this);
130
131 if (OverlapSensor)
132 {
133 OverlapSensor->AttachToComponent(DroneSkeletalMesh, FAttachmentTransformRules::KeepRelativeTransform);
134 }
135 }
136
138 {
139 // Attach rain/snowfall niagara component to drone skeletal mesh.
140 NiagaraComponent->AttachToComponent(DroneSkeletalMesh, FAttachmentTransformRules::KeepRelativeTransform);
141 }
142
143 // Apply default parameters
145}
TSharedPtr< ROSMessages::std_msgs::Float32 > ROSMessage
Definition: PIDDrone.h:198
void CreateTopic()
Definition: PIDDrone.cpp:487
UWorld * World
Definition: PIDDrone.h:250
FVector StartingPosition
Definition: PIDDrone.h:252
UStaticMeshComponent * PositionMesh
Definition: PIDDrone.h:258
USkeletalMeshComponent * DroneSkeletalMesh
Definition: PIDDrone.h:255
void ChangeDroneParameters(const FDroneParameters &newParameters)
Definition: PIDDrone.cpp:34
FString ActorID
Definition: Vehicle.h:308
AOverlapSensor * OverlapSensor
Definition: Vehicle.h:294
ATransformSensor * TransformSensor
Definition: Vehicle.h:291
UNiagaraComponent * NiagaraComponent
Definition: Vehicle.h:297
static AOverlapSensor * SpawnOverlapSensor(const FTransform &transform, FOverlapSensorParameters Parameters, const FString sensorIdentifier, const FString sensorName, AActor *Parent=nullptr)
static ATransformSensor * SpawnTransformSensor(const FTransform &transform, FTransformSensorParameters Parameters, const FString sensorIdentifier, const FString sensorName, bool SimulateSensor=true, AActor *Parent=nullptr)
UPrimitiveComponent * PrimitiveComponent

References AVehicle::ActorID, ChangeDroneParameters(), CreateTopic(), DroneParameters, DroneSkeletalMesh, AVehicle::NiagaraComponent, AVehicle::OverlapSensor, FOverlapSensorParameters::OwningActor, FTransformSensorParameters::OwningActor, PositionMesh, FTransformSensorParameters::PrimitiveComponent, FOverlapSensorParameters::RelativePosition, ROSMessage, FTransformSensorParameters::SaveTransformDataToDisk, FOverlapSensorParameters::Size, USensorFactory::SpawnOverlapSensor(), USensorFactory::SpawnTransformSensor(), StartingPosition, AVehicle::TransformSensor, FTransformSensorParameters::UseOwningActorTransform, and World.

◆ ChangeDroneParameters()

void APIDDrone::ChangeDroneParameters ( const FDroneParameters newParameters)

Definition at line 34 of file PIDDrone.cpp.

35{
36#if WITH_EDITOR
37 UE_LOG(LogTemp, Warning, TEXT("Parameters Changed!"));
38#endif
39
40 DroneParameters = newParameters;
41
43 {
44 // Create OverlapSensor
46 Params.OwningActor = this;
47 Params.AllChannels = true;
48
49 const float RadiusMeters = DroneParameters.InnerOverlapRadiusMeters;
50 Params.Size = FVector(RadiusMeters, RadiusMeters, RadiusMeters);
51
52 Params.RelativePosition = FVector(0.0f, 0.0f, 0.0f);
53 FString OverlapSensorID = ActorID + "/inner_overlap";
54 InnerOverlapSensor = USensorFactory::SpawnOverlapSensor(GetActorTransform(), Params, OverlapSensorID, "overlap", this);
55
57 {
58 InnerOverlapSensor->AttachToComponent(DroneSkeletalMesh, FAttachmentTransformRules::KeepRelativeTransform);
59 }
60 }
62 {
63 InnerOverlapSensor->Destroy();
64 InnerOverlapSensor = nullptr;
65 }
66
68 {
69 DroneSkeletalMesh->SetCollisionProfileName(TEXT("DroneNoCollision"));
70 }
71
72 if (OverlapSensor)
73 {
75
76 const float BoundsSizeMeters = DroneParameters.OverlapRadiusMeters;
77 OverlapSensor->SetOverlapBounds(FVector(BoundsSizeMeters, BoundsSizeMeters, BoundsSizeMeters));
78
79 }
80
82 {
84
85 const float BoundsSizeMeters = DroneParameters.InnerOverlapRadiusMeters;
86 InnerOverlapSensor->SetOverlapBounds(FVector(BoundsSizeMeters, BoundsSizeMeters, BoundsSizeMeters));
87 }
88}
void SetVisualizeOverlapArea(bool Visualize)
void SetOverlapBounds(const FVector &NewSize)
AOverlapSensor * InnerOverlapSensor
Definition: PIDDrone.h:261
float InnerOverlapRadiusMeters

References AVehicle::ActorID, FOverlapSensorParameters::AllChannels, FDroneParameters::CollisionsEnabled, FDroneParameters::CreateInnerOverlapSensor, DroneParameters, DroneSkeletalMesh, FDroneParameters::InnerOverlapRadiusMeters, InnerOverlapSensor, FDroneParameters::OverlapRadiusMeters, AVehicle::OverlapSensor, FOverlapSensorParameters::OwningActor, FOverlapSensorParameters::RelativePosition, AOverlapSensor::SetOverlapBounds(), AOverlapSensor::SetVisualizeOverlapArea(), FOverlapSensorParameters::Size, USensorFactory::SpawnOverlapSensor(), and FDroneParameters::VisualizeOverlap.

Referenced by BeginPlay(), and USimulatorJsonParser::ParseAndSetDroneParameters().

◆ ClearWaypoints()

void APIDDrone::ClearWaypoints ( )
inline

Definition at line 115 of file PIDDrone.h.

116 {
117 DroneParameters.Points.Empty();
118 }

Referenced by AssignRoamingPoints().

◆ CreateTopic()

void APIDDrone::CreateTopic ( )
private

Definition at line 487 of file PIDDrone.cpp.

488{
489 if (ROSTopic)
490 {
491 return;
492 }
493
494 UROSIntegrationGameInstance* ROSInstance = UAgrarsenseStatics::GetROSGameInstance(GetWorld());
495 if (ROSInstance && ROSInstance->IsROSConnected())
496 {
497 ROSTopic = NewObject<UTopic>(UTopic::StaticClass());
498 if (ROSTopic)
499 {
500
501 FString TopicName = FString::Printf(TEXT("/agrarsense/out/vehicles/%s/height"), *GetActorID_Implementation());
502 //UE_LOG(LogTemp, Warning, TEXT("TopicName is %s"), *TopicName);
503
504 ROSTopic->Init(ROSInstance->ROSIntegrationCore, TopicName, "std_msgs/Float32");
505 ROSTopic->Advertise();
506 }
507 }
508}
UTopic * ROSTopic
Definition: PIDDrone.h:196
virtual FString GetActorID_Implementation() const override
Definition: Vehicle.h:202
static UROSIntegrationGameInstance * GetROSGameInstance(const UObject *WorldContextObject)

References AVehicle::GetActorID_Implementation(), UAgrarsenseStatics::GetROSGameInstance(), and ROSTopic.

Referenced by BeginPlay(), and ROSBridgeStateChanged().

◆ DestroyTopic()

void APIDDrone::DestroyTopic ( )
private

Definition at line 527 of file PIDDrone.cpp.

528{
529 if (ROSTopic)
530 {
531 ROSTopic->Unadvertise();
532 ROSTopic->Unsubscribe();
533 ROSTopic->MarkAsDisconnected();
534 ROSTopic->ConditionalBeginDestroy();
535 ROSTopic = nullptr;
536 }
537}

References ROSTopic.

Referenced by EndPlay(), and ROSBridgeStateChanged().

◆ DrawDebugPoints()

void APIDDrone::DrawDebugPoints ( )
private

Definition at line 196 of file PIDDrone.cpp.

197{
198 TArray<FTransform> dronePoints = DroneParameters.Points;
199
200 dronePath.Add(DroneSkeletalMesh->GetComponentTransform());
201
202 for (int i = 0; i < dronePoints.Num(); i++)
203 {
204 if (World)
205 {
206 //UE_LOG(LogTemp, Warning, TEXT("Drone point %d: %s"), i, *dronePoints[i].GetLocation().ToString());
207 DrawDebugSphere(World, dronePoints[i].GetLocation(), 5.0f, 25, FColor::Red, false);
208 if (i < dronePoints.Num() - 1)
209 {
210 FVector nextPointLocation = dronePoints[i + 1].GetLocation();
211 DrawDebugLine(World, dronePoints[i].GetLocation(), nextPointLocation, FColor::Blue, false, 0.0f, 0, 5.0f);
212 }
213 }
214 }
215
216 for (int i = 0; i < dronePath.Num(); i++)
217 {
218 if (i < dronePath.Num() - 1)
219 {
220 FVector nextPointLocation = dronePath[i + 1].GetLocation();
221 DrawDebugLine(World, dronePath[i].GetLocation(), nextPointLocation, FColor::Green, false, 0.0f, 0, 5.0f);
222 }
223 }
224}
TArray< FTransform > dronePath
Definition: PIDDrone.h:283

References DroneParameters, dronePath, DroneSkeletalMesh, FDroneParameters::Points, and World.

Referenced by Tick().

◆ EndPlay()

void APIDDrone::EndPlay ( const EEndPlayReason::Type  EndPlayReason)
overrideprivatevirtual

Reimplemented from AVehicle.

Definition at line 147 of file PIDDrone.cpp.

148{
149 Super::EndPlay(EndPlayReason);
150
151 if (TransformSensor)
152 {
153 TransformSensor->Destroy();
154 TransformSensor = nullptr;
155 }
156
158 {
159 InnerOverlapSensor->Destroy();
160 InnerOverlapSensor = nullptr;
161 }
162
163 ROSMessage.Reset();
164 DestroyTopic();
165}
void DestroyTopic()
Definition: PIDDrone.cpp:527

References DestroyTopic(), InnerOverlapSensor, ROSMessage, and AVehicle::TransformSensor.

◆ GenerateRoamingPoints()

TArray< FTransform > APIDDrone::GenerateRoamingPoints ( float  radius,
int32  roamingPoints 
)

Generates a roadming points array for the drone in radius.

Parameters
radiusradius of the roaming area
Returns
TArray<FVector>

Definition at line 449 of file PIDDrone.cpp.

450{
451 TArray<FTransform> generatedRoamingPoints;
452 generatedRoamingPoints.Reserve(roamingPoints);
453
454 FVector currentPosition = GetTransform().GetLocation();
455
456 FVector min = currentPosition - FVector(radius / 2, radius / 2, 0);
457 FVector max = currentPosition + FVector(radius / 2, radius / 2, 0);
458
459 for (int32 i = 0; i < roamingPoints; i++)
460 {
461 FTransform randomPoint;
462 randomPoint.SetLocation(FVector(FMath::RandRange(min.X, max.X), FMath::RandRange(min.Y, max.Y), 5000));
463
464 generatedRoamingPoints.Add(randomPoint);
465#if WITH_EDITOR
466 UE_LOG(LogTemp, Warning, TEXT("Waypoint %i: (%s)"), i, *randomPoint.GetLocation().ToString());
467#endif
468 }
469
470 return generatedRoamingPoints;
471}

Referenced by SetFlightpath().

◆ GetCurrentWaypointTarget()

FVector APIDDrone::GetCurrentWaypointTarget ( )
private

Definition at line 339 of file PIDDrone.cpp.

340{
341 return GetCurrentWaypointTarget_Transform().GetLocation();
342}
FTransform GetCurrentWaypointTarget_Transform()
Definition: PIDDrone.cpp:344

References GetCurrentWaypointTarget_Transform().

Referenced by SetFlightpath().

◆ GetCurrentWaypointTarget_Transform()

FTransform APIDDrone::GetCurrentWaypointTarget_Transform ( )
private

Definition at line 344 of file PIDDrone.cpp.

345{
347 {
348 return DroneSkeletalMesh->GetRelativeTransform();
349 }
350
352}
int32 passedWaypoints
Definition: PIDDrone.h:277

References DroneParameters, DroneSkeletalMesh, passedWaypoints, and FDroneParameters::Points.

Referenced by GetCurrentWaypointTarget().

◆ GetDroneAction()

EDroneAction APIDDrone::GetDroneAction ( ) const
inline

Get drone's action (roaming, manual)

Returns
Drone's action

Definition at line 68 of file PIDDrone.h.

69 {
71 }

◆ GetDroneDistanceToNextPoint()

float APIDDrone::GetDroneDistanceToNextPoint ( )
inline

Definition at line 92 of file PIDDrone.h.

93 {
94 // On manual flight, return a fixed distance to not affect autofly max speed
96 {
97 return 5000;
98 }
99
100 return distanceToNextPoint;
101 }
float distanceToNextPoint
Definition: PIDDrone.h:281

References Manual.

◆ GetDroneParameters()

FDroneParameters APIDDrone::GetDroneParameters ( ) const
inline

Definition at line 74 of file PIDDrone.h.

75 {
76 return DroneParameters;
77 }

Referenced by USimulatorJsonExporter::SetDroneParameters().

◆ GetDroneSkeletalMesh()

USkeletalMeshComponent * APIDDrone::GetDroneSkeletalMesh ( ) const
inline

Definition at line 186 of file PIDDrone.h.

187 {
188 return DroneSkeletalMesh;
189 }

◆ GetDroneSpeed()

float APIDDrone::GetDroneSpeed ( ) const
inline

Definition at line 104 of file PIDDrone.h.

105 {
107 {
108 return 0;
109 }
110
111 return FMath::Max(FMath::Abs(DroneSkeletalMesh->GetComponentVelocity().X), FMath::Abs(DroneSkeletalMesh->GetComponentVelocity().Y));
112 }

◆ GetInteractableWorldTransform_Implementation()

virtual FTransform APIDDrone::GetInteractableWorldTransform_Implementation ( ) const
inlineoverridevirtual

Reimplemented from AVehicle.

Definition at line 39 of file PIDDrone.h.

40 {
42 {
43 return DroneSkeletalMesh->GetComponentTransform();
44 }
45 else
46 {
47 return GetActorTransform();
48 }
49 }

◆ GetShowForwardArrow()

bool APIDDrone::GetShowForwardArrow ( ) const
inline

Definition at line 180 of file PIDDrone.h.

181 {
182 return ShowForwardArrow;
183 }
bool ShowForwardArrow
Definition: PIDDrone.h:273

◆ GetVehicleType()

virtual EVehicleTypes APIDDrone::GetVehicleType ( ) const
inlineoverridevirtual

Get type of the Vehicle

Returns
Vehicle's type

Reimplemented from AVehicle.

Definition at line 37 of file PIDDrone.h.

References Drone.

◆ GetYawRotationDifference()

float APIDDrone::GetYawRotationDifference ( USkeletalMeshComponent *  DroneSkeletalMesh,
UStaticMeshComponent *  DesiredLocation 
)

Get wanted waypoint target rotation.

Returns
float

Definition at line 510 of file PIDDrone.cpp.

511{
512 if (!DroneMesh || !DesiredLocation)
513 {
514 return 0.0f;
515 }
516
517 FVector ToTarget = DesiredLocation->GetComponentLocation() - DroneMesh->GetComponentLocation();
518 FRotator LookRotation = ToTarget.Rotation();
519
520 float CurrentYaw = DroneMesh->GetComponentRotation().Yaw;
521 float DesiredYaw = LookRotation.Yaw;
522
523 float DeltaYaw = FRotator::NormalizeAxis(DesiredYaw - CurrentYaw);
524 return DeltaYaw;
525}

◆ HandleDestroy()

void APIDDrone::HandleDestroy ( )
private

Definition at line 226 of file PIDDrone.cpp.

227{
228 // Should trigger EndPlay?
229
231 if (SimulationLevelManager)
232 {
233 AVehicle* controlledVehicle = SimulationLevelManager->GetManuallyControlledVehicle();
234
235 if (controlledVehicle == this)
236 {
237 SimulationLevelManager->CeaseManualControlOfVehicle();
238 }
239 }
240
241 passedWaypoints = 0;
242 Destroy();
243}
static ASimulationLevelManager * GetSimulationLevelManager(const UObject *WorldContextObject)

References ASimulationLevelManager::CeaseManualControlOfVehicle(), Destroy, ASimulationLevelManager::GetManuallyControlledVehicle(), UAgrarsenseStatics::GetSimulationLevelManager(), passedWaypoints, and World.

Referenced by SetFlightpath().

◆ IsRoaming()

bool APIDDrone::IsRoaming ( ) const
inlineprivate

Definition at line 227 of file PIDDrone.h.

References Roaming.

Referenced by SetFlightpath().

◆ MoveDroneToPosition()

void APIDDrone::MoveDroneToPosition ( const FTransform  Transform)

Override all drone roaming points and continue towards this position.

Parameters
Transformdrone move position

Definition at line 326 of file PIDDrone.cpp.

327{
328 if (DroneParameters.Points.Num() > 0)
329 {
330 DroneParameters.Points.Empty();
332 }
333 else
334 {
336 }
337}

References DroneParameters, FDroneParameters::Points, and Transform.

◆ ROSBridgeStateChanged()

void APIDDrone::ROSBridgeStateChanged ( EROSState  ROSState)
overrideprotectedvirtual

Reimplemented from AVehicle.

Definition at line 473 of file PIDDrone.cpp.

474{
475 switch (ROSState)
476 {
478 CreateTopic();
479 break;
480
482 DestroyTopic();
483 break;
484 }
485}

References Connected, CreateTopic(), DestroyTopic(), and Disconnected.

◆ SetCurrentTransformToMovedFromGarageTransform()

virtual void APIDDrone::SetCurrentTransformToMovedFromGarageTransform ( )
inlineoverridevirtual

Reimplemented from AVehicle.

Definition at line 153 of file PIDDrone.h.

154 {
156 {
157 MovedFromGarageTransform = DroneSkeletalMesh->GetComponentTransform();
158 UE_LOG(LogTemp, Warning, TEXT("Moved from garage transform %s"), *MovedFromGarageTransform.ToString());
159
160 }
161 else
162 {
163 MovedFromGarageTransform = GetActorTransform();
164 UE_LOG(LogTemp, Warning, TEXT("ACTOR Moved from garage transform WHAT IS THIS: %s"), *MovedFromGarageTransform.ToString());
165
166 }
167 }
FTransform MovedFromGarageTransform
Definition: Vehicle.h:313

◆ SetDesiredLocationMesh()

void APIDDrone::SetDesiredLocationMesh ( UStaticMeshComponent *  meshcomponent)
inlineprivate

Definition at line 233 of file PIDDrone.h.

234 {
235 PositionMesh = meshcomponent;
236 }

◆ SetDrawDebugPoints()

void APIDDrone::SetDrawDebugPoints ( bool  show)
inline

Definition at line 174 of file PIDDrone.h.

175 {
176 drawDebugPoints = show;
177 }
bool drawDebugPoints
Definition: PIDDrone.h:275

Referenced by USimulatorJsonParser::ParseAndSetDroneParameters().

◆ SetDroneAction()

void APIDDrone::SetDroneAction ( EDroneAction  mode)
inline

Set drone's action (roaming, manual)

Definition at line 55 of file PIDDrone.h.

56 {
58 }

◆ SetDroneRotation()

void APIDDrone::SetDroneRotation ( USkeletalMeshComponent *  target,
FRotator  rotator 
)
private

Definition at line 364 of file PIDDrone.cpp.

365{
366 if (!target)
367 {
368 return;
369 }
370
371 FRotator currentRotation = target->GetRelativeRotation();
372 FRotator rotationDifference = rotator - currentRotation;
373
374 target->AddRelativeRotation(rotationDifference, false, nullptr, ETeleportType::TeleportPhysics);
375
376 // Prevent locking up when using interp
377 if (FMath::Abs(rotator.Pitch) < 0.001f)
378 {
379 rotator.Pitch = 0.0f;
380 }
381 if (FMath::Abs(rotator.Yaw) < 0.001f)
382 {
383 rotator.Yaw = 0.0f;
384 }
385 if (FMath::Abs(rotator.Roll) < 0.001f)
386 {
387 rotator.Roll = 0.0f;
388 }
389
390 // Corrected rotation
391 target->SetRelativeRotation(rotator, false, nullptr, ETeleportType::TeleportPhysics);
392}

◆ SetFlightpath()

void APIDDrone::SetFlightpath ( )

Called in tick function for drone roaming through points.

Definition at line 246 of file PIDDrone.cpp.

247{
248 // TODO: Check if in garage
249 // include drone rotation to point
250
251 // Don't try to fly if no waypoints
252 if (DroneParameters.Points.Num() == 0 && IsRoaming())
253 {
255 }
256
257 FVector waypoint = GetCurrentWaypointTarget();
258 FVector currentlocation = DroneSkeletalMesh->GetRelativeTransform().GetLocation();
259
260 if (PositionMesh)
261 {
262 // Doesn't work
263 PositionMesh->SetWorldLocation(waypoint);
264 }
265#if WITH_EDITOR
266 else
267 {
268 UE_LOG(LogTemp, Warning, TEXT("Desired location mesh not found"));
269 //DrawDebugLine(World, currentlocation, waypoint, FColor::Red, false, 0.0f, 0.0f, 5.0f);
270 }
271#endif
272 distanceToNextPoint = FVector2f::Distance(FVector2f(waypoint.X, waypoint.Y), FVector2f(currentlocation.X, currentlocation.Y));
273 if (distanceToNextPoint < 100)
274 {
275 waypointReached = true;
276 if (passedWaypoints != DroneParameters.Points.Num() - 1)
277 {
278#if WITH_EDITOR
279 UE_LOG(LogTemp, Warning, TEXT("Changing waypoint from %i to %i"), passedWaypoints, passedWaypoints + 1);
280#endif
281
283 }
284 else
285 {
287 {
289 passedWaypoints = 0;
290 }
291 else
292 {
294 {
297 OnDroneFinished.Broadcast(DroneParameters.Points.Last());
298 break;
301 passedWaypoints = 0;
302 break;
304 passedWaypoints = 0;
305 break;
307 Algo::Reverse(DroneParameters.Points);
308 passedWaypoints = 0;
309 break;
311 OnDroneFinished.Broadcast(DroneParameters.Points.Last());
312 if (!GetWorld()->GetTimerManager().IsTimerActive(DestroyHandle))
313 {
315 GetWorld()->GetTimerManager().SetTimer(DestroyHandle, this, &APIDDrone::HandleDestroy, 5.0f, false);
316 }
317 break;
318 default:
319 break;
320 }
321 }
322 }
323 }
324}
bool waypointReached
Definition: PIDDrone.h:269
FVector GetCurrentWaypointTarget()
Definition: PIDDrone.cpp:339
void HandleDestroy()
Definition: PIDDrone.cpp:226
bool IsRoaming() const
Definition: PIDDrone.h:227
FDroneFinished OnDroneFinished
Definition: PIDDrone.h:61
FTimerHandle DestroyHandle
Definition: PIDDrone.h:285
TArray< FTransform > GenerateRoamingPoints(float radius, int32 roamingPoints)
Generates a roadming points array for the drone in radius.
Definition: PIDDrone.cpp:449
EDroneEndAction DroneEndAction

References Destroy, DestroyHandle, distanceToNextPoint, FDroneParameters::DroneAction, FDroneParameters::DroneEndAction, DroneParameters, DroneSkeletalMesh, GenerateRandomNew, GenerateRoamingPoints(), GetCurrentWaypointTarget(), GoBackwards, HandleDestroy(), IsRoaming(), OnDroneFinished, passedWaypoints, FDroneParameters::Points, PositionMesh, RepeatFromBeginning, Roaming, Stationary, Stop, and waypointReached.

Referenced by AutoPilot().

◆ SetManualControl()

void APIDDrone::SetManualControl ( bool  value)
inline

Definition at line 127 of file PIDDrone.h.

128 {
129 manualControl = value;
130 }
bool manualControl
Definition: PIDDrone.h:271

◆ SetShowForwardArrow()

void APIDDrone::SetShowForwardArrow ( bool  Show)
inline

Definition at line 169 of file PIDDrone.h.

170 {
171 ShowForwardArrow = Show;
172 }

Referenced by USimulatorJsonParser::ParseAndSetDroneParameters().

◆ Tick()

void APIDDrone::Tick ( float  DeltaTime)
overrideprivatevirtual

Definition at line 167 of file PIDDrone.cpp.

168{
169 Super::Tick(DeltaTime);
170
171 if (!IsVehicleInGarage())
172 {
173 AutoPilot(DeltaTime);
175
176#if WITH_EDITOR
177 if (drawDebugPoints)
178 {
180 }
181#endif
182
183 }
184}
void AutoPilot(const float DeltaTime)
Definition: PIDDrone.cpp:186
void UpdateGroundHeight()
Definition: PIDDrone.cpp:394
void DrawDebugPoints()
Definition: PIDDrone.cpp:196
bool IsVehicleInGarage() const
Definition: Vehicle.h:131

References AutoPilot(), DrawDebugPoints(), drawDebugPoints, AVehicle::IsVehicleInGarage(), and UpdateGroundHeight().

◆ UpdateGroundHeight()

void APIDDrone::UpdateGroundHeight ( )
private

Definition at line 394 of file PIDDrone.cpp.

395{
396 if (!DroneSkeletalMesh || !ROSTopic || !ROSMessage.IsValid())
397 {
398 return;
399 }
400
401 FVector Start = DroneSkeletalMesh->GetComponentLocation();
402 FVector End = Start - FVector(0, 0, 10000.0f);
403
404 FCollisionQueryParams TraceParams = FCollisionQueryParams(FName(TEXT("UpdateGroundHeight")), true, this);
405 TraceParams.bReturnPhysicalMaterial = false;
406 TraceParams.bTraceComplex = false;
407
408 FHitResult HitResult;
409
410#ifdef ParallelLineTraceSingleByChannel_EXISTS
411 // Defined and implemented in our AGRARSENSE Unreal Engine fork
412 // This LineTrace method doesn't block the physics scene which improves linetrace performance.
413 World->ParallelLineTraceSingleByChannel(
414 HitResult,
415 Start,
416 End,
417 ECC_Visibility,
418 TraceParams,
419 FCollisionResponseParams::DefaultResponseParam);
420#else
421 // If not using our fork of the engine, use default LineTrace method.
422 World->LineTraceSingleByChannel(
423 HitResult,
424 Start,
425 End,
426 ECC_Visibility,
427 TraceParams,
428 FCollisionResponseParams::DefaultResponseParam);
429#endif
430
431 if (HitResult.IsValidBlockingHit())
432 {
433 float Height = (Start.Z - HitResult.ImpactPoint.Z) / 100.0f;
434 float HeightRounded = FMath::RoundToFloat(Height * 1000.0f) / 1000.0f;
435
436 if (!FMath::IsNearlyEqual(DroneHeightFromGround, HeightRounded, 0.005f))
437 {
438 DroneHeightFromGround = HeightRounded;
439
441 ROSTopic->Publish(ROSMessage);
442
443 //FString HitActorName = HitResult.GetActor() ? HitResult.GetActor()->GetName() : TEXT("None");
444 //UE_LOG(LogTemp, Log, TEXT("Drone is %f meters above ground. Hit object: %s"), DroneHeightFromGround, *HitActorName);
445 }
446 }
447}
float DroneHeightFromGround
Definition: PIDDrone.h:279

References DroneHeightFromGround, DroneSkeletalMesh, ROSMessage, ROSTopic, and World.

Referenced by Tick().

Member Data Documentation

◆ DestroyHandle

FTimerHandle APIDDrone::DestroyHandle
private

Definition at line 285 of file PIDDrone.h.

Referenced by SetFlightpath().

◆ distanceToNextPoint

float APIDDrone::distanceToNextPoint = 0.0f
private

Definition at line 281 of file PIDDrone.h.

Referenced by SetFlightpath().

◆ drawDebugPoints

bool APIDDrone::drawDebugPoints = false
private

Definition at line 275 of file PIDDrone.h.

Referenced by Tick().

◆ DroneHeightFromGround

float APIDDrone::DroneHeightFromGround = 0.0f
private

Definition at line 279 of file PIDDrone.h.

Referenced by UpdateGroundHeight().

◆ DroneParameters

FDroneParameters APIDDrone::DroneParameters
private

◆ dronePath

TArray<FTransform> APIDDrone::dronePath
private

Definition at line 283 of file PIDDrone.h.

Referenced by DrawDebugPoints().

◆ DroneSkeletalMesh

USkeletalMeshComponent* APIDDrone::DroneSkeletalMesh = nullptr
private

◆ flightmode

EFlightMode APIDDrone::flightmode = EFlightMode::Roaming
private

Definition at line 247 of file PIDDrone.h.

◆ InnerOverlapSensor

AOverlapSensor* APIDDrone::InnerOverlapSensor = nullptr
private

Definition at line 261 of file PIDDrone.h.

Referenced by ChangeDroneParameters(), and EndPlay().

◆ manualControl

bool APIDDrone::manualControl = false
private

Definition at line 271 of file PIDDrone.h.

◆ OnDroneFinished

FDroneFinished APIDDrone::OnDroneFinished

Definition at line 61 of file PIDDrone.h.

Referenced by SetFlightpath().

◆ passedWaypoints

int32 APIDDrone::passedWaypoints = 0
private

Definition at line 277 of file PIDDrone.h.

Referenced by GetCurrentWaypointTarget_Transform(), HandleDestroy(), and SetFlightpath().

◆ PositionMesh

UStaticMeshComponent* APIDDrone::PositionMesh = nullptr
private

Definition at line 258 of file PIDDrone.h.

Referenced by BeginPlay(), and SetFlightpath().

◆ ROSMessage

TSharedPtr<ROSMessages::std_msgs::Float32> APIDDrone::ROSMessage
protected

Definition at line 198 of file PIDDrone.h.

Referenced by BeginPlay(), EndPlay(), and UpdateGroundHeight().

◆ ROSTopic

UTopic* APIDDrone::ROSTopic = nullptr
protected

Definition at line 196 of file PIDDrone.h.

Referenced by CreateTopic(), DestroyTopic(), and UpdateGroundHeight().

◆ ShowForwardArrow

bool APIDDrone::ShowForwardArrow = false
private

Definition at line 273 of file PIDDrone.h.

◆ StartingPosition

FVector APIDDrone::StartingPosition
private

Definition at line 252 of file PIDDrone.h.

Referenced by BeginPlay().

◆ waypointReached

bool APIDDrone::waypointReached = false
private

Definition at line 269 of file PIDDrone.h.

Referenced by SetFlightpath().

◆ WayPoints

TArray<FVector> APIDDrone::WayPoints
private
Initial value:
= {
{3790, 8050, 5000},
{11779.536955,6566.541435,5000}
}

Definition at line 264 of file PIDDrone.h.

Referenced by AssignRoamingPoints().

◆ World

UWorld* APIDDrone::World = nullptr
private

Definition at line 250 of file PIDDrone.h.

Referenced by BeginPlay(), DrawDebugPoints(), HandleDestroy(), and UpdateGroundHeight().


The documentation for this class was generated from the following files: