Apollo 11.0
自动驾驶开放平台
sensor.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 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 *****************************************************************************/
17
18#include "cyber/common/log.h"
19
20namespace apollo {
21namespace perception {
22namespace fusion {
23
24size_t Sensor::kMaxCachedFrameNum = 10;
25
26void Sensor::QueryLatestFrames(double timestamp,
27 std::vector<SensorFramePtr>* frames) {
28 if (frames == nullptr) {
29 AERROR << "frames are not available";
30 return;
31 }
32
33 frames->clear();
34 for (size_t i = 0; i < frames_.size(); ++i) {
35 if (frames_[i]->GetTimestamp() > latest_query_timestamp_ &&
36 frames_[i]->GetTimestamp() <= timestamp) {
37 frames->push_back(frames_[i]);
38 }
39 }
40 latest_query_timestamp_ = timestamp;
41}
42
44 SensorFramePtr latest_frame = nullptr;
45 for (size_t i = 0; i < frames_.size(); ++i) {
46 if (frames_[i]->GetTimestamp() > latest_query_timestamp_ &&
47 frames_[i]->GetTimestamp() <= timestamp) {
48 latest_frame = frames_[i];
49 latest_query_timestamp_ = frames_[i]->GetTimestamp();
50 }
51 }
52 return latest_frame;
53}
54
55bool Sensor::GetPose(double timestamp, Eigen::Affine3d* pose) const {
56 if (pose == nullptr) {
57 AERROR << "pose is not available";
58 return false;
59 }
60 for (int i = static_cast<int>(frames_.size()) - 1; i >= 0; --i) {
61 double time_diff = timestamp - frames_[i]->GetTimestamp();
62 if (fabs(time_diff) < 1.0e-3) { // > ?
63 return frames_[i]->GetPose(pose);
64 }
65 }
66
67 AWARN << "Failed to find pose for timestamp: " << timestamp;
68 return false;
69}
70
71void Sensor::AddFrame(const base::FrameConstPtr& frame_ptr) {
72 SensorFramePtr frame(new SensorFrame(frame_ptr));
73 if (frames_.size() == kMaxCachedFrameNum) {
74 frames_.pop_front();
75 }
76 frames_.emplace_back(frame);
77}
78
79} // namespace fusion
80} // namespace perception
81} // namespace apollo
SensorFramePtr QueryLatestFrame(double timestamp)
query latest frame whose time stamp is in range (_latest_fused_time_stamp, time_stamp]
Definition sensor.cc:43
void QueryLatestFrames(double timestamp, std::vector< SensorFramePtr > *frames)
query frames whose time stamp is in range (_latest_fused_time_stamp, time_stamp]
Definition sensor.cc:26
bool GetPose(double timestamp, Eigen::Affine3d *pose) const
Definition sensor.cc:55
void AddFrame(const base::FrameConstPtr &frame_ptr)
Definition sensor.cc:71
#define AERROR
Definition log.h:44
#define AWARN
Definition log.h:43
std::shared_ptr< const Frame > FrameConstPtr
Definition frame.h:61
std::shared_ptr< SensorFrame > SensorFramePtr
class register implement
Definition arena_queue.h:37