TickBasedSource.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. #include <AzCore/Serialization/SerializeContext.h>
  9. #include <AzCore/std/numeric.h>
  10. #include <ROS2/ROS2Bus.h>
  11. #include <ROS2/Sensor/Events/TickBasedSource.h>
  12. #include <ROS2/Utilities/ROS2Conversions.h>
  13. namespace ROS2
  14. {
  15. void TickBasedSource::Reflect(AZ::ReflectContext* context)
  16. {
  17. if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  18. {
  19. serializeContext->Class<TickBasedSource>()->Version(1);
  20. }
  21. }
  22. void TickBasedSource::Start()
  23. {
  24. AZ::TickBus::Handler::BusConnect();
  25. }
  26. void TickBasedSource::Stop()
  27. {
  28. AZ::TickBus::Handler::BusDisconnect();
  29. }
  30. float TickBasedSource::GetDeltaTime(float deltaTime) const
  31. {
  32. return deltaTime;
  33. }
  34. void TickBasedSource::OnTick(float deltaTime, AZ::ScriptTimePoint time)
  35. {
  36. AZ_UNUSED(time);
  37. AZ_UNUSED(deltaTime);
  38. const auto expectedSimulationLoopTime = ROS2Interface::Get()->GetExpectedSimulationLoopTime();
  39. m_sourceEvent.Signal(expectedSimulationLoopTime);
  40. }
  41. } // namespace ROS2