Agrarsense
Public Member Functions | 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 SetDroneParameters (const FDroneParameters &InParameters)
 
void AddWayPoint (FVector Waypoint)
 
void ClearWaypoints ()
 
void FlySetFlightpath ()
 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...
 
virtual void SetCurrentTransformToMovedFromGarageTransform () override
 
- Public Member Functions inherited from AVehicle
 AVehicle ()
 
virtual EVehicleTypes GetVehicleType () const
 
virtual FString GetTopicName ()
 
void TogglePhysics (bool isOn)
 
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
 
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)
 

Private Member Functions

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

Private Attributes

FDroneParameters DroneParameters
 
EFlightMode flightmode = EFlightMode::Roaming
 
UWorld * World = nullptr
 
FVector StartingPosition
 
USkeletalMeshComponent * mesh = nullptr
 
UStaticMeshComponent * desiredPositionMesh = nullptr
 
bool waypointReached = false
 
bool manualControl = false
 
TArray< FVector > WayPoints
 
int32 passedWaypoints = 0
 

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 ()
 
- Public Attributes inherited from AVehicle
FText InteractableName
 
FVehicleGarageChangedDelegate OnVehicleGarageChanged
 
virtual void BeginPlay () override
 
virtual void EndPlay (const EEndPlayReason::Type EndPlayReason) override
 
- Protected Attributes inherited from AVehicle
TObjectPtr< USensorsManagerComponent > SensorsManager
 
ACollisionSensorCollisionSensor = nullptr
 
ATransformSensorTransformSensor = nullptr
 
AOverlapSensorOverlapSensor = nullptr
 
UNiagaraComponent * NiagaraComponent = nullptr
 
FString ActorName
 
FString ActorID
 
FTransform OriginalCameraTransform
 
FTransform MovedFromGarageTransform
 
bool VehicleInGarage = false
 

Detailed Description

Definition at line 17 of file PIDDrone.h.

Constructor & Destructor Documentation

◆ APIDDrone()

APIDDrone::APIDDrone ( )

Definition at line 20 of file PIDDrone.cpp.

20 : Super()
21{
22 PrimaryActorTick.bCanEverTick = true;
23 InteractableName = NSLOCTEXT("Agrarsense", "DroneInteractableName", "Drone");
24}
FText InteractableName
Definition: Vehicle.h:241

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:170
TArray< FTransform > Points

References FDroneParameters::Points.

◆ AssignRoamingPoints()

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

Definition at line 148 of file PIDDrone.cpp.

149{
150 // Empty current waypoints if any
152
153 for (const FTransform& point : Points)
154 {
155 // Assing new waypoints to the array
156 WayPoints.Add(point.GetLocation());
157 }
158}
TArray< FVector > WayPoints
Definition: PIDDrone.h:187
void ClearWaypoints()
Definition: PIDDrone.h:92

References ClearWaypoints(), and WayPoints.

◆ AutoPilot()

void APIDDrone::AutoPilot ( float  DeltaTime)
private

Definition at line 219 of file PIDDrone.cpp.

220{
222 {
223 return;
224 }
225
227}
void FlySetFlightpath()
Called in tick function for drone roaming through points.
Definition: PIDDrone.cpp:53
EDroneAction DroneAction

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

Referenced by Tick().

◆ BeginPlay()

void APIDDrone::BeginPlay ( )
overrideprivatevirtual

Reimplemented from AVehicle.

Definition at line 26 of file PIDDrone.cpp.

27{
28 Super::BeginPlay();
29
30 World = GetWorld();
31
32 mesh = Cast<USkeletalMeshComponent>(GetComponentByClass(USkeletalMeshComponent::StaticClass()));
33 desiredPositionMesh = Cast<UStaticMeshComponent>(GetComponentByClass(UStaticMeshComponent::StaticClass()));
34
35 StartingPosition = GetActorLocation();
36}
UWorld * World
Definition: PIDDrone.h:176
FVector StartingPosition
Definition: PIDDrone.h:178
UStaticMeshComponent * desiredPositionMesh
Definition: PIDDrone.h:181
USkeletalMeshComponent * mesh
Definition: PIDDrone.h:180

References desiredPositionMesh, mesh, StartingPosition, and World.

◆ ChangeDroneParameters()

void APIDDrone::ChangeDroneParameters ( const FDroneParameters newParameters)
inline

Definition at line 69 of file PIDDrone.h.

70 {
71#if WITH_EDITOR
72 UE_LOG(LogTemp, Warning, TEXT("Parameters Changed!"));
73#endif
74 SetDroneParameters(newParameters);
75 }
void SetDroneParameters(const FDroneParameters &InParameters)
Definition: PIDDrone.h:77

Referenced by USimulatorJsonParser::ParseAndSetDroneParameters().

◆ ClearWaypoints()

void APIDDrone::ClearWaypoints ( )
inline

Definition at line 92 of file PIDDrone.h.

93 {
94 DroneParameters.Points.Empty();
95 }

Referenced by AssignRoamingPoints().

◆ EndPlay()

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

Reimplemented from AVehicle.

Definition at line 38 of file PIDDrone.cpp.

39{
40 Super::EndPlay(EndPlayReason);
41}

◆ FlySetFlightpath()

void APIDDrone::FlySetFlightpath ( )

Called in tick function for drone roaming through points.

Definition at line 53 of file PIDDrone.cpp.

54{
55 // TODO: Check if in garage
56 // include drone rotation to point
57
58 // Don't try to fly if no waypoints
59 if (DroneParameters.Points.Num() == 0 && IsRoaming())
60 {
62 }
63
64 FVector waypoint = GetCurrentWaypointTarget();
65 FVector currentlocation = mesh->GetRelativeTransform().GetLocation();
66
68 {
69 // Doesn't work
70 desiredPositionMesh->SetWorldLocation(waypoint);
71 }
72#if WITH_EDITOR
73 else
74 {
75 UE_LOG(LogTemp, Warning, TEXT("Desired location mesh not found"));
76 //DrawDebugLine(World, currentlocation, waypoint, FColor::Red, false, 0.0f, 0.0f, 5.0f);
77 }
78#endif
79
80 if (FVector2f::Distance(FVector2f(waypoint.X, waypoint.Y), FVector2f(currentlocation.X, currentlocation.Y)) < 1000)
81 {
82 waypointReached = true;
83 if (passedWaypoints != DroneParameters.Points.Num() - 1)
84 {
85#if WITH_EDITOR
86 UE_LOG(LogTemp, Warning, TEXT("Changing waypoint from %i to %i"), passedWaypoints, passedWaypoints + 1);
87#endif
88
90 }
91 else
92 {
94 {
97 }
98 else
99 {
101 {
104 break;
107 passedWaypoints = 0;
108 break;
110 passedWaypoints = 0;
111 break;
113 Algo::Reverse(DroneParameters.Points);
114 passedWaypoints = 0;
115 break;
116 default:
117 break;
118 }
119 }
120 }
121 }
122}
bool waypointReached
Definition: PIDDrone.h:183
FVector GetCurrentWaypointTarget()
Definition: PIDDrone.cpp:137
int32 passedWaypoints
Definition: PIDDrone.h:192
bool IsRoaming() const
Definition: PIDDrone.h:150
TArray< FTransform > GenerateRoamingPoints(float radius, int32 roamingPoints)
Generates a roadming points array for the drone in radius.
Definition: PIDDrone.cpp:195
EDroneEndAction DroneEndAction

References desiredPositionMesh, FDroneParameters::DroneAction, FDroneParameters::DroneEndAction, DroneParameters, GenerateRandomNew, GenerateRoamingPoints(), GetCurrentWaypointTarget(), GoBackwards, IsRoaming(), mesh, passedWaypoints, FDroneParameters::Points, RepeatFromBeginning, Roaming, Stationary, Stop, and waypointReached.

Referenced by AutoPilot().

◆ 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 195 of file PIDDrone.cpp.

196{
197 TArray<FTransform> generatedRoamingPoints;
198 generatedRoamingPoints.Reserve(roamingPoints);
199
200 FVector currentPosition = this->GetTransform().GetLocation();
201
202 FVector min = currentPosition - FVector(radius / 2, radius / 2, 0);
203 FVector max = currentPosition + FVector(radius / 2, radius / 2, 0);
204
205 for (int32 i = 0; i < roamingPoints; i++)
206 {
207 FTransform randomPoint;
208 randomPoint.SetLocation(FVector(FMath::RandRange(min.X, max.X), FMath::RandRange(min.Y, max.Y), 5000));
209
210 generatedRoamingPoints.Add(randomPoint);
211#if WITH_EDITOR
212 UE_LOG(LogTemp, Warning, TEXT("Waypoint %i: (%s)"), i, *randomPoint.GetLocation().ToString());
213#endif
214 }
215
216 return generatedRoamingPoints;
217}

Referenced by FlySetFlightpath().

◆ GetCurrentWaypointTarget()

FVector APIDDrone::GetCurrentWaypointTarget ( )
private

Definition at line 137 of file PIDDrone.cpp.

138{
139 // UE_LOG(LogTemp, Warning, TEXT(" % s"), *DroneParameters.Points[passedWaypoints].GetLocation().ToString());
141 {
142 return FVector(0, 0, 0);
143 }
144
145 return DroneParameters.Points[passedWaypoints].GetLocation();
146}

References DroneParameters, passedWaypoints, and FDroneParameters::Points.

Referenced by FlySetFlightpath().

◆ GetDroneAction()

EDroneAction APIDDrone::GetDroneAction ( ) const
inline

Get drone's action (roaming, manual)

Returns
Drone's action

Definition at line 57 of file PIDDrone.h.

58 {
60 }

◆ GetDroneParameters()

FDroneParameters APIDDrone::GetDroneParameters ( ) const
inline

Definition at line 63 of file PIDDrone.h.

64 {
65 return DroneParameters;
66 }

Referenced by USimulatorJsonExporter::SetDroneParameters().

◆ GetInteractableWorldTransform_Implementation()

virtual FTransform APIDDrone::GetInteractableWorldTransform_Implementation ( ) const
inlineoverridevirtual

Reimplemented from AVehicle.

Definition at line 31 of file PIDDrone.h.

32 {
33 if (mesh)
34 {
35 return mesh->GetComponentTransform();
36 }
37 else
38 {
39 return GetActorTransform();
40 }
41 }

◆ GetVehicleType()

virtual EVehicleTypes APIDDrone::GetVehicleType ( ) const
inlineoverridevirtual

Get type of the Vehicle

Returns
Vehicle's type

Reimplemented from AVehicle.

Definition at line 29 of file PIDDrone.h.

References Drone.

◆ IsRoaming()

bool APIDDrone::IsRoaming ( ) const
inlineprivate

Definition at line 150 of file PIDDrone.h.

References Roaming.

Referenced by FlySetFlightpath().

◆ MoveDroneToPosition()

void APIDDrone::MoveDroneToPosition ( const FTransform  Transform)

Override all drone roaming points and continue towards this position.

Parameters
Transformdrone move position

Definition at line 124 of file PIDDrone.cpp.

125{
126 if (DroneParameters.Points.Num() > 0)
127 {
128 DroneParameters.Points.Empty();
130 }
131 else
132 {
134 }
135}

References DroneParameters, FDroneParameters::Points, and Transform.

◆ SetCurrentTransformToMovedFromGarageTransform()

virtual void APIDDrone::SetCurrentTransformToMovedFromGarageTransform ( )
inlineoverridevirtual

Reimplemented from AVehicle.

Definition at line 123 of file PIDDrone.h.

124 {
125 if (mesh)
126 {
127 MovedFromGarageTransform = mesh->GetComponentTransform();
128 UE_LOG(LogTemp, Warning, TEXT("Moved from garage transform %s"), *MovedFromGarageTransform.ToString());
129
130 }
131 else
132 {
133 MovedFromGarageTransform = GetActorTransform();
134 UE_LOG(LogTemp, Warning, TEXT("ACTOR Moved from garage transform WHAT IS THIS: %s"), *MovedFromGarageTransform.ToString());
135
136 }
137 }
FTransform MovedFromGarageTransform
Definition: Vehicle.h:280

◆ SetDesiredLocationMesh()

void APIDDrone::SetDesiredLocationMesh ( UStaticMeshComponent *  meshcomponent)
inlineprivate

Definition at line 156 of file PIDDrone.h.

157 {
158 desiredPositionMesh = meshcomponent;
159 }

◆ SetDroneAction()

void APIDDrone::SetDroneAction ( EDroneAction  mode)
inline

Set drone's action (roaming, manual)

Definition at line 47 of file PIDDrone.h.

48 {
50 }

◆ SetDroneParameters()

void APIDDrone::SetDroneParameters ( const FDroneParameters InParameters)
inline

Definition at line 77 of file PIDDrone.h.

78 {
79 DroneParameters = InParameters;
80 }

◆ SetDroneRotation()

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

Definition at line 160 of file PIDDrone.cpp.

161{
162 if (!target)
163 {
164 return;
165 }
166
167 FRotator rotation = FRotator(
168 FMath::Clamp(rotator.Pitch, -2, 2),
169 FMath::Clamp(rotator.Yaw, -2, 2),
170 FMath::Clamp(rotator.Roll, -2, 2));
171
172 FRotator currentRotation = target->GetRelativeRotation();
173
174 FRotator rotationDifference = currentRotation - rotator;
175
176 if (FMath::Abs(rotator.Pitch) > 0 && FMath::Abs(currentRotation.Pitch) < FMath::Abs(rotationDifference.Pitch))
177 {
178 target->AddRelativeRotation(FRotator(rotation.Pitch, 0, 0), false, nullptr, ETeleportType::TeleportPhysics);
179 }
180 if (FMath::Abs(rotator.Yaw) > 0 && FMath::Abs(currentRotation.Yaw) < FMath::Abs(rotationDifference.Yaw))
181 {
182 target->AddRelativeRotation(FRotator(0, rotation.Yaw, 0), false, nullptr, ETeleportType::TeleportPhysics);
183 }
184 if (FMath::Abs(rotator.Roll) > 0 && FMath::Abs(currentRotation.Roll) < FMath::Abs(rotationDifference.Roll))
185 {
186 target->AddRelativeRotation(FRotator(0, 0, rotation.Roll), false, nullptr, ETeleportType::TeleportPhysics);
187 }
188
189 if (rotator.Pitch == 0 || rotator.Yaw == 0 || rotator.Roll == 0)
190 {
191 target->AddRelativeRotation(FRotator(-FMath::Clamp(rotationDifference.Pitch, -2, 2), -FMath::Clamp(rotationDifference.Yaw, -2, 2), -FMath::Clamp(rotationDifference.Roll, -2, 2)), false, nullptr, ETeleportType::TeleportPhysics);
192 }
193}

◆ SetManualControl()

void APIDDrone::SetManualControl ( bool  value)
inline

Definition at line 104 of file PIDDrone.h.

105 {
106 manualControl = value;
107 }
bool manualControl
Definition: PIDDrone.h:184

◆ Tick()

void APIDDrone::Tick ( float  DeltaTime)
overrideprivatevirtual

Definition at line 43 of file PIDDrone.cpp.

44{
45 Super::Tick(DeltaTime);
46
47 if (!IsVehicleInGarage())
48 {
49 AutoPilot(DeltaTime);
50 }
51}
void AutoPilot(float DeltaTime)
Definition: PIDDrone.cpp:219
bool IsVehicleInGarage() const
Definition: Vehicle.h:131

References AutoPilot(), and AVehicle::IsVehicleInGarage().

Member Data Documentation

◆ desiredPositionMesh

UStaticMeshComponent* APIDDrone::desiredPositionMesh = nullptr
private

Definition at line 181 of file PIDDrone.h.

Referenced by BeginPlay(), and FlySetFlightpath().

◆ DroneParameters

FDroneParameters APIDDrone::DroneParameters
private

◆ flightmode

EFlightMode APIDDrone::flightmode = EFlightMode::Roaming
private

Definition at line 173 of file PIDDrone.h.

◆ manualControl

bool APIDDrone::manualControl = false
private

Definition at line 184 of file PIDDrone.h.

◆ mesh

USkeletalMeshComponent* APIDDrone::mesh = nullptr
private

Definition at line 180 of file PIDDrone.h.

Referenced by BeginPlay(), and FlySetFlightpath().

◆ passedWaypoints

int32 APIDDrone::passedWaypoints = 0
private

Definition at line 192 of file PIDDrone.h.

Referenced by FlySetFlightpath(), and GetCurrentWaypointTarget().

◆ StartingPosition

FVector APIDDrone::StartingPosition
private

Definition at line 178 of file PIDDrone.h.

Referenced by BeginPlay().

◆ waypointReached

bool APIDDrone::waypointReached = false
private

Definition at line 183 of file PIDDrone.h.

Referenced by FlySetFlightpath().

◆ WayPoints

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

Definition at line 187 of file PIDDrone.h.

Referenced by AssignRoamingPoints().

◆ World

UWorld* APIDDrone::World = nullptr
private

Definition at line 176 of file PIDDrone.h.

Referenced by BeginPlay().


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