RealTimeSource.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 "ITimeSource.h"
  10. namespace ROS2
  11. {
  12. //! The RealTimeSource starts from 0 at the start of the simulation.
  13. //! This time source could be affected by the jitter in the data, simulation
  14. //! computations or other similar events. On the other hand RealTimeSource
  15. //! can remain consistent with the other independent clocks if it is synchronized
  16. //! (e.g. through NTP).
  17. class RealTimeSource : public ITimeSource
  18. {
  19. public:
  20. virtual ~RealTimeSource() = default;
  21. // ITimeSource overrides ...
  22. virtual void Activate() override {};
  23. virtual void Deactivate() override {};
  24. //! Sets the time source to the given time.
  25. //! @param time The time to set the time source to.
  26. //! @return An outcome indicating success or failure.
  27. virtual AZ::Outcome<void, AZStd::string> AdjustTime(const builtin_interfaces::msg::Time& time) override;
  28. //! Get simulation time as ROS 2 message.
  29. //! @see ROS2Requests::GetROSTimestamp() for more details.
  30. virtual builtin_interfaces::msg::Time GetROSTimestamp() const override;
  31. private:
  32. int64_t GetElapsedTimeMicroseconds() const;
  33. };
  34. } // namespace ROS2