TickBasedSource.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. #include <ROS2/Clock/ROS2ClockRequestBus.h>
  14. namespace ROS2
  15. {
  16. void TickBasedSource::Reflect(AZ::ReflectContext* context)
  17. {
  18. if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  19. {
  20. serializeContext->Class<TickBasedSource>()->Version(1);
  21. }
  22. }
  23. void TickBasedSource::Start()
  24. {
  25. AZ::TickBus::Handler::BusConnect();
  26. }
  27. void TickBasedSource::Stop()
  28. {
  29. AZ::TickBus::Handler::BusDisconnect();
  30. }
  31. float TickBasedSource::GetDeltaTime(float deltaTime) const
  32. {
  33. return deltaTime;
  34. }
  35. void TickBasedSource::OnTick(float deltaTime, AZ::ScriptTimePoint time)
  36. {
  37. AZ_UNUSED(time);
  38. AZ_UNUSED(deltaTime);
  39. float expectedSimulationLoopTime = -1.f;
  40. // query time ROS2 system
  41. ROS2ClockRequestBus::BroadcastResult(
  42. expectedSimulationLoopTime, &ROS2ClockRequestBus::Events::GetExpectedLoopTime);
  43. AZ_Assert(expectedSimulationLoopTime >= 0.f, "Did not receive expected simulation loop time from ROS2ClockRequestBus");
  44. m_sourceEvent.Signal(expectedSimulationLoopTime);
  45. }
  46. } // namespace ROS2