55
66#include  < AzCore/Serialization/SerializeContext.h> 
77#include  < AzFramework/Components/ConsoleBus.h> 
8+ 
9+ #include  < AzCore/Time/ITime.h> 
10+ #include  < PhysX/Configuration/PhysXConfiguration.h> 
11+ 
812namespace  SensorDebug 
913{
1014    AZ_COMPONENT_IMPL (SensorDebugSystemComponent, " SensorDebugSystemComponent" 
@@ -21,6 +25,7 @@ namespace SensorDebug
2125    {
2226        ImGui::ImGuiUpdateListenerBus::Handler::BusConnect ();
2327        AZ::TickBus::Handler::BusConnect ();
28+         GetPhysXConfig ();
2429    }
2530
2631    void  SensorDebugSystemComponent::Deactivate ()
@@ -98,6 +103,29 @@ namespace SensorDebug
98103        AZ_Printf (" TestComponent" " Found %d sensor entities" size ());
99104    }
100105
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+ 
101129    void  SensorDebugSystemComponent::FindSensorsWithGivenType (const  char * typeId)
102130    {
103131        ClearSensors ();
@@ -128,15 +156,77 @@ namespace SensorDebug
128156        AZ_Printf (" TestComponent" " Found %d sensor entities" size ());
129157    }
130158
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+ 
131184    void  SensorDebugSystemComponent::OnImGuiUpdate ()
132185    {
133186        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" 
201+         ImGui::Text (" Current ROS 2 time (Node) : %f" 
202+         ImGui::Text (" Current O3DE time         : %f" 
203+ 
204+         ImGui::Separator ();
205+         ImGui::Text (" PhysX" 
206+         ImGui::InputFloat (" Fixed timestamp" m_fixedTimestep , 0 .0f , 0 .0f , " %.6f" 
207+         ImGui::InputFloat (" Max timestamp" m_maxTimestep , 0 .0f , 0 .0f , " %.6f" 
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" 
134224
135225        ImGui::InputFloat (" Application Max FPS" 
136226        ImGui::SameLine ();
137227        if  (ImGui::Button (" Set sys_MaxFPS" 
138228        {
139-             // disable vsync
229+             //   disable vsync
140230            AZStd::string commandVsync = AZStd::string::format (" vsync_interval=0" 
141231            AzFramework::ConsoleRequestBus::Broadcast (&AzFramework::ConsoleRequests::ExecuteConsoleCommand, commandVsync.c_str ());
142232            AZStd::string commandMaxFps = AZStd::string::format (" sys_MaxFPS=%f" 
@@ -228,22 +318,22 @@ namespace SensorDebug
228318                frequency, sensorEntity, &ROS2::SensorConfigurationRequest::GetEffectiveFrequency);
229319
230320            m_sensorFrequencyHistory[sensorEntity].push_back (frequency);
231-             auto  & sensorFrequencyHistory = m_sensorFrequencyHistory[sensorEntity];
321+             auto &  sensorFrequencyHistory = m_sensorFrequencyHistory[sensorEntity];
232322            if  (sensorFrequencyHistory.size () > m_historySize)
233323            {
234324                sensorFrequencyHistory.erase (sensorFrequencyHistory.begin ());
235325            }
236326            float  freqencySum = 0 .0f ;
237327            for  (const  auto & freq : sensorFrequencyHistory)
238328            {
239-                      freqencySum += freq;
329+                 freqencySum += freq;
240330            }
241331            const  float  averageFrequency = freqencySum / static_cast <float >(sensorFrequencyHistory.size ());
242332            //  compute std deviation
243333            float  variance = 0 .0f ;
244334            for  (const  auto & freq : sensorFrequencyHistory)
245335            {
246-                      variance += (freq - averageFrequency) * (freq - averageFrequency);
336+                 variance += (freq - averageFrequency) * (freq - averageFrequency);
247337            }
248338            float  stdDeviation = sqrt (variance / static_cast <float >(sensorFrequencyHistory.size ()));
249339            const  AZStd::string histogramNameWithCookie = AZStd::string::format (" Histogram%s" c_str ());
@@ -254,7 +344,7 @@ namespace SensorDebug
254344            const  AZStd::string resetButton = AZStd::string::format (" reset stats%s" c_str ());
255345            if  (ImGui::Button (resetButton.c_str ()))
256346            {
257-                      sensorFrequencyHistory.clear ();
347+                 sensorFrequencyHistory.clear ();
258348            }
259349            ImGui::Text (
260350                " %s : %s effective Freq: %.2f Hz [ std_dev = %.2f ]" 
0 commit comments