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
 

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 60 of file AgrarsenseGameInstance.cpp.

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

Referenced by Init().

◆ ROSBridgeConnected()

void UAgrarsenseGameInstance::ROSBridgeConnected ( )
overrideprivatevirtual

Called from ROSIntegrationGameInstance.h when ROS Bridge is connected.

Definition at line 40 of file AgrarsenseGameInstance.cpp.

41{
42 UROSHandler* ROSHandler = UAgrarsenseStatics::GetROSHandle(GetWorld());
43 if (ROSHandler)
44 {
45 SimulatorLog::Log("ROS Connected.");
46 ROSHandler->OnROSStateChanged.Broadcast(EROSState::Connected);
47 }
48}
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 50 of file AgrarsenseGameInstance.cpp.

51{
52 UROSHandler* ROSHandler = UAgrarsenseStatics::GetROSHandle(GetWorld());
53 if (ROSHandler)
54 {
55 SimulatorLog::Log("ROS Disconnected.");
56 ROSHandler->OnROSStateChanged.Broadcast(EROSState::Disconnected);
57 }
58}

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

Member Data Documentation

◆ DefaultAsyncROSConnection

bool UAgrarsenseGameInstance::DefaultAsyncROSConnection = true

Definition at line 31 of file AgrarsenseGameInstance.h.

Referenced by Init().

◆ DefaultConnectToROS

bool UAgrarsenseGameInstance::DefaultConnectToROS = true

Definition at line 25 of file AgrarsenseGameInstance.h.

Referenced by Init().

◆ DefaultROSHost

FString UAgrarsenseGameInstance::DefaultROSHost = "127.0.0.1"

Definition at line 28 of file AgrarsenseGameInstance.h.

Referenced by Init().

◆ DefaultROSMaxRetries

int UAgrarsenseGameInstance::DefaultROSMaxRetries = 3

Definition at line 37 of file AgrarsenseGameInstance.h.

Referenced by Init().

◆ DefaultROSPort

int UAgrarsenseGameInstance::DefaultROSPort = 9090

Definition at line 34 of file AgrarsenseGameInstance.h.

Referenced by Init().


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