Apollo  6.0
Open source self driving car software
clock.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2020 The Apollo Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *****************************************************************************/
16 
17 #ifndef CYBER_TIME_CLOCK_H_
18 #define CYBER_TIME_CLOCK_H_
19 
20 #include <mutex>
21 
22 #include "cyber/proto/run_mode_conf.pb.h"
23 
25 #include "cyber/common/macros.h"
26 #include "cyber/time/time.h"
27 
28 namespace apollo {
29 namespace cyber {
30 
31 using ::apollo::cyber::proto::ClockMode;
32 
39 class Clock {
40  public:
41  static constexpr int64_t PRECISION =
42  std::chrono::system_clock::duration::period::den /
43  std::chrono::system_clock::duration::period::num;
44 
46  static_assert(PRECISION >= 1000000,
47  "The precision of the system clock should be at least 1 "
48  "microsecond.");
49 
54  static Time Now();
55 
60  static double NowInSeconds();
61 
66  static void SetNow(const Time& now);
67 
72  static void SetMode(ClockMode mode);
73 
78  static ClockMode mode();
79 
84  static void SetNowInSeconds(const double seconds) {
85  Clock::SetNow(Time(seconds));
86  }
87 
88  private:
89  ClockMode mode_;
90  Time mock_now_;
92 
94 };
95 
96 } // namespace cyber
97 } // namespace apollo
98 
99 #endif // CYBER_TIME_CLOCK_H_
::apollo::cyber::Time Time
Definition: racobit_radar_message_manager.h:41
static void SetNowInSeconds(const double seconds)
This is for mock clock mode only. It will set the timestamp for the mock clock with UNIX timestamp in...
Definition: clock.h:84
static constexpr int64_t PRECISION
Definition: clock.h:41
static void SetNow(const Time &now)
This is for mock clock mode only. It will set the timestamp for the mock clock.
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Definition: atomic_rw_lock.h:36
#define DECLARE_SINGLETON(classname)
Definition: macros.h:52
a singleton clock that can be used to get the current timestamp. The source can be either system(cybe...
Definition: clock.h:39
static void SetMode(ClockMode mode)
static ClockMode mode()
Gets the current clock mode.
static Time Now()
PRECISION >= 1000000 means the precision is at least 1us.
Cyber has builtin time type Time.
Definition: time.h:31
static double NowInSeconds()
gets the current time in second.