RapyutaSimulationPlugins
RRGameMode.h
Go to the documentation of this file.
1 
15 #pragma once
16 
17 
18 
19 #include "Engine/EngineTypes.h"
20 
21 
22 
23 // RapyutaSimulationPlugins
24 
25 #include "Core/RRROS2GameMode.h"
26 
27 #include "Core/RRTypeUtils.h"
28 
29 
30 
31 #include "RRGameMode.generated.h"
32 
33 
34 
48 enum class ERRSimType : uint8
49 
50 {
51 
52  NONE = 0x00,
53 
54  DATA_SYNTH = 0x01,
55 
56  ROBOT_SIM = 0x02
57 
58 };
59 
60 
61 
79 class RAPYUTASIMULATIONPLUGINS_API ARRGameMode : public ARRROS2GameMode
80 
81 {
82 
83 
84 
85 public:
86 
87  ARRGameMode();
88 
89  static constexpr int32 SIM_START_TIMEOUT_MINS = 2;
90 
91  static constexpr int32 SIM_START_TIMEOUT_SECS = 60 * SIM_START_TIMEOUT_MINS;
92 
93 
94 
95 
100  uint8 SimType = static_cast<uint8>(ERRSimType::ROBOT_SIM);
101 
102 
103 
104  bool IsSimType(const ERRSimType InSimType) const
105 
106  {
107 
108  return (static_cast<uint8>(InSimType) & static_cast<uint8>(SimType));
109 
110  }
111 
112 
113 
114  bool IsDataSynthSimType() const
115 
116  {
117 
118  return IsSimType(ERRSimType::DATA_SYNTH);
119 
120  }
121 
122 
123 
124  void SetSimType(const ERRSimType InSimType)
125 
126  {
127 
128  SimType |= static_cast<uint8>(InSimType);
129 
130  }
131 
132 
133 
134  FString GetSimTypeName() const
135 
136  {
137 
138  // SimType is not changed during Sim run
139 
140  static FString simTypeName = [this]()
141 
142  {
143 
144  FString resultName;
145 
146  auto fAppendIfOfType = [this, &resultName](const ERRSimType InSimType)
147 
148  {
149 
150  if (IsSimType(InSimType))
151 
152  {
153 
154  const FString typeName = URRTypeUtils::GetEnumValueAsString(TEXT("ERRSimType"), InSimType);
155 
156  if (resultName.IsEmpty())
157 
158  {
159 
160  resultName = typeName;
161 
162  }
163 
164  else
165 
166  {
167 
168  resultName.Append(FString::Printf(TEXT(",%s"), *typeName));
169 
170  }
171 
172  }
173 
174  };
175 
176  fAppendIfOfType(ERRSimType::ROBOT_SIM);
177 
178  fAppendIfOfType(ERRSimType::DATA_SYNTH);
179 
180  return resultName;
181 
182  }();
183 
184  return simTypeName;
185 
186  }
187 
188 
189 
190  virtual void PreInitializeComponents() override;
191 
192  virtual void InitGameState() override;
193 
194 
195 
206  virtual void StartPlay() override;
207 
208 
209 
216  virtual void PrintSimConfig() const override;
217 
218 
219 
226  static void PrintUEPreprocessors();
227 
228 
229 
236  virtual void ConfigureSimInPlay();
237 
238 
239 
258  virtual void StartSim();
259 
260 
261 
262 
267  bool bBenchmark = true;
268 
269 
270 
271  void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
272 
273 
274 
275 private:
276 
277  FTimerHandle OwnTimerHandle;
278 
279 
284  float BeginTimeStampSec = 0.f;
285 
286 
287 
303  bool TryStartingSim();
304 
305 };
306 
URRTypeUtils::GetEnumValueAsString
static FORCEINLINE FString GetEnumValueAsString(const FString &InTypeName, TEnum InEnumValue, const TCHAR *InModuleName=nullptr)
Definition: RRTypeUtils.h:118
ARRGameMode
GameMode with specific setting, asset loading and #SceneDirector. Parent class, ARRROS2GameMode,...
Definition: RRGameMode.h:79
RRTypeUtils.h
UE type related utils.
ERRSimType
ERRSimType
todo
Definition: RRGameMode.h:48
ARRROS2GameMode::StartPlay
virtual void StartPlay() override
Set timestep with startplay and call InitSim.
ARRROS2GameMode
ROS 2 GameMode which have Clock publisher and ROS 2 services to interact with ROS 2.
Definition: RRROS2GameMode.h:64
ARRROS2GameMode::PrintSimConfig
virtual void PrintSimConfig() const
Print GameMode's user configs in INI.
ARRGameMode::IsSimType
bool IsSimType(const ERRSimType InSimType) const
Definition: RRGameMode.h:104
RRROS2GameMode.h
ROS 2 GameMode which have Clock publisher and ROS 2 services to interact with ROS 2.
ERRSimType::DATA_SYNTH
@ DATA_SYNTH
ARRGameMode::OwnTimerHandle
FTimerHandle OwnTimerHandle
Definition: RRGameMode.h:277
ERRSimType::ROBOT_SIM
@ ROBOT_SIM
ARRGameMode::GetSimTypeName
FString GetSimTypeName() const
Definition: RRGameMode.h:134
ARRGameMode::SetSimType
void SetSimType(const ERRSimType InSimType)
Definition: RRGameMode.h:124
ERRUEComponentType::NONE
@ NONE
ARRGameMode::IsDataSynthSimType
bool IsDataSynthSimType() const
Definition: RRGameMode.h:114