Autoware.Auto
measurement_time_keeper.hpp
Go to the documentation of this file.
1 // Copyright 2020 Apex.AI, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
17 
18 #ifndef STATE_ESTIMATION_NODES__MEASUREMENT_TIME_KEEPER_HPP_
19 #define STATE_ESTIMATION_NODES__MEASUREMENT_TIME_KEEPER_HPP_
20 
21 #include <common/types.hpp>
23 
24 #include <algorithm>
25 #include <chrono>
26 #include <utility>
27 
28 namespace autoware
29 {
30 namespace prediction
31 {
32 
42 {
43 public:
47  MeasurementBasedTimeKeeper() = default;
48 
57  const GlobalTime & time_of_event,
58  const MeasurementBasedTime & timestamp)
59  : m_time_last_measurement_received{time_of_event}, m_last_measurement_timestamp{timestamp}
60  {
61  m_last_temporal_update = convert_to_measurement_time(time_of_event);
62  }
63 
69  inline common::types::bool8_t is_initialized() const noexcept
70  {
71  return m_time_last_measurement_received.is_valid() && m_last_temporal_update.is_valid();
72  }
73 
83  template<typename MeasurementT>
85  const GlobalTime & time_of_event,
86  const MeasurementT & measurement)
87  {
88  m_time_last_measurement_received = time_of_event;
89  m_last_measurement_timestamp = measurement.get_acquisition_time();
90  }
91 
99  inline MeasurementBasedTime::duration time_since_last_temporal_update(
100  const GlobalTime & time_point) const noexcept
101  {
102  return convert_to_measurement_time(time_point) - m_last_temporal_update;
103  }
111  inline MeasurementBasedTime::duration time_since_last_temporal_update(
112  const MeasurementBasedTime & time_point) const noexcept
113  {
114  return time_point - m_last_temporal_update;
115  }
116 
123  const MeasurementBasedTime::duration & time_since_last_update) noexcept
124  {
125  m_last_temporal_update += time_since_last_update;
126  }
127 
134  {
135  return std::max(m_last_measurement_timestamp, m_last_temporal_update);
136  }
137 
138 private:
147  inline MeasurementBasedTime convert_to_measurement_time(
148  const GlobalTime & global_time) const noexcept
149  {
150  return m_last_measurement_timestamp + (global_time - m_time_last_measurement_received);
151  }
152 
154  GlobalTime m_time_last_measurement_received{};
156  MeasurementBasedTime m_last_measurement_timestamp{};
159  MeasurementBasedTime m_last_temporal_update{};
160 };
161 
162 
163 } // namespace prediction
164 } // namespace autoware
165 
166 #endif // STATE_ESTIMATION_NODES__MEASUREMENT_TIME_KEEPER_HPP_
autoware::prediction::MeasurementBasedTime
Time< TimeReferenceFrame::kMeasurement > MeasurementBasedTime
Utility typedef to define time based on a measurement clock.
Definition: time.hpp:138
types.hpp
This file includes common type definition.
autoware::prediction::MeasurementBasedTimeKeeper::time_since_last_temporal_update
MeasurementBasedTime::duration time_since_last_temporal_update(const MeasurementBasedTime &time_point) const noexcept
Get the time since the last temporal update.
Definition: measurement_time_keeper.hpp:111
autoware::prediction::Time< TimeReferenceFrame::kGlobal >
autoware::common::types::bool8_t
bool bool8_t
Definition: types.hpp:33
autoware::prediction::MeasurementBasedTimeKeeper::is_initialized
common::types::bool8_t is_initialized() const noexcept
Determines if initialized with proper timestamps.
Definition: measurement_time_keeper.hpp:69
autoware
This file defines the lanelet2_map_provider_node class.
Definition: quick_sort.hpp:24
measurement.hpp
autoware::prediction::MeasurementBasedTimeKeeper
This is a time storage class that keeps the time with respect to the clock that timestamped the last ...
Definition: measurement_time_keeper.hpp:41
autoware::prediction::GlobalTime
Time< TimeReferenceFrame::kGlobal > GlobalTime
Utility typedef to define time based on some global clock.
Definition: time.hpp:140
autoware::prediction::MeasurementBasedTimeKeeper::time_since_last_temporal_update
MeasurementBasedTime::duration time_since_last_temporal_update(const GlobalTime &time_point) const noexcept
Get the time since the last temporal update in measurement clock frame.
Definition: measurement_time_keeper.hpp:99
autoware::prediction::MeasurementBasedTimeKeeper::increment_last_temporal_update_time
void increment_last_temporal_update_time(const MeasurementBasedTime::duration &time_since_last_update) noexcept
Increment the time of last temporal update by a given amount.
Definition: measurement_time_keeper.hpp:122
autoware::prediction::MeasurementBasedTimeKeeper::update_with_measurement
void update_with_measurement(const GlobalTime &time_of_event, const MeasurementT &measurement)
Update when a new measurement is received. This changes the base of calculation of the local time.
Definition: measurement_time_keeper.hpp:84
autoware::prediction::Time::is_valid
common::types::bool8_t is_valid() const noexcept
Determines if the stored time_point is valid.
Definition: time.hpp:67
autoware::prediction::MeasurementBasedTimeKeeper::MeasurementBasedTimeKeeper
MeasurementBasedTimeKeeper()=default
Allow empty initialization.
autoware::prediction::MeasurementBasedTimeKeeper::MeasurementBasedTimeKeeper
MeasurementBasedTimeKeeper(const GlobalTime &time_of_event, const MeasurementBasedTime &timestamp)
Constructs a new instance from the time the event has occured (measurement was received) and its time...
Definition: measurement_time_keeper.hpp:56
autoware::prediction::MeasurementBasedTimeKeeper::latest_timestamp
MeasurementBasedTime latest_timestamp() const noexcept
Get the latest stored timestamp.
Definition: measurement_time_keeper.hpp:133