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

#include <Vehicle.h>

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

Public Member Functions

 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
 
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)
 

Public Attributes

FText InteractableName
 
FVehicleGarageChangedDelegate OnVehicleGarageChanged
 

Protected Member Functions

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

Protected Attributes

TObjectPtr< USensorsManagerComponent > SensorsManager
 
ACollisionSensorCollisionSensor = nullptr
 
ATransformSensorTransformSensor = nullptr
 
AOverlapSensorOverlapSensor = nullptr
 
UNiagaraComponent * NiagaraComponent = nullptr
 
FString ActorName
 
FString ActorID
 
FTransform OriginalCameraTransform
 

Private Attributes

bool VehicleInGarage = false
 
FTransform MovedFromGarageTransform
 

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 37 of file Vehicle.h.

Constructor & Destructor Documentation

◆ AVehicle()

AVehicle::AVehicle ( )

Definition at line 19 of file Vehicle.cpp.

20{
21 PrimaryActorTick.bCanEverTick = false;
22 SensorsManager = CreateDefaultSubobject<USensorsManagerComponent>(TEXT("SensorsManagerComp"));
23 InteractableName = NSLOCTEXT("Agrarsense", "VehicleInteractableName", "Vehicle");
24}
FText InteractableName
Definition: Vehicle.h:241
TObjectPtr< USensorsManagerComponent > SensorsManager
Definition: Vehicle.h:257

References InteractableName, and SensorsManager.

Member Function Documentation

◆ BeginPlay()

void AVehicle::BeginPlay ( )
overrideprotectedvirtual

Reimplemented in AForwarder, AHarvester, and APIDDrone.

Definition at line 26 of file Vehicle.cpp.

27{
28 Super::BeginPlay();
29
30 TogglePhysics(true);
31
32 // Spawn Transform and Collision sensors for each vehicle
33 FTransform transform = GetTransform();
34
35 // Create Collision sensor
36 FString VehicleCollisionSensorID = ActorID + "/collision";
37 CollisionSensor = USensorFactory::SpawnCollisionSensor(transform, this, VehicleCollisionSensorID, "collision", true);
38
39 // Create Transform sensor
40 FString VehicleTransformSensorID = ActorID + "/transform";
41 TransformSensor = USensorFactory::SpawnTransformSensor(transform, this, VehicleTransformSensorID, "transform", true);
42
43 float NiagaraComponentHeight = 500.0f;
44 float OverlapBoundsSize = 5000.0f;
45
47 {
48 // Adjust certain variables if vehicle is a drone
49 OverlapBoundsSize = 2500.0f;
50 NiagaraComponentHeight = 200.0f;
51 }
52
53 FVector RelativePosition = FVector(0.0f, 0.0f, 0.0f);
55 {
56 // TODO make better solution for this.
57 RelativePosition = FVector(150.0f, -120.0f, 250.0f);
58 }
59
60 // Create OverlapSensor
62 Params.OwningActor = this;
63 Params.Size = FVector(OverlapBoundsSize, OverlapBoundsSize, OverlapBoundsSize);
65 Params.RelativePosition = RelativePosition;
66 FString OverlapSensorID = ActorID + "/overlap";
67 OverlapSensor = USensorFactory::SpawnOverlapSensor(transform, Params, OverlapSensorID, "overlap");
68
69 // Load and setup rain/snow fall niagara system
70 UNiagaraSystem* NiagaraSystem = LoadObject<UNiagaraSystem>(nullptr, TEXT("/Game/Agrarsense/Particles/WaterAndSnow/NS_Particles.NS_Particles"));
71 if (NiagaraSystem)
72 {
73 NiagaraComponent = UNiagaraFunctionLibrary::SpawnSystemAttached(NiagaraSystem, this->GetRootComponent(),
74 FName("NiagaraEmitterSocketName"),
75 FVector(0.0, 0.0, NiagaraComponentHeight), FRotator::ZeroRotator, EAttachLocation::KeepRelativeOffset, true);
76 }
77}
ACollisionSensor * CollisionSensor
Definition: Vehicle.h:260
FString ActorID
Definition: Vehicle.h:275
AOverlapSensor * OverlapSensor
Definition: Vehicle.h:266
virtual EVehicleTypes GetVehicleType() const
Definition: Vehicle.h:50
void TogglePhysics(bool isOn)
ATransformSensor * TransformSensor
Definition: Vehicle.h:263
UNiagaraComponent * NiagaraComponent
Definition: Vehicle.h:269
static ATransformSensor * SpawnTransformSensor(const FTransform &transform, AActor *Owner, const FString sensorIdentifier, const FString sensorName, bool SimulateSensor=true)
static ACollisionSensor * SpawnCollisionSensor(const FTransform &transform, AActor *Owner, const FString sensorIdentifier, const FString sensorName, bool SimulateSensor=true)
static AOverlapSensor * SpawnOverlapSensor(const FTransform &transform, FOverlapSensorParameters Parameters, const FString sensorIdentifier, const FString sensorName)

References ActorID, CollisionSensor, Drone, Forwarder, GetVehicleType(), NiagaraComponent, OverlapSensor, FOverlapSensorParameters::OwningActor, FOverlapSensorParameters::RelativePosition, FOverlapSensorParameters::Size, USensorFactory::SpawnCollisionSensor(), USensorFactory::SpawnOverlapSensor(), USensorFactory::SpawnTransformSensor(), Sphere, TogglePhysics(), TransformSensor, and FOverlapSensorParameters::TriggerShape.

◆ EndPlay()

void AVehicle::EndPlay ( const EEndPlayReason::Type  EndPlayReason)
overrideprotectedvirtual

Reimplemented in AForwarder, AHarvester, and APIDDrone.

Definition at line 86 of file Vehicle.cpp.

87{
88 Super::EndPlay(EndPlayReason);
89
91 {
92 TransformSensor->Destroy();
93 TransformSensor = nullptr;
94 }
95
97 {
98 CollisionSensor->Destroy();
99 CollisionSensor = nullptr;
100 }
101
102 if (OverlapSensor)
103 {
104 OverlapSensor->Destroy();
105 OverlapSensor = nullptr;
106 }
107
108 // Destroy attached sensors when vehicle is destroyed
109 if (IsValid(SensorsManager) && EndPlayReason == EEndPlayReason::Destroyed)
110 {
111 SensorsManager->DestroyAllSensors();
112 }
113
115 {
116 NiagaraComponent->UnregisterComponent();
117 NiagaraComponent->DestroyComponent();
118 NiagaraComponent = nullptr;
119 }
120}

References CollisionSensor, NiagaraComponent, OverlapSensor, SensorsManager, and TransformSensor.

◆ ExportToJsonFile()

FString AVehicle::ExportToJsonFile ( const FString &  FileName)

Export the Vehicle and its sensors to a JSON file.

Parameters
FileNameThe name of the file without extension.
Returns
FString representing the saved JSON file path, or an empty string if the export fails.

Definition at line 135 of file Vehicle.cpp.

136{
137 bool OverrideTransform = IsVehicleInGarage();
138
139 FTransform TransformToUse = GetActorTransform();
140
141 if (OverrideTransform)
142 {
143 TransformToUse = MovedFromGarageTransform;
144 }
145
146 return USimulatorJsonExporter::ExportVehicleAndSensorsToJSON(FileName, this, OverrideTransform, TransformToUse);
147}
FTransform MovedFromGarageTransform
Definition: Vehicle.h:284
bool IsVehicleInGarage() const
Definition: Vehicle.h:131
static FString ExportVehicleAndSensorsToJSON(FString FileName, AVehicle *Vehicle, bool OverrideTransform=false, const FTransform &Transform=FTransform())

References USimulatorJsonExporter::ExportVehicleAndSensorsToJSON(), IsVehicleInGarage(), and MovedFromGarageTransform.

Referenced by UROSCommands::HandleExportSensors(), and UROSCommands::HandleExportVehicles().

◆ GetActorID_Implementation()

virtual FString AVehicle::GetActorID_Implementation ( ) const
inlineoverridevirtual

Definition at line 203 of file Vehicle.h.

204 {
205 return ActorID;
206 }

Referenced by AOverlapSensor::Init().

◆ GetActorInformation_Implementation()

virtual FString AVehicle::GetActorInformation_Implementation ( ) const
inlineoverridevirtual

Definition at line 213 of file Vehicle.h.

214 {
216 const FString ID = GetActorID_Implementation();
217 const FString Name = GetActorName_Implementation();
218 const FTransform VehicleTransform = GetActorTransform();
219 const FVector Location = VehicleTransform.GetLocation();
220 const FRotator Rotation = VehicleTransform.Rotator();
221 FString Information = FString::Printf(TEXT("Vehicle: %s, Name: %s, ID: %s, Location: %s, Rotation: %s"), *Vehicle, *Name, *ID, *Location.ToString(), *Rotation.ToString());
222
223 return Information;
224 }
virtual FString GetActorID_Implementation() const override
Definition: Vehicle.h:203
virtual FString GetActorName_Implementation() const override
Definition: Vehicle.h:208
static FString ConvertVehicleTypeToString(EVehicleTypes VehicleType)

References UEnumUtilities::ConvertVehicleTypeToString(), ASensor::GetActorID_Implementation(), ASensor::GetActorName_Implementation(), and AOverlapSensor::Vehicle.

◆ GetActorName_Implementation()

virtual FString AVehicle::GetActorName_Implementation ( ) const
inlineoverridevirtual

Definition at line 208 of file Vehicle.h.

209 {
210 return ActorName;
211 }
FString ActorName
Definition: Vehicle.h:272

Referenced by AOverlapSensor::Init().

◆ GetCollisionSensor()

ACollisionSensor * AVehicle::GetCollisionSensor ( ) const
inline

Get collision sensor attached to this Vehicle

Returns
ACollisionSensor pointer

Definition at line 151 of file Vehicle.h.

152 {
153 return CollisionSensor;
154 }

◆ GetInteractableName_Implementation()

virtual FText AVehicle::GetInteractableName_Implementation ( ) const
inlineoverridevirtual

Definition at line 193 of file Vehicle.h.

194 {
195 return InteractableName;
196 }

◆ GetInteractableWorldTransform_Implementation()

virtual FTransform AVehicle::GetInteractableWorldTransform_Implementation ( ) const
inlineoverridevirtual

Reimplemented in APIDDrone.

Definition at line 198 of file Vehicle.h.

199 {
200 return GetActorTransform();
201 }

◆ GetMovedFromGarageTransform()

FTransform AVehicle::GetMovedFromGarageTransform ( ) const
inline

Get transform of the vehicle when it moved to garage

Returns

Definition at line 182 of file Vehicle.h.

183 {
185 }

◆ GetOverlapSensor()

AOverlapSensor * AVehicle::GetOverlapSensor ( ) const
inline

Get overlap sensor attached to this Vehicle

Returns
AOverlapSensor pointer

Definition at line 171 of file Vehicle.h.

172 {
173 return OverlapSensor;
174 }

◆ GetSensorsManager()

USensorsManagerComponent * AVehicle::GetSensorsManager ( ) const
inline

Get sensor manager attached to this Vehicle

Returns
USensorsManagerComponent pointer

Definition at line 141 of file Vehicle.h.

142 {
143 return SensorsManager;
144 }

◆ GetTopicName()

virtual FString AVehicle::GetTopicName ( )
inlinevirtual

Get ROS topic name for this sensor

Definition at line 59 of file Vehicle.h.

60 {
61 return FString(TEXT("Undefined"));
62 }

◆ GetTransformSensor()

ATransformSensor * AVehicle::GetTransformSensor ( ) const
inline

Get transform sensor attached to this Vehicle

Returns
ATransformSensor pointer

Definition at line 161 of file Vehicle.h.

162 {
163 return TransformSensor;
164 }

◆ GetVehicleType()

virtual EVehicleTypes AVehicle::GetVehicleType ( ) const
inlinevirtual

Get type of the Vehicle

Returns
Vehicle's type

Reimplemented in AForwarder, AHarvester, and APIDDrone.

Definition at line 50 of file Vehicle.h.

51 {
53 }

References NONE.

Referenced by BeginPlay().

◆ IsVehicleInGarage()

bool AVehicle::IsVehicleInGarage ( ) const
inline

Checks if the vehicle is currently in the "Garage" where vehicle can be setup with sensors.

Returns
True if the vehicle is in the garage, false otherwise.

Definition at line 131 of file Vehicle.h.

132 {
133 return VehicleInGarage;
134 }
bool VehicleInGarage
Definition: Vehicle.h:282

Referenced by ExportToJsonFile(), and APIDDrone::Tick().

◆ PossessedBy()

void AVehicle::PossessedBy ( AController *  NewController)
overridevirtual

Definition at line 79 of file Vehicle.cpp.

80{
81 Super::PossessedBy(NewController);
82
84}
void ResetCamera()

References ResetCamera().

◆ ResetCamera()

void AVehicle::ResetCamera ( )

Reset the camera to original position and rotation BlueprintImplementableEvent meant to be implemented in blueprint e.g. BP_Forwarder

Referenced by PossessedBy().

◆ SetActorIDAndName_Implementation()

virtual void AVehicle::SetActorIDAndName_Implementation ( const FString &  NewActorName,
const FString &  NewID 
)
inlineoverridevirtual

Definition at line 231 of file Vehicle.h.

232 {
233 ActorName = NewActorName;
234 ActorID = NewID;
235 SetAndValidateActorIDAndName(ActorName, ActorID, TWeakObjectPtr<AActor>(this));
236 }
static void SetAndValidateActorIDAndName(FString &ActorName, FString &ActorID, TWeakObjectPtr< AActor > Actor)

References IActorInformation::SetAndValidateActorIDAndName().

◆ SetActorName_Implementation()

virtual void AVehicle::SetActorName_Implementation ( const FString &  NewActorName)
inlineoverridevirtual

Definition at line 226 of file Vehicle.h.

227 {
228 ActorName = NewActorName;
229 }

◆ SetCurrentTransformToMovedFromGarageTransform()

void AVehicle::SetCurrentTransformToMovedFromGarageTransform ( )
inline

Definition at line 188 of file Vehicle.h.

189 {
190 MovedFromGarageTransform = GetTransform();
191 }

◆ SetVehicleIsInGarage()

void AVehicle::SetVehicleIsInGarage ( bool  VehicleIsInGarage)
inline

Sets the state of the vehicle garage state boolean.

Parameters
VehicleIsInGarage- A boolean indicating whether the vehicle is in the garage or not.

Definition at line 120 of file Vehicle.h.

121 {
122 VehicleInGarage = VehicleIsInGarage;
124 }
FVehicleGarageChangedDelegate OnVehicleGarageChanged
Definition: Vehicle.h:244

◆ SetVisualizeVehicleOverlapArea()

void AVehicle::SetVisualizeVehicleOverlapArea ( bool  Visible)

Sets the visibility of the vehicle overlap area visualization.

Parameters
VisibleWhether the vehicle overlap area should be visible or not.

Definition at line 127 of file Vehicle.cpp.

128{
129 if (OverlapSensor)
130 {
132 }
133}
void SetVisualizeOverlapArea(bool Visualize)

References OverlapSensor, and AOverlapSensor::SetVisualizeOverlapArea().

◆ TeleportVehicleTo()

void AVehicle::TeleportVehicleTo ( FVector  NewLocation,
FRotator  NewRotation 
)

Teleport the vehicle into a specific location and rotation

Parameters
NewLocation
NewRotation

◆ TeleportVehicleTo_Implementation()

void AVehicle::TeleportVehicleTo_Implementation ( FVector  NewLocation,
FRotator  NewRotation 
)
virtual

Teleport to implementation

Parameters
NewLocation
NewRotation

Definition at line 122 of file Vehicle.cpp.

123{
124 SetActorLocationAndRotation(NewLocation, NewRotation, false, nullptr, ETeleportType::TeleportPhysics);
125}

◆ ToggleLights()

void AVehicle::ToggleLights ( bool  isOn)

Toggle lights of the vehicle on or off. BlueprintImplementableEvent meant to be implemented in blueprint e.g. BP_Forwarder

Parameters
isOnPhysics on or off

◆ TogglePhysics()

void AVehicle::TogglePhysics ( bool  isOn)

Toggle physics of the vehicle on or off. BlueprintImplementableEvent meant to be implemented in blueprint e.g. BP_Forwarder

Parameters
isOnPhysics on or off

Referenced by BeginPlay(), and UROSCommands::HandleTeleportActorByID().

Member Data Documentation

◆ ActorID

FString AVehicle::ActorID
protected

Definition at line 275 of file Vehicle.h.

Referenced by BeginPlay().

◆ ActorName

FString AVehicle::ActorName
protected

Definition at line 272 of file Vehicle.h.

◆ CollisionSensor

ACollisionSensor* AVehicle::CollisionSensor = nullptr
protected

Definition at line 260 of file Vehicle.h.

Referenced by BeginPlay(), and EndPlay().

◆ InteractableName

FText AVehicle::InteractableName

◆ MovedFromGarageTransform

FTransform AVehicle::MovedFromGarageTransform
private

Definition at line 284 of file Vehicle.h.

Referenced by ExportToJsonFile().

◆ NiagaraComponent

UNiagaraComponent* AVehicle::NiagaraComponent = nullptr
protected

Definition at line 269 of file Vehicle.h.

Referenced by BeginPlay(), and EndPlay().

◆ OnVehicleGarageChanged

FVehicleGarageChangedDelegate AVehicle::OnVehicleGarageChanged

Definition at line 244 of file Vehicle.h.

◆ OriginalCameraTransform

FTransform AVehicle::OriginalCameraTransform
protected

Definition at line 278 of file Vehicle.h.

◆ OverlapSensor

AOverlapSensor* AVehicle::OverlapSensor = nullptr
protected

Definition at line 266 of file Vehicle.h.

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

◆ SensorsManager

TObjectPtr<USensorsManagerComponent> AVehicle::SensorsManager
protected

Definition at line 257 of file Vehicle.h.

Referenced by AVehicle(), EndPlay(), and ASimulationLevelManager::GetSensorsManager().

◆ TransformSensor

ATransformSensor* AVehicle::TransformSensor = nullptr
protected

Definition at line 263 of file Vehicle.h.

Referenced by BeginPlay(), and EndPlay().

◆ VehicleInGarage

bool AVehicle::VehicleInGarage = false
private

Definition at line 282 of file Vehicle.h.


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