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

#include <CollisionSensor.h>

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

Public Member Functions

 ACollisionSensor (const FObjectInitializer &ObjectInitializer)
 
void Init (AActor *NewOwner, bool SimulateSensor=true)
 
virtual ESensorTypes GetSensorType () const override
 
- Public Member Functions inherited from ASensor
 ASensor (const FObjectInitializer &ObjectInitializer)
 
FString ExportToJsonFile (const FString &FileName)
 
virtual ESensorTypes GetSensorType () const
 
FString GetSensorIdentifier () const
 
void SetSensorIdentifier (const FString newIdentifier)
 
FString GetSensorName () const
 
virtual FString GetParametersAsString () const
 
void SetSensorName (const FString newName)
 
virtual FString GetTopicName ()
 
UTopic * GetROSTopic () const
 
void SetSimulateSensor (bool SimulateSensor)
 
bool CanSimulateSensor () const
 
ASensorModelGetSensorModel () const
 
void SetSensorModel (ASensorModel *NewSensorModel)
 
bool IsROSConnected () const
 
UROSIntegrationGameInstance * GetROSGameInstance () const
 
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
 
- 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

virtual void BeginPlay () override
 
virtual void EndPlay (const EEndPlayReason::Type EndPlayReason) override
 
- Protected Member Functions inherited from ASensor
virtual void BeginPlay () override
 
virtual void EndPlay (const EEndPlayReason::Type EndPlayReason) override
 
virtual void CreateROSTopic ()
 
virtual void DestroyROSTopic ()
 
virtual void CreateDataSavePath ()
 
bool IsLogFileCreated ()
 
virtual void CreateLogFile ()
 
void WriteToLogFile (const FString &Message)
 

Private Member Functions

void SendCollisionData (const FString &CollisionDataString)
 
void OnCollisionEvent (AActor *Actor, AActor *OtherActor, FVector NormalImpulse, const FHitResult &Hit)
 

Private Attributes

TWeakObjectPtr< AActor > CurrentOwner
 
TSharedPtr< ROSMessages::std_msgs::String > CollisionMessage
 

Additional Inherited Members

- Static Public Member Functions inherited from ASensor
static void HideComponentForAllCameras (UPrimitiveComponent *PrimitiveComponent)
 
static TMap< FString, FColor > GetSemanticColors ()
 
static TArray< TWeakObjectPtr< UPrimitiveComponent > > GetComponentsToHide ()
 
- 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 ASensor
FSensorDestroy OnSensorDestroy
 
FString AttachedToComponent
 
FName AttachedToBone
 
- Static Protected Member Functions inherited from ASensor
template<typename InStructType >
static FString StructToString (const InStructType &InStruct)
 
- Protected Attributes inherited from ASensor
UTopic * ROSTopic = nullptr
 
bool SendDataToROS = true
 
ULogFileLogFile = nullptr
 
FString FileSavePath
 
UROSIntegrationGameInstance * ROSInstance = nullptr
 
- Static Protected Attributes inherited from ASensor
static FPrimitiveAdded OnPrimitiveAdded
 
static const FName NiagaraPointsInt = "User.PointCount"
 
static const FName NiagaraHitPoints = "User.HitPoints"
 
static const FName NiagaraHitColors = "User.HitColors"
 
static const FName NiagaraPointsFloat = "User.Test"
 

Detailed Description

Collision sensor for vehicles.

Definition at line 39 of file CollisionSensor.h.

Constructor & Destructor Documentation

◆ ACollisionSensor()

ACollisionSensor::ACollisionSensor ( const FObjectInitializer &  ObjectInitializer)

Definition at line 11 of file CollisionSensor.cpp.

11 : Super(ObjectInitializer)
12{
13 PrimaryActorTick.bCanEverTick = false;
14}

Member Function Documentation

◆ BeginPlay()

void ACollisionSensor::BeginPlay ( )
overrideprotectedvirtual

Reimplemented from ASensor.

Definition at line 30 of file CollisionSensor.cpp.

31{
32 Super::BeginPlay();
33}

◆ EndPlay()

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

Reimplemented from ASensor.

Definition at line 35 of file CollisionSensor.cpp.

36{
37 Super::EndPlay(EndPlayReason);
38
39 if (CurrentOwner.IsValid())
40 {
41 CurrentOwner->OnActorHit.RemoveDynamic(this, &ACollisionSensor::OnCollisionEvent);
42 }
43
44 CurrentOwner.Reset();
45 CollisionMessage.Reset();
46}
TSharedPtr< ROSMessages::std_msgs::String > CollisionMessage
void OnCollisionEvent(AActor *Actor, AActor *OtherActor, FVector NormalImpulse, const FHitResult &Hit)
TWeakObjectPtr< AActor > CurrentOwner

References CollisionMessage, CurrentOwner, and OnCollisionEvent().

◆ GetSensorType()

virtual ESensorTypes ACollisionSensor::GetSensorType ( ) const
inlineoverridevirtual

Get type of the sensor

Returns
Sensor's type

Reimplemented from ASensor.

Definition at line 59 of file CollisionSensor.h.

60 {
62 }

References Collision.

◆ Init()

void ACollisionSensor::Init ( AActor *  NewOwner,
bool  SimulateSensor = true 
)

Initialize collision sensor.

Parameters
NewOwnerThe new owner actor to be set.
SimulateSensorWhether to simulate the sensor (default is true).

Definition at line 16 of file CollisionSensor.cpp.

17{
18 SetSimulateSensor(SimulateSensor);
19
20 if (NewOwner)
21 {
22 NewOwner->OnActorHit.AddDynamic(this, &ACollisionSensor::OnCollisionEvent);
23 CurrentOwner = NewOwner;
24 }
25 CollisionMessage = MakeShared<ROSMessages::std_msgs::String>();
26
28}
void SetSimulateSensor(bool SimulateSensor)
Definition: Sensor.h:151
virtual void CreateROSTopic()
Definition: Sensor.cpp:146

References CollisionMessage, ASensor::CreateROSTopic(), CurrentOwner, OnCollisionEvent(), and ASensor::SetSimulateSensor().

Referenced by USensorFactory::SpawnCollisionSensor().

◆ OnCollisionEvent()

void ACollisionSensor::OnCollisionEvent ( AActor *  Actor,
AActor *  OtherActor,
FVector  NormalImpulse,
const FHitResult &  Hit 
)
private

Definition at line 48 of file CollisionSensor.cpp.

49{
50 if (!CanSimulateSensor() || !Actor || !OtherActor)
51 {
52 return;
53 }
54
55 NormalImpulse *= 1e-2;
56 if (NormalImpulse.Size() > 200)
57 {
58 CollisionData Collisiondata =
59 {
60 Actor->GetName(),
61 OtherActor->GetName(),
62 NormalImpulse
63 };
64
65 SendCollisionData(Collisiondata.ToString());
66
67 FString MsgHumanReadable = Collisiondata.ToStringHumanReadable();
68 WriteToLogFile(MsgHumanReadable); // Log to separate file
69 SimulatorLog::Log(MsgHumanReadable); // Log to ROS info topic and Simulator log file
70 }
71}
void SendCollisionData(const FString &CollisionDataString)
bool CanSimulateSensor() const
Definition: Sensor.h:161
void WriteToLogFile(const FString &Message)
Definition: Sensor.cpp:242
static void Log(const FString &Message, bool LogToTextFile=true, bool LogToROS=true)
FString ToStringHumanReadable()
FString ToString()

References ASensor::CanSimulateSensor(), SimulatorLog::Log(), SendCollisionData(), CollisionData::ToString(), CollisionData::ToStringHumanReadable(), and ASensor::WriteToLogFile().

Referenced by EndPlay(), and Init().

◆ SendCollisionData()

void ACollisionSensor::SendCollisionData ( const FString &  CollisionDataString)
private

Definition at line 73 of file CollisionSensor.cpp.

74{
75 UTopic* Topic = GetROSTopic();
76 if (IsROSConnected() && CollisionMessage.IsValid() && Topic)
77 {
78 CollisionMessage->_Data = CollisionDataString;
79 Topic->Publish(CollisionMessage);
80 }
81}
UTopic * GetROSTopic() const
Definition: Sensor.h:141
bool IsROSConnected() const
Definition: Sensor.h:192

References CollisionMessage, ASensor::GetROSTopic(), and ASensor::IsROSConnected().

Referenced by OnCollisionEvent().

Member Data Documentation

◆ CollisionMessage

TSharedPtr<ROSMessages::std_msgs::String> ACollisionSensor::CollisionMessage
private

Definition at line 80 of file CollisionSensor.h.

Referenced by EndPlay(), Init(), and SendCollisionData().

◆ CurrentOwner

TWeakObjectPtr<AActor> ACollisionSensor::CurrentOwner
private

Definition at line 78 of file CollisionSensor.h.

Referenced by EndPlay(), and Init().


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