CARLA
Timestamp.h
Go to the documentation of this file.
1 // Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
2 // de Barcelona (UAB).
3 //
4 // This work is licensed under the terms of the MIT license.
5 // For a copy, see <https://opensource.org/licenses/MIT>.
6 
7 #pragma once
8 
9 #include <cstdint>
10 
11 namespace carla {
12 namespace client {
13 
14  class Timestamp {
15  public:
16 
17  Timestamp() = default;
18 
20  std::size_t in_frame,
21  double in_elapsed_seconds,
22  double in_delta_seconds,
23  double in_platform_timestamp)
24  : frame(in_frame),
25  elapsed_seconds(in_elapsed_seconds),
26  delta_seconds(in_delta_seconds),
27  platform_timestamp(in_platform_timestamp) {}
28 
29  /// Number of frames elapsed since the simulator was launched.
30  std::size_t frame = 0u;
31 
32  /// Simulated seconds elapsed since the beginning of the current episode.
33  double elapsed_seconds = 0.0;
34 
35  /// Simulated seconds elapsed since previous frame.
36  double delta_seconds = 0.0;
37 
38  /// Time-stamp of the frame at which this measurement was taken, in seconds
39  /// as given by the OS.
40  double platform_timestamp = 0.0;
41 
42  bool operator==(const Timestamp &rhs) const {
43  return frame == rhs.frame;
44  }
45 
46  bool operator!=(const Timestamp &rhs) const {
47  return !(*this == rhs);
48  }
49  };
50 
51 } // namespace client
52 } // namespace carla
53 
54 
55 namespace std {
56 /**
57  * \brief standard ostream operator
58  *
59  * \param[in/out] out The output stream to write to
60  * \param[in] timestamp the timestamp to stream out
61  *
62  * \returns The stream object.
63  *
64  */
65 inline std::ostream &operator<<(std::ostream &out, const ::carla::client::Timestamp &timestamp) {
66  out << "Timestamp(frame=" << std::to_string(timestamp.frame)
67  << ",elapsed_seconds=" << std::to_string(timestamp.elapsed_seconds)
68  << ",delta_seconds=" << std::to_string(timestamp.delta_seconds)
69  << ",platform_timestamp=" << std::to_string(timestamp.platform_timestamp) << ')';
70  return out;
71 }
72 } // namespace std
bool operator!=(const Timestamp &rhs) const
Definition: Timestamp.h:46
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
std::size_t frame
Number of frames elapsed since the simulator was launched.
Definition: Timestamp.h:30
Timestamp(std::size_t in_frame, double in_elapsed_seconds, double in_delta_seconds, double in_platform_timestamp)
Definition: Timestamp.h:19
static std::ostream & operator<<(std::ostream &out, const Buffer &buf)
Definition: test/Buffer.h:48
bool operator==(const Timestamp &rhs) const
Definition: Timestamp.h:42
double delta_seconds
Simulated seconds elapsed since previous frame.
Definition: Timestamp.h:36
double elapsed_seconds
Simulated seconds elapsed since the beginning of the current episode.
Definition: Timestamp.h:33
double platform_timestamp
Time-stamp of the frame at which this measurement was taken, in seconds as given by the OS...
Definition: Timestamp.h:40