CreOS SDK
The CreOS SDK allows you to interact with Avular robots
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
Loading...
Searching...
No Matches
robot_clock.hpp
1// Copyright (C) 2024 Avular Holding B.V. - All Rights Reserved
2// You may use this code under the terms of the Avular
3// Software End-User License Agreement.
4//
5// You should have received a copy of the Avular
6// Software End-User License Agreement license with
7// this file, or download it from: avular.com/eula
8//
9/*****************************************************************************
10 * Created on: 2024 October 30
11 * Author: Robbert-Jan de Jager
12 *
13 * Definition of the Robot Clock. The robot clock is a standard c++ clock
14 * object used to represent robot time. In normal operation it will behave
15 * identical to std::chrono::system_clock, but in simulation it will contain
16 * simulation time.
17 ****************************************************************************/
18#pragma once
19
20#include <chrono>
21#include <creos/utils_global.hpp>
22#include <cstdint>
23#include <nlohmann/json.hpp>
24
25namespace creos {
26
34class CREOS_UTILS_API RobotClock {
35public:
36 using duration = typename std::chrono::nanoseconds;
37 using rep = typename duration::rep;
38 using period = typename duration::period;
39 using time_point = typename std::chrono::time_point<RobotClock, duration>;
40
41 static_assert(duration::min() < duration::zero(), "a clock's minimum duration cannot be less than its epoch");
42
43 static constexpr bool is_steady = false;
44
48 static time_point from_time_t(std::time_t t) noexcept;
49
53 static time_point now() noexcept;
54};
55
56inline void to_json(nlohmann::json& j, const RobotClock::time_point& p) {
57 j = nlohmann::json(p.time_since_epoch().count());
58}
59
60inline void from_json(const nlohmann::json& j, RobotClock::time_point& p) {
61 p = RobotClock::time_point(RobotClock::duration(j.get<RobotClock::rep>()));
62}
63
64static_assert(std::chrono::is_clock_v<RobotClock>);
65
66} // namespace creos
The clock that represents the robot time.
Definition robot_clock.hpp:34
The main namespace for the CreOS client library.