Agrarsense
Static Public Member Functions | Private Member Functions | Static Private Member Functions | Static Private Attributes | Friends | List of all members
UInfoTopic Class Reference

#include <InfoTopic.h>

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

Static Public Member Functions

static void SetAllowSendInfo (bool Allow)
 
static void SendMessage (const FString &Message)
 

Private Member Functions

void Setup ()
 
void SetupROSInfoTopic ()
 
void DestroyROSTopic ()
 
void ROSBridgeStateChanged (EROSState state)
 

Static Private Member Functions

static void Init ()
 
static void Destroy ()
 

Static Private Attributes

static UInfoTopicInstance = nullptr
 
static TWeakObjectPtr< UTopic > InfoTopic
 
static TSharedPtr< ROSMessages::std_msgs::String > ROSMessage
 
static bool ROSConnected = false
 
static bool AllowInfoTopic = true
 

Friends

class AAgrarsenseGameModeBase
 

Detailed Description

Definition at line 27 of file InfoTopic.h.

Member Function Documentation

◆ Destroy()

void UInfoTopic::Destroy ( )
staticprivate

Definition at line 33 of file InfoTopic.cpp.

34{
35 if (Instance)
36 {
38 Instance = nullptr;
39 }
40}
void DestroyROSTopic()
Definition: InfoTopic.cpp:75
static UInfoTopic * Instance
Definition: InfoTopic.h:56

References DestroyROSTopic(), and Instance.

Referenced by AAgrarsenseGameModeBase::EndPlay().

◆ DestroyROSTopic()

void UInfoTopic::DestroyROSTopic ( )
private

Definition at line 75 of file InfoTopic.cpp.

76{
77 if (InfoTopic.IsValid())
78 {
79 InfoTopic->Unadvertise();
80 InfoTopic->Unsubscribe();
81 InfoTopic->MarkAsDisconnected();
82 InfoTopic->ConditionalBeginDestroy();
83 InfoTopic.Reset();
84
85#if WITH_EDITOR
86 UE_LOG(LogTemp, Warning, TEXT("InfoTopic.cpp: Destroyed ROS Info Topic"));
87#endif
88 }
89}
static TWeakObjectPtr< UTopic > InfoTopic
Definition: InfoTopic.h:58

References InfoTopic.

Referenced by Destroy(), and ROSBridgeStateChanged().

◆ Init()

void UInfoTopic::Init ( )
staticprivate

Definition at line 24 of file InfoTopic.cpp.

25{
26 if (Instance == nullptr)
27 {
28 Instance = NewObject<UInfoTopic>();
29 Instance->Setup();
30 }
31}
void Setup()
Definition: InfoTopic.cpp:42

References Instance, and Setup().

Referenced by AAgrarsenseGameModeBase::SpawnNeededActorsBeginPlay().

◆ ROSBridgeStateChanged()

void UInfoTopic::ROSBridgeStateChanged ( EROSState  state)
private

Definition at line 59 of file InfoTopic.cpp.

60{
61 switch (state)
62 {
64 ROSConnected = true;
66 break;
67
69 ROSConnected = false;
71 break;
72 }
73}
void SetupROSInfoTopic()
Definition: InfoTopic.cpp:91
static bool ROSConnected
Definition: InfoTopic.h:62

References Connected, DestroyROSTopic(), Disconnected, ROSConnected, and SetupROSInfoTopic().

Referenced by Setup().

◆ SendMessage()

void UInfoTopic::SendMessage ( const FString &  Message)
static

Definition at line 129 of file InfoTopic.cpp.

130{
131 // UInfoTopic::Init must be called before SendMessage is called.
132 // At the moment Init called from AgrarsenseGameModeBase.cpp BeginPlay
133
134 if (!InfoTopic.IsValid() || !ROSMessage.IsValid())
135 {
136 if (Instance)
137 {
139 }
140 }
141
143 && InfoTopic.IsValid() && ROSMessage.IsValid() && !Message.IsEmpty())
144 {
145 ROSMessage->_Data = Message;
146 InfoTopic->Publish(ROSMessage);
147 }
148}
static bool AllowInfoTopic
Definition: InfoTopic.h:64
static TSharedPtr< ROSMessages::std_msgs::String > ROSMessage
Definition: InfoTopic.h:60

References AllowInfoTopic, InfoTopic, Instance, ROSConnected, ROSMessage, and SetupROSInfoTopic().

Referenced by SimulatorLog::Log(), and UInfoTopicBlueprint::SendInfoMessageToROS().

◆ SetAllowSendInfo()

void UInfoTopic::SetAllowSendInfo ( bool  Allow)
static

Definition at line 124 of file InfoTopic.cpp.

125{
126 AllowInfoTopic = Allow;
127}

References AllowInfoTopic.

◆ Setup()

void UInfoTopic::Setup ( )
private

Definition at line 42 of file InfoTopic.cpp.

43{
44 Instance = this;
45
46 if (GEngine && GEngine->GameViewport)
47 {
48 UWorld* World = GEngine->GameViewport->GetWorld();
50 if (RosHandle)
51 {
52 RosHandle->OnROSStateChanged.AddUniqueDynamic(this, &UInfoTopic::ROSBridgeStateChanged);
53 }
54 }
55
57}
static UROSHandler * GetROSHandle(const UObject *WorldContextObject)
void ROSBridgeStateChanged(EROSState state)
Definition: InfoTopic.cpp:59
FROSDelegate_ROState OnROSStateChanged
Definition: ROSHandler.h:81

References UAgrarsenseStatics::GetROSHandle(), Instance, UROSHandler::OnROSStateChanged, ROSBridgeStateChanged(), and SetupROSInfoTopic().

Referenced by Init().

◆ SetupROSInfoTopic()

void UInfoTopic::SetupROSInfoTopic ( )
private

Definition at line 91 of file InfoTopic.cpp.

92{
93 if (InfoTopic.IsValid() && ROSMessage.IsValid())
94 {
95 return;
96 }
97
98 if (GEngine && GEngine->GameViewport)
99 {
100 UWorld* World = GEngine->GameViewport->GetWorld();
101 UROSIntegrationGameInstance* RosInstance = UAgrarsenseStatics::GetROSGameInstance(World);
102
103 if (RosInstance)
104 {
105 ROSMessage.Reset();
106 ROSMessage = MakeShared<ROSMessages::std_msgs::String>();
107
108 ROSConnected = RosInstance->IsROSConnected();
109
110 if (!InfoTopic.IsValid() && ROSConnected)
111 {
112 InfoTopic = NewObject<UTopic>(UTopic::StaticClass());
113 InfoTopic->Init(RosInstance->ROSIntegrationCore, TEXT("/agrarsense/out/info"), TEXT("std_msgs/String"));
114 InfoTopic->Advertise();
115
116#if WITH_EDITOR
117 UE_LOG(LogTemp, Warning, TEXT("InfoTopic.cpp: Created ROS Info Topic"));
118#endif
119 }
120 }
121 }
122}
static UROSIntegrationGameInstance * GetROSGameInstance(const UObject *WorldContextObject)

References UAgrarsenseStatics::GetROSGameInstance(), InfoTopic, ROSConnected, and ROSMessage.

Referenced by ROSBridgeStateChanged(), SendMessage(), and Setup().

Friends And Related Function Documentation

◆ AAgrarsenseGameModeBase

friend class AAgrarsenseGameModeBase
friend

Definition at line 41 of file InfoTopic.h.

Member Data Documentation

◆ AllowInfoTopic

bool UInfoTopic::AllowInfoTopic = true
staticprivate

Definition at line 64 of file InfoTopic.h.

Referenced by SendMessage(), and SetAllowSendInfo().

◆ InfoTopic

TWeakObjectPtr< UTopic > UInfoTopic::InfoTopic
staticprivate

Definition at line 58 of file InfoTopic.h.

Referenced by DestroyROSTopic(), SendMessage(), and SetupROSInfoTopic().

◆ Instance

UInfoTopic * UInfoTopic::Instance = nullptr
staticprivate

Definition at line 56 of file InfoTopic.h.

Referenced by Destroy(), Init(), SendMessage(), and Setup().

◆ ROSConnected

bool UInfoTopic::ROSConnected = false
staticprivate

Definition at line 62 of file InfoTopic.h.

Referenced by ROSBridgeStateChanged(), SendMessage(), and SetupROSInfoTopic().

◆ ROSMessage

TSharedPtr< ROSMessages::std_msgs::String > UInfoTopic::ROSMessage
staticprivate

Definition at line 60 of file InfoTopic.h.

Referenced by SendMessage(), and SetupROSInfoTopic().


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