PhysicsBasedSource.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/EBus/OrderedEvent.h>
  10. #include <AzFramework/Physics/Common/PhysicsEvents.h>
  11. #include <AzFramework/Physics/Common/PhysicsTypes.h>
  12. #include <ROS2/ROS2Bus.h>
  13. #include <ROS2/Sensor/Events/SensorEventSource.h>
  14. namespace ROS2
  15. {
  16. //! Class implementing physics callbacks as sensor event source. Source event (ROS2::SensorEventSource) is signalled based on scene
  17. //! simulation finish event.
  18. //! @note The working frequency of this event source can be changed through engine settings (physics simulation delta).
  19. //! @see ROS2::SensorEventSource
  20. class PhysicsBasedSource final : public SensorEventSource<AZ::OrderedEvent, AZ::OrderedEventHandler, AzPhysics::SceneHandle, float>
  21. {
  22. public:
  23. AZ_TYPE_INFO(PhysicsBasedSource, "{48BB21A8-F14E-4869-95DC-28EEA279Cf53}");
  24. static void Reflect(AZ::ReflectContext* context);
  25. // Overrides of ROS2::SensorEventSource.
  26. void Start() override;
  27. void Stop() override;
  28. [[nodiscard]] float GetDeltaTime(AzPhysics::SceneHandle sceneHandle, float deltaTime) const override;
  29. private:
  30. AzPhysics::SceneEvents::OnSceneSimulationFinishHandler m_onSceneSimulationEventHandler; ///< Handler for physics callback.
  31. builtin_interfaces::msg::Time m_lastSimulationTime; ///< Last simulation time.
  32. };
  33. } // namespace ROS2