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

#include <AgrarsenseGameInstance.h>

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

Public Member Functions

virtual void Init () override
 
virtual void BeginDestroy () override
 
virtual void Shutdown () override
 

Public Attributes

bool DefaultConnectToROS = true
 
FString DefaultROSHost = "127.0.0.1"
 
bool DefaultAsyncROSConnection = true
 
int DefaultROSPort = 9090
 
int DefaultROSMaxRetries = 3
 

Private Member Functions

virtual void ROSBridgeConnected () override
 
virtual void ROSBridgeDisconnected () override
 
void ParseLaunchArguments (bool &ConnectToROS, bool &AsyncROSConnection, FString &Host, int &Port, int &MaxRetries)
 

Detailed Description

Definition at line 14 of file AgrarsenseGameInstance.h.

Member Function Documentation

◆ BeginDestroy()

void UAgrarsenseGameInstance::BeginDestroy ( )
overridevirtual

Definition at line 35 of file AgrarsenseGameInstance.cpp.

36{
37 Super::BeginDestroy();
38}

◆ Init()

void UAgrarsenseGameInstance::Init ( )
overridevirtual

Definition at line 15 of file AgrarsenseGameInstance.cpp.

16{
17 bool ConnectToROS = DefaultConnectToROS;
18 bool AsyncROSConnection = DefaultAsyncROSConnection;
19 FString Host = DefaultROSHost;
20 int Port = DefaultROSPort;
21 int MaxRetries = DefaultROSMaxRetries;
22
23 ParseLaunchArguments(ConnectToROS, AsyncROSConnection, Host, Port, MaxRetries);
24
25 // Set UROSIntegrationGameInstance ROS variables, afterwards these cannot be changed.
26 bConnectToROS = ConnectToROS;
27 bConnectToROSAsync = AsyncROSConnection;
28 ROSBridgeServerHost = Host;
29 ROSBridgeServerPort = Port;
30 bMaxRetries = MaxRetries;
31
32 Super::Init();
33}
void ParseLaunchArguments(bool &ConnectToROS, bool &AsyncROSConnection, FString &Host, int &Port, int &MaxRetries)

References DefaultAsyncROSConnection, DefaultConnectToROS, DefaultROSHost, DefaultROSMaxRetries, DefaultROSPort, and ParseLaunchArguments().

◆ ParseLaunchArguments()

void UAgrarsenseGameInstance::ParseLaunchArguments ( bool &  ConnectToROS,
bool &  AsyncROSConnection,
FString &  Host,
int &  Port,
int &  MaxRetries 
)
private

Parse launch arguments related to ROS setup. Packaged builds only.

Definition at line 65 of file AgrarsenseGameInstance.cpp.

66{
67 if (FParse::Param(FCommandLine::Get(), TEXT("-no-ros")))
68 {
69 ConnectToROS = false;
70 }
71
72 if (FParse::Param(FCommandLine::Get(), TEXT("-no-ros-async")))
73 {
74 AsyncROSConnection = false;
75 }
76
77 FString HostString;
78 if (FParse::Value(FCommandLine::Get(), TEXT("-ros-host-ip="), HostString))
79 {
80 FRegexPattern IpPattern(TEXT("^\\d+\\.\\d+\\.\\d+\\.\\d+$"));
81 FRegexMatcher Matcher(IpPattern, HostString);
82
83 if (Matcher.FindNext())
84 {
85 Host = HostString;
86 }
87 }
88
89 FString PortString;
90 if (FParse::Value(FCommandLine::Get(), TEXT("-ros-port="), PortString))
91 {
92 if (PortString.IsNumeric())
93 {
94 Port = FCString::Atoi(*PortString);
95 }
96 }
97
98 FString MaxRetriesString;
99 if (FParse::Value(FCommandLine::Get(), TEXT("-ros-max-retries="), MaxRetriesString))
100 {
101 if (MaxRetriesString.IsNumeric())
102 {
103 MaxRetries = FCString::Atoi(*MaxRetriesString);
104 }
105 }
106}

Referenced by Init().

◆ ROSBridgeConnected()

void UAgrarsenseGameInstance::ROSBridgeConnected ( )
overrideprivatevirtual

Called from ROSIntegrationGameInstance.h when ROS Bridge is connected.

Definition at line 45 of file AgrarsenseGameInstance.cpp.

46{
47 UROSHandler* ROSHandler = UAgrarsenseStatics::GetROSHandle(GetWorld());
48 if (ROSHandler)
49 {
50 SimulatorLog::Log("ROS Connected.");
51 ROSHandler->OnROSStateChanged.Broadcast(EROSState::Connected);
52 }
53}
static void Log(const FString &Message, bool LogToTextFile=true, bool LogToROS=true)
static UROSHandler * GetROSHandle(const UObject *WorldContextObject)
FROSDelegate_ROState OnROSStateChanged
Definition: ROSHandler.h:81

References Connected, UAgrarsenseStatics::GetROSHandle(), SimulatorLog::Log(), and UROSHandler::OnROSStateChanged.

◆ ROSBridgeDisconnected()

void UAgrarsenseGameInstance::ROSBridgeDisconnected ( )
overrideprivatevirtual

Called from ROSIntegrationGameInstance.h when ROS Bridge is disconnected.

Definition at line 55 of file AgrarsenseGameInstance.cpp.

56{
57 UROSHandler* ROSHandler = UAgrarsenseStatics::GetROSHandle(GetWorld());
58 if (ROSHandler)
59 {
60 SimulatorLog::Log("ROS Disconnected.");
61 ROSHandler->OnROSStateChanged.Broadcast(EROSState::Disconnected);
62 }
63}

References Disconnected, UAgrarsenseStatics::GetROSHandle(), SimulatorLog::Log(), and UROSHandler::OnROSStateChanged.

◆ Shutdown()

void UAgrarsenseGameInstance::Shutdown ( )
overridevirtual

Definition at line 40 of file AgrarsenseGameInstance.cpp.

41{
42 Super::Shutdown();
43}

Member Data Documentation

◆ DefaultAsyncROSConnection

bool UAgrarsenseGameInstance::DefaultAsyncROSConnection = true

Definition at line 33 of file AgrarsenseGameInstance.h.

Referenced by Init().

◆ DefaultConnectToROS

bool UAgrarsenseGameInstance::DefaultConnectToROS = true

Definition at line 27 of file AgrarsenseGameInstance.h.

Referenced by Init().

◆ DefaultROSHost

FString UAgrarsenseGameInstance::DefaultROSHost = "127.0.0.1"

Definition at line 30 of file AgrarsenseGameInstance.h.

Referenced by Init().

◆ DefaultROSMaxRetries

int UAgrarsenseGameInstance::DefaultROSMaxRetries = 3

Definition at line 39 of file AgrarsenseGameInstance.h.

Referenced by Init().

◆ DefaultROSPort

int UAgrarsenseGameInstance::DefaultROSPort = 9090

Definition at line 36 of file AgrarsenseGameInstance.h.

Referenced by Init().


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