5
5
6
6
#include < AzCore/Serialization/SerializeContext.h>
7
7
#include < AzFramework/Components/ConsoleBus.h>
8
+
9
+ #include < AzCore/Time/ITime.h>
10
+ #include < PhysX/Configuration/PhysXConfiguration.h>
11
+
8
12
namespace SensorDebug
9
13
{
10
14
AZ_COMPONENT_IMPL (SensorDebugSystemComponent, " SensorDebugSystemComponent" , SensorDebugSystemComponentTypeId);
@@ -21,6 +25,7 @@ namespace SensorDebug
21
25
{
22
26
ImGui::ImGuiUpdateListenerBus::Handler::BusConnect ();
23
27
AZ::TickBus::Handler::BusConnect ();
28
+ GetPhysXConfig ();
24
29
}
25
30
26
31
void SensorDebugSystemComponent::Deactivate ()
@@ -98,6 +103,29 @@ namespace SensorDebug
98
103
AZ_Printf (" TestComponent" , " Found %d sensor entities" , m_sensorEntities.size ());
99
104
}
100
105
106
+ AzPhysics::Scene* SensorDebugSystemComponent::GetScene ()
107
+ {
108
+ if (m_scene)
109
+ {
110
+ return m_scene;
111
+ }
112
+ AzPhysics::SystemInterface* physicsSystem = AZ::Interface<AzPhysics::SystemInterface>::Get ();
113
+ AZ_Assert (physicsSystem, " No physics system." );
114
+
115
+ AzPhysics::SceneInterface* sceneInterface = AZ::Interface<AzPhysics::SceneInterface>::Get ();
116
+ AZ_Assert (sceneInterface, " No scene intreface." );
117
+
118
+ AzPhysics::SceneHandle defaultSceneHandle = sceneInterface->GetSceneHandle (AzPhysics::DefaultPhysicsSceneName);
119
+ if (defaultSceneHandle == AzPhysics::InvalidSceneHandle)
120
+ {
121
+ return nullptr ;
122
+ }
123
+ AzPhysics::Scene* scene = sceneInterface->GetScene (defaultSceneHandle);
124
+ AZ_Assert (defaultSceneHandle != AzPhysics::InvalidSceneHandle, " Invalid default physics scene pointer." );
125
+ m_scene = scene;
126
+ return scene;
127
+ }
128
+
101
129
void SensorDebugSystemComponent::FindSensorsWithGivenType (const char * typeId)
102
130
{
103
131
ClearSensors ();
@@ -128,15 +156,77 @@ namespace SensorDebug
128
156
AZ_Printf (" TestComponent" , " Found %d sensor entities" , m_sensorEntities.size ());
129
157
}
130
158
159
+ void SensorDebugSystemComponent::Pause (bool isPaused)
160
+ {
161
+ GetScene ()->SetEnabled (!isPaused);
162
+ }
163
+
164
+ void SensorDebugSystemComponent::UpdatePhysXConfig ()
165
+ {
166
+ AzPhysics::SystemInterface* physicsSystem = AZ::Interface<AzPhysics::SystemInterface>::Get ();
167
+ AZ_Assert (physicsSystem, " No physics system." );
168
+ auto * physicsSystemConfigurationPtr = physicsSystem->GetConfiguration ();
169
+ auto * physicsSystemConfiguration = azdynamic_cast<const PhysX::PhysXSystemConfiguration*>(physicsSystemConfigurationPtr);
170
+ AZ_Assert (physicsSystemConfiguration, " Invalid physics system configuration pointer, a new Physics system in O3DE????" );
171
+ physicsSystem->UpdateConfiguration (&ModifiedPhysXConfig, true );
172
+ }
173
+
174
+ void SensorDebugSystemComponent::GetPhysXConfig ()
175
+ {
176
+ AzPhysics::SystemInterface* physicsSystem = AZ::Interface<AzPhysics::SystemInterface>::Get ();
177
+ AZ_Assert (physicsSystem, " No physics system." );
178
+ auto * physicsSystemConfigurationPtr = physicsSystem->GetConfiguration ();
179
+ auto * physicsSystemConfiguration = azdynamic_cast<const PhysX::PhysXSystemConfiguration*>(physicsSystemConfigurationPtr);
180
+ AZ_Assert (physicsSystemConfiguration, " Invalid physics system configuration pointer, a new Physics system in O3DE????" );
181
+ ModifiedPhysXConfig = *physicsSystemConfiguration;
182
+ }
183
+
131
184
void SensorDebugSystemComponent::OnImGuiUpdate ()
132
185
{
133
186
ImGui::Begin (" ROS2 SensorDebugger" );
187
+ ImGui::Separator ();
188
+ ImGui::Text (" TimeyWimey Stuff" );
189
+
190
+ auto ros2ts = ROS2::ROS2Interface::Get ()->GetROSTimestamp ();
191
+ const float ros2tsSec = ros2ts.sec + ros2ts.nanosec / 1e9 ;
192
+ auto ros2Node = ROS2::ROS2Interface::Get ()->GetNode ();
193
+
194
+ auto nodeTime = ros2Node->now ();
195
+ const float ros2nodetsSec = nodeTime.seconds () + nodeTime.nanoseconds () / 1e9 ;
196
+
197
+ auto timeSystem = AZ::Interface<AZ::ITime>::Get ();
198
+ const auto elapsedTime = timeSystem ? static_cast <double >(timeSystem->GetElapsedTimeUs ()) / 1e6 : 0.0 ;
199
+
200
+ ImGui::Text (" Current ROS 2 time (Gem) : %f" , ros2tsSec);
201
+ ImGui::Text (" Current ROS 2 time (Node) : %f" , ros2nodetsSec);
202
+ ImGui::Text (" Current O3DE time : %f" , elapsedTime);
203
+
204
+ ImGui::Separator ();
205
+ ImGui::Text (" PhysX" );
206
+ ImGui::InputFloat (" Fixed timestamp" , &ModifiedPhysXConfig.m_fixedTimestep , 0 .0f , 0 .0f , " %.6f" );
207
+ ImGui::InputFloat (" Max timestamp" , &ModifiedPhysXConfig.m_maxTimestep , 0 .0f , 0 .0f , " %.6f" git a);
208
+ if (ImGui::Button (" Update PhysX Config" ))
209
+ {
210
+ UpdatePhysXConfig ();
211
+ }
212
+ ImGui::SameLine ();
213
+ if (ImGui::Button (" Pause" ))
214
+ {
215
+ Pause (true );
216
+ }
217
+ ImGui::SameLine ();
218
+ if (ImGui::Button (" Unpause" ))
219
+ {
220
+ Pause (false );
221
+ }
222
+ ImGui::Separator ();
223
+ ImGui::Text (" Atom" );
134
224
135
225
ImGui::InputFloat (" Application Max FPS" , &m_maxFPS);
136
226
ImGui::SameLine ();
137
227
if (ImGui::Button (" Set sys_MaxFPS" ))
138
228
{
139
- // disable vsync
229
+ // disable vsync
140
230
AZStd::string commandVsync = AZStd::string::format (" vsync_interval=0" );
141
231
AzFramework::ConsoleRequestBus::Broadcast (&AzFramework::ConsoleRequests::ExecuteConsoleCommand, commandVsync.c_str ());
142
232
AZStd::string commandMaxFps = AZStd::string::format (" sys_MaxFPS=%f" , m_maxFPS);
@@ -228,22 +318,22 @@ namespace SensorDebug
228
318
frequency, sensorEntity, &ROS2::SensorConfigurationRequest::GetEffectiveFrequency);
229
319
230
320
m_sensorFrequencyHistory[sensorEntity].push_back (frequency);
231
- auto & sensorFrequencyHistory = m_sensorFrequencyHistory[sensorEntity];
321
+ auto & sensorFrequencyHistory = m_sensorFrequencyHistory[sensorEntity];
232
322
if (sensorFrequencyHistory.size () > m_historySize)
233
323
{
234
324
sensorFrequencyHistory.erase (sensorFrequencyHistory.begin ());
235
325
}
236
326
float freqencySum = 0 .0f ;
237
327
for (const auto & freq : sensorFrequencyHistory)
238
328
{
239
- freqencySum += freq;
329
+ freqencySum += freq;
240
330
}
241
331
const float averageFrequency = freqencySum / static_cast <float >(sensorFrequencyHistory.size ());
242
332
// compute std deviation
243
333
float variance = 0 .0f ;
244
334
for (const auto & freq : sensorFrequencyHistory)
245
335
{
246
- variance += (freq - averageFrequency) * (freq - averageFrequency);
336
+ variance += (freq - averageFrequency) * (freq - averageFrequency);
247
337
}
248
338
float stdDeviation = sqrt (variance / static_cast <float >(sensorFrequencyHistory.size ()));
249
339
const AZStd::string histogramNameWithCookie = AZStd::string::format (" Histogram%s" , cookie.c_str ());
@@ -254,7 +344,7 @@ namespace SensorDebug
254
344
const AZStd::string resetButton = AZStd::string::format (" reset stats%s" , cookie.c_str ());
255
345
if (ImGui::Button (resetButton.c_str ()))
256
346
{
257
- sensorFrequencyHistory.clear ();
347
+ sensorFrequencyHistory.clear ();
258
348
}
259
349
ImGui::Text (
260
350
" %s : %s effective Freq: %.2f Hz [ std_dev = %.2f ]" ,
0 commit comments