Apollo 10.0
自动驾驶开放平台
trigger_base.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2019 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
18
19#include "cyber/common/log.h"
21
22namespace apollo {
23namespace data {
24
25bool TriggerBase::Init(const SmartRecordTrigger& trigger_conf) {
26 LockTrigger(trigger_conf);
27 if (trigger_obj_ == nullptr) {
28 AERROR << "failed to lock trigger " << GetTriggerName();
29 return false;
30 }
31 return true;
32}
33
34uint64_t TriggerBase::SecondsToNanoSeconds(const double seconds) const {
35 static constexpr uint64_t kSecondsToNanoSecondsFactor = 1000000000UL;
36 return static_cast<uint64_t>(kSecondsToNanoSecondsFactor * seconds);
37}
38
39void TriggerBase::LockTrigger(const SmartRecordTrigger& trigger_conf) {
40 for (const auto& trigger : trigger_conf.triggers()) {
41 if (trigger.trigger_name() == trigger_name_) {
42 trigger_obj_.reset(new Trigger(trigger));
43 break;
44 }
45 }
46}
47
48uint64_t TriggerBase::GetValidValueInRange(const double desired_value,
49 const double min_limit,
50 const double max_limit) const {
51 return SecondsToNanoSeconds(desired_value < min_limit
52 ? min_limit
53 : desired_value > max_limit ? max_limit
54 : desired_value);
55}
56
57void TriggerBase::TriggerIt(const uint64_t msg_time) const {
58 static constexpr float kMaxBackwardTime = 80.0;
59 static constexpr float kMaxForwardTime = 80.0;
60 static constexpr uint64_t kZero = 0.0;
61 const uint64_t backward_time = GetValidValueInRange(
62 trigger_obj_->backward_time(), kZero, kMaxBackwardTime);
63 const uint64_t forward_time = GetValidValueInRange(
64 trigger_obj_->forward_time(), kZero, kMaxForwardTime);
65 IntervalPool::Instance()->AddInterval(msg_time - backward_time,
66 msg_time + forward_time);
67 IntervalPool::Instance()->LogIntervalEvent(
68 trigger_obj_->trigger_name(), trigger_obj_->description(), msg_time,
69 backward_time, forward_time);
70}
71
72} // namespace data
73} // namespace apollo
uint64_t GetValidValueInRange(const double desired_value, const double min_limit, const double max_limit) const
uint64_t SecondsToNanoSeconds(const double seconds) const
const std::string & GetTriggerName() const
std::unique_ptr< Trigger > trigger_obj_
virtual bool Init(const SmartRecordTrigger &trigger_conf)
void TriggerIt(const uint64_t msg_time) const
#define AERROR
Definition log.h:44
class register implement
Definition arena_queue.h:37