Agrarsense
Public Member Functions | 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 SetDroneParameters (const FDroneParameters &InParameters)
 
void AddWayPoint (FVector Waypoint)
 
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...
 
virtual void SetCurrentTransformToMovedFromGarageTransform () override
 
void SetShowForwardArrow (bool Show)
 
bool GetShowForwardArrow () const
 
- Public Member Functions inherited from AVehicle
 AVehicle ()
 
virtual EVehicleTypes GetVehicleType () const
 
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
 
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)
 

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
 
FString ActorName
 
FString ActorID
 
FTransform OriginalCameraTransform
 
FTransform MovedFromGarageTransform
 
bool VehicleInGarage = false
 

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 AutoPilot (const float DeltaTime)
 
void AssignRoamingPoints (const TArray< FTransform > Points)
 
void SetDroneRotation (USkeletalMeshComponent *target, FRotator rotator)
 
void UpdateGroundHeight ()
 
bool IsRoaming () const
 
void SetDesiredLocationMesh (UStaticMeshComponent *meshcomponent)
 
FVector GetCurrentWaypointTarget ()
 

Private Attributes

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

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
 

Detailed Description

Definition at line 22 of file PIDDrone.h.

Constructor & Destructor Documentation

◆ APIDDrone()

APIDDrone::APIDDrone ( )

Definition at line 23 of file PIDDrone.cpp.

23 : Super()
24{
25 PrimaryActorTick.bCanEverTick = true;
26 InteractableName = NSLOCTEXT("Agrarsense", "DroneInteractableName", "Drone");
27}
FText InteractableName
Definition: Vehicle.h:258

References AVehicle::InteractableName.

Member Function Documentation

◆ AddWayPoint()

void APIDDrone::AddWayPoint ( FVector  Waypoint)
inline

Definition at line 88 of file PIDDrone.h.

89 {
90 FTransform transform;
91 transform.SetLocation(Waypoint);
92
93 DroneParameters.Points.Add(transform);
94 }
FDroneParameters DroneParameters
Definition: PIDDrone.h:201
TArray< FTransform > Points

References FDroneParameters::Points.

◆ AssignRoamingPoints()

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

Definition at line 185 of file PIDDrone.cpp.

186{
188
189 for (const FTransform& point : Points)
190 {
191 WayPoints.Add(point.GetLocation());
192 }
193}
TArray< FVector > WayPoints
Definition: PIDDrone.h:218
void ClearWaypoints()
Definition: PIDDrone.h:97

References ClearWaypoints(), and WayPoints.

◆ AutoPilot()

void APIDDrone::AutoPilot ( const float  DeltaTime)
private

Definition at line 80 of file PIDDrone.cpp.

81{
83 {
84 return;
85 }
86
88}
void SetFlightpath()
Called in tick function for drone roaming through points.
Definition: PIDDrone.cpp:90
EDroneAction DroneAction

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

Referenced by Tick().

◆ BeginPlay()

void APIDDrone::BeginPlay ( )
overrideprivatevirtual

Reimplemented from AVehicle.

Definition at line 29 of file PIDDrone.cpp.

30{
31 Super::BeginPlay();
32
33 World = GetWorld();
34
35 ROSMessage.Reset();
36 ROSMessage = MakeShared<ROSMessages::std_msgs::Float32>();
37
39
40 DroneSkeletalMesh = Cast<USkeletalMeshComponent>(GetComponentByClass(USkeletalMeshComponent::StaticClass()));
41
42 PositionMesh = Cast<UStaticMeshComponent>(GetComponentByClass(UStaticMeshComponent::StaticClass()));
43
44 StartingPosition = GetActorLocation();
45
46
48 {
49 // Create Transform sensor for forwarder and harvester
51 Params.SaveTransformDataToDisk = true;
52 Params.OwningActor = this;
53 Params.UseOwningActorTransform = false;
54 Params.PrimitiveComponent = Cast<UPrimitiveComponent>(DroneSkeletalMesh);
55
56 FString VehicleTransformSensorID = ActorID + "/transform";
57 TransformSensor = USensorFactory::SpawnTransformSensor(GetActorTransform(), Params, VehicleTransformSensorID, "transform", true, this);
58 }
59}
TSharedPtr< ROSMessages::std_msgs::Float32 > ROSMessage
Definition: PIDDrone.h:162
void CreateTopic()
Definition: PIDDrone.cpp:318
UWorld * World
Definition: PIDDrone.h:207
FVector StartingPosition
Definition: PIDDrone.h:209
UStaticMeshComponent * PositionMesh
Definition: PIDDrone.h:215
USkeletalMeshComponent * DroneSkeletalMesh
Definition: PIDDrone.h:212
FString ActorID
Definition: Vehicle.h:300
ATransformSensor * TransformSensor
Definition: Vehicle.h:288
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, CreateTopic(), DroneSkeletalMesh, FTransformSensorParameters::OwningActor, PositionMesh, FTransformSensorParameters::PrimitiveComponent, ROSMessage, FTransformSensorParameters::SaveTransformDataToDisk, USensorFactory::SpawnTransformSensor(), StartingPosition, AVehicle::TransformSensor, FTransformSensorParameters::UseOwningActorTransform, and World.

◆ ChangeDroneParameters()

void APIDDrone::ChangeDroneParameters ( const FDroneParameters newParameters)
inline

Definition at line 74 of file PIDDrone.h.

75 {
76#if WITH_EDITOR
77 UE_LOG(LogTemp, Warning, TEXT("Parameters Changed!"));
78#endif
79 SetDroneParameters(newParameters);
80 }
void SetDroneParameters(const FDroneParameters &InParameters)
Definition: PIDDrone.h:82

Referenced by USimulatorJsonParser::ParseAndSetDroneParameters().

◆ ClearWaypoints()

void APIDDrone::ClearWaypoints ( )
inline

Definition at line 97 of file PIDDrone.h.

98 {
99 DroneParameters.Points.Empty();
100 }

Referenced by AssignRoamingPoints().

◆ CreateTopic()

void APIDDrone::CreateTopic ( )
private

Definition at line 318 of file PIDDrone.cpp.

319{
320 if (ROSTopic)
321 {
322 return;
323 }
324
325 UROSIntegrationGameInstance* ROSInstance = UAgrarsenseStatics::GetROSGameInstance(GetWorld());
326 if (ROSInstance && ROSInstance->IsROSConnected())
327 {
328 ROSTopic = NewObject<UTopic>(UTopic::StaticClass());
329 if (ROSTopic)
330 {
331
332 FString TopicName = FString::Printf(TEXT("/agrarsense/out/vehicles/%s/height"), *GetActorID_Implementation());
333 //UE_LOG(LogTemp, Warning, TEXT("TopicName is %s"), *TopicName);
334
335 ROSTopic->Init(ROSInstance->ROSIntegrationCore, TopicName, "std_msgs/Float32");
336 ROSTopic->Advertise();
337 }
338 }
339}
UTopic * ROSTopic
Definition: PIDDrone.h:160
virtual FString GetActorID_Implementation() const override
Definition: Vehicle.h:195
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 341 of file PIDDrone.cpp.

342{
343 if (ROSTopic)
344 {
345 ROSTopic->Unadvertise();
346 ROSTopic->Unsubscribe();
347 ROSTopic->MarkAsDisconnected();
348 ROSTopic->ConditionalBeginDestroy();
349 ROSTopic = nullptr;
350 }
351}

References ROSTopic.

Referenced by EndPlay(), and ROSBridgeStateChanged().

◆ EndPlay()

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

Reimplemented from AVehicle.

Definition at line 61 of file PIDDrone.cpp.

62{
63 Super::EndPlay(EndPlayReason);
64
65 ROSMessage.Reset();
67}
void DestroyTopic()
Definition: PIDDrone.cpp:341

References DestroyTopic(), and ROSMessage.

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

281{
282 TArray<FTransform> generatedRoamingPoints;
283 generatedRoamingPoints.Reserve(roamingPoints);
284
285 FVector currentPosition = this->GetTransform().GetLocation();
286
287 FVector min = currentPosition - FVector(radius / 2, radius / 2, 0);
288 FVector max = currentPosition + FVector(radius / 2, radius / 2, 0);
289
290 for (int32 i = 0; i < roamingPoints; i++)
291 {
292 FTransform randomPoint;
293 randomPoint.SetLocation(FVector(FMath::RandRange(min.X, max.X), FMath::RandRange(min.Y, max.Y), 5000));
294
295 generatedRoamingPoints.Add(randomPoint);
296#if WITH_EDITOR
297 UE_LOG(LogTemp, Warning, TEXT("Waypoint %i: (%s)"), i, *randomPoint.GetLocation().ToString());
298#endif
299 }
300
301 return generatedRoamingPoints;
302}

Referenced by SetFlightpath().

◆ GetCurrentWaypointTarget()

FVector APIDDrone::GetCurrentWaypointTarget ( )
private

Definition at line 174 of file PIDDrone.cpp.

175{
176 // UE_LOG(LogTemp, Warning, TEXT(" % s"), *DroneParameters.Points[passedWaypoints].GetLocation().ToString());
178 {
179 return FVector(0, 0, 0);
180 }
181
182 return DroneParameters.Points[passedWaypoints].GetLocation();
183}
int32 passedWaypoints
Definition: PIDDrone.h:229

References DroneParameters, passedWaypoints, and FDroneParameters::Points.

Referenced by SetFlightpath().

◆ GetDroneAction()

EDroneAction APIDDrone::GetDroneAction ( ) const
inline

Get drone's action (roaming, manual)

Returns
Drone's action

Definition at line 62 of file PIDDrone.h.

63 {
65 }

◆ GetDroneParameters()

FDroneParameters APIDDrone::GetDroneParameters ( ) const
inline

Definition at line 68 of file PIDDrone.h.

69 {
70 return DroneParameters;
71 }

Referenced by USimulatorJsonExporter::SetDroneParameters().

◆ GetInteractableWorldTransform_Implementation()

virtual FTransform APIDDrone::GetInteractableWorldTransform_Implementation ( ) const
inlineoverridevirtual

Reimplemented from AVehicle.

Definition at line 36 of file PIDDrone.h.

37 {
39 {
40 return DroneSkeletalMesh->GetComponentTransform();
41 }
42 else
43 {
44 return GetActorTransform();
45 }
46 }

◆ GetShowForwardArrow()

bool APIDDrone::GetShowForwardArrow ( ) const
inline

Definition at line 150 of file PIDDrone.h.

151 {
152 return ShowForwardArrow;
153 }
bool ShowForwardArrow
Definition: PIDDrone.h:227

◆ GetVehicleType()

virtual EVehicleTypes APIDDrone::GetVehicleType ( ) const
inlineoverridevirtual

Get type of the Vehicle

Returns
Vehicle's type

Reimplemented from AVehicle.

Definition at line 34 of file PIDDrone.h.

References Drone.

◆ IsRoaming()

bool APIDDrone::IsRoaming ( ) const
inlineprivate

Definition at line 187 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 161 of file PIDDrone.cpp.

162{
163 if (DroneParameters.Points.Num() > 0)
164 {
165 DroneParameters.Points.Empty();
167 }
168 else
169 {
171 }
172}

References DroneParameters, FDroneParameters::Points, and Transform.

◆ ROSBridgeStateChanged()

void APIDDrone::ROSBridgeStateChanged ( EROSState  ROSState)
overrideprotectedvirtual

Reimplemented from AVehicle.

Definition at line 304 of file PIDDrone.cpp.

305{
306 switch (ROSState)
307 {
309 CreateTopic();
310 break;
311
313 DestroyTopic();
314 break;
315 }
316}

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

◆ SetCurrentTransformToMovedFromGarageTransform()

virtual void APIDDrone::SetCurrentTransformToMovedFromGarageTransform ( )
inlineoverridevirtual

Reimplemented from AVehicle.

Definition at line 128 of file PIDDrone.h.

129 {
131 {
132 MovedFromGarageTransform = DroneSkeletalMesh->GetComponentTransform();
133 UE_LOG(LogTemp, Warning, TEXT("Moved from garage transform %s"), *MovedFromGarageTransform.ToString());
134
135 }
136 else
137 {
138 MovedFromGarageTransform = GetActorTransform();
139 UE_LOG(LogTemp, Warning, TEXT("ACTOR Moved from garage transform WHAT IS THIS: %s"), *MovedFromGarageTransform.ToString());
140
141 }
142 }
FTransform MovedFromGarageTransform
Definition: Vehicle.h:305

◆ SetDesiredLocationMesh()

void APIDDrone::SetDesiredLocationMesh ( UStaticMeshComponent *  meshcomponent)
inlineprivate

Definition at line 193 of file PIDDrone.h.

194 {
195 PositionMesh = meshcomponent;
196 }

◆ SetDroneAction()

void APIDDrone::SetDroneAction ( EDroneAction  mode)
inline

Set drone's action (roaming, manual)

Definition at line 52 of file PIDDrone.h.

53 {
55 }

◆ SetDroneParameters()

void APIDDrone::SetDroneParameters ( const FDroneParameters InParameters)
inline

Definition at line 82 of file PIDDrone.h.

83 {
84 DroneParameters = InParameters;
85 }

◆ SetDroneRotation()

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

Definition at line 195 of file PIDDrone.cpp.

196{
197 if (!target)
198 {
199 return;
200 }
201
202 FRotator currentRotation = target->GetRelativeRotation();
203 FRotator rotationDifference = rotator - currentRotation;
204
205 target->AddRelativeRotation(rotationDifference, false, nullptr, ETeleportType::TeleportPhysics);
206
207 // Prevent locking up when using interp
208 if (FMath::Abs(rotator.Pitch) < 0.001f)
209 {
210 rotator.Pitch = 0.0f;
211 }
212 if (FMath::Abs(rotator.Yaw) < 0.001f)
213 {
214 rotator.Yaw = 0.0f;
215 }
216 if (FMath::Abs(rotator.Roll) < 0.001f)
217 {
218 rotator.Roll = 0.0f;
219 }
220
221 // Corrected rotation
222 target->SetRelativeRotation(rotator, false, nullptr, ETeleportType::TeleportPhysics);
223}

◆ SetFlightpath()

void APIDDrone::SetFlightpath ( )

Called in tick function for drone roaming through points.

Definition at line 90 of file PIDDrone.cpp.

91{
92 // TODO: Check if in garage
93 // include drone rotation to point
94
95 // Don't try to fly if no waypoints
96 if (DroneParameters.Points.Num() == 0 && IsRoaming())
97 {
99 }
100
101 FVector waypoint = GetCurrentWaypointTarget();
102 FVector currentlocation = DroneSkeletalMesh->GetRelativeTransform().GetLocation();
103
104 if (PositionMesh)
105 {
106 // Doesn't work
107 PositionMesh->SetWorldLocation(waypoint);
108 }
109#if WITH_EDITOR
110 else
111 {
112 UE_LOG(LogTemp, Warning, TEXT("Desired location mesh not found"));
113 //DrawDebugLine(World, currentlocation, waypoint, FColor::Red, false, 0.0f, 0.0f, 5.0f);
114 }
115#endif
116
117 if (FVector2f::Distance(FVector2f(waypoint.X, waypoint.Y), FVector2f(currentlocation.X, currentlocation.Y)) < 1000)
118 {
119 waypointReached = true;
120 if (passedWaypoints != DroneParameters.Points.Num() - 1)
121 {
122#if WITH_EDITOR
123 UE_LOG(LogTemp, Warning, TEXT("Changing waypoint from %i to %i"), passedWaypoints, passedWaypoints + 1);
124#endif
125
127 }
128 else
129 {
131 {
133 passedWaypoints = 0;
134 }
135 else
136 {
138 {
141 break;
144 passedWaypoints = 0;
145 break;
147 passedWaypoints = 0;
148 break;
150 Algo::Reverse(DroneParameters.Points);
151 passedWaypoints = 0;
152 break;
153 default:
154 break;
155 }
156 }
157 }
158 }
159}
bool waypointReached
Definition: PIDDrone.h:223
FVector GetCurrentWaypointTarget()
Definition: PIDDrone.cpp:174
bool IsRoaming() const
Definition: PIDDrone.h:187
TArray< FTransform > GenerateRoamingPoints(float radius, int32 roamingPoints)
Generates a roadming points array for the drone in radius.
Definition: PIDDrone.cpp:280
EDroneEndAction DroneEndAction

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

Referenced by AutoPilot().

◆ SetManualControl()

void APIDDrone::SetManualControl ( bool  value)
inline

Definition at line 109 of file PIDDrone.h.

110 {
111 manualControl = value;
112 }
bool manualControl
Definition: PIDDrone.h:225

◆ SetShowForwardArrow()

void APIDDrone::SetShowForwardArrow ( bool  Show)
inline

Definition at line 144 of file PIDDrone.h.

145 {
146 ShowForwardArrow = Show;
147 }

Referenced by USimulatorJsonParser::ParseAndSetDroneParameters().

◆ Tick()

void APIDDrone::Tick ( float  DeltaTime)
overrideprivatevirtual

Definition at line 69 of file PIDDrone.cpp.

70{
71 Super::Tick(DeltaTime);
72
73 if (!IsVehicleInGarage())
74 {
75 AutoPilot(DeltaTime);
77 }
78}
void AutoPilot(const float DeltaTime)
Definition: PIDDrone.cpp:80
void UpdateGroundHeight()
Definition: PIDDrone.cpp:225
bool IsVehicleInGarage() const
Definition: Vehicle.h:124

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

◆ UpdateGroundHeight()

void APIDDrone::UpdateGroundHeight ( )
private

Definition at line 225 of file PIDDrone.cpp.

226{
227 if (!DroneSkeletalMesh || !ROSTopic || !ROSMessage.IsValid())
228 {
229 return;
230 }
231
232 FVector Start = DroneSkeletalMesh->GetComponentLocation();
233 FVector End = Start - FVector(0, 0, 10000.0f);
234
235 FCollisionQueryParams TraceParams = FCollisionQueryParams(FName(TEXT("UpdateGroundHeight")), true, this);
236 TraceParams.bReturnPhysicalMaterial = false;
237 TraceParams.bTraceComplex = false;
238
239 FHitResult HitResult;
240
241#ifdef ParallelLineTraceSingleByChannel_EXISTS
242 // Defined and implemented in our AGRARSENSE Unreal Engine fork
243 // This LineTrace method doesn't block the physics scene which improves linetrace performance.
244 World->ParallelLineTraceSingleByChannel(
245 HitResult,
246 Start,
247 End,
248 ECC_Visibility,
249 TraceParams,
250 FCollisionResponseParams::DefaultResponseParam);
251#else
252 // If not using our fork of the engine, use default LineTrace method.
253 World->LineTraceSingleByChannel(
254 HitResult,
255 Start,
256 End,
257 ECC_Visibility,
258 TraceParams,
259 FCollisionResponseParams::DefaultResponseParam);
260#endif
261
262 if (HitResult.IsValidBlockingHit())
263 {
264 float Height = (Start.Z - HitResult.ImpactPoint.Z) / 100.0f;
265 float HeightRounded = FMath::RoundToFloat(Height * 1000.0f) / 1000.0f;
266
267 if (!FMath::IsNearlyEqual(DroneHeightFromGround, HeightRounded, 0.005f))
268 {
269 DroneHeightFromGround = HeightRounded;
270
272 ROSTopic->Publish(ROSMessage);
273
274 //FString HitActorName = HitResult.GetActor() ? HitResult.GetActor()->GetName() : TEXT("None");
275 //UE_LOG(LogTemp, Log, TEXT("Drone is %f meters above ground. Hit object: %s"), DroneHeightFromGround, *HitActorName);
276 }
277 }
278}
float DroneHeightFromGround
Definition: PIDDrone.h:231

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

Referenced by Tick().

Member Data Documentation

◆ DroneHeightFromGround

float APIDDrone::DroneHeightFromGround = 0.0f
private

Definition at line 231 of file PIDDrone.h.

Referenced by UpdateGroundHeight().

◆ DroneParameters

FDroneParameters APIDDrone::DroneParameters
private

◆ DroneSkeletalMesh

USkeletalMeshComponent* APIDDrone::DroneSkeletalMesh = nullptr
private

Definition at line 212 of file PIDDrone.h.

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

◆ flightmode

EFlightMode APIDDrone::flightmode = EFlightMode::Roaming
private

Definition at line 204 of file PIDDrone.h.

◆ manualControl

bool APIDDrone::manualControl = false
private

Definition at line 225 of file PIDDrone.h.

◆ passedWaypoints

int32 APIDDrone::passedWaypoints = 0
private

Definition at line 229 of file PIDDrone.h.

Referenced by GetCurrentWaypointTarget(), and SetFlightpath().

◆ PositionMesh

UStaticMeshComponent* APIDDrone::PositionMesh = nullptr
private

Definition at line 215 of file PIDDrone.h.

Referenced by BeginPlay(), and SetFlightpath().

◆ ROSMessage

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

Definition at line 162 of file PIDDrone.h.

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

◆ ROSTopic

UTopic* APIDDrone::ROSTopic = nullptr
protected

Definition at line 160 of file PIDDrone.h.

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

◆ ShowForwardArrow

bool APIDDrone::ShowForwardArrow = false
private

Definition at line 227 of file PIDDrone.h.

◆ StartingPosition

FVector APIDDrone::StartingPosition
private

Definition at line 209 of file PIDDrone.h.

Referenced by BeginPlay().

◆ waypointReached

bool APIDDrone::waypointReached = false
private

Definition at line 223 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 218 of file PIDDrone.h.

Referenced by AssignRoamingPoints().

◆ World

UWorld* APIDDrone::World = nullptr
private

Definition at line 207 of file PIDDrone.h.

Referenced by BeginPlay(), and UpdateGroundHeight().


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