Apollo 11.0
自动驾驶开放平台
sensor_data_manager.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 <algorithm>
19#include <utility>
20
21#include "cyber/common/log.h"
23
24namespace apollo {
25namespace perception {
26namespace fusion {
27
28SensorDataManager::SensorDataManager() { CHECK_EQ(this->Init(), true); }
29
31 if (inited_) {
32 return true;
33 }
34 sensor_manager_ = algorithm::SensorManager::Instance();
35 inited_ = true;
36 return true;
37}
38
40 inited_ = false;
41 sensor_manager_ = nullptr;
42 sensors_.clear();
43}
44
46 const base::FrameConstPtr& frame_ptr) {
47 const base::SensorInfo& sensor_info = frame_ptr->sensor_info;
48 std::string sensor_id = sensor_info.name;
49 const auto it = sensors_.find(sensor_id);
50 SensorPtr sensor_ptr = nullptr;
51 if (it == sensors_.end()) {
52 if (!sensor_manager_->IsSensorExist(sensor_id)) {
53 AERROR << "Failed to find sensor " << sensor_id << " in sensor manager.";
54 return;
55 }
56 sensor_ptr.reset(new Sensor(sensor_info));
57 sensors_.emplace(sensor_id, sensor_ptr);
58 } else {
59 sensor_ptr = it->second;
60 }
61
62 sensor_ptr->AddFrame(frame_ptr);
63}
64
66 base::SensorType type = frame_ptr->sensor_info.type;
67 return sensor_manager_->IsLidar(type);
68}
69
71 base::SensorType type = frame_ptr->sensor_info.type;
72 return sensor_manager_->IsRadar(type);
73}
74
76 base::SensorType type = frame_ptr->sensor_info.type;
77 return sensor_manager_->IsCamera(type);
78}
79
81 double timestamp, const std::string& sensor_id,
82 std::vector<SensorFramePtr>* frames) const {
83 if (frames == nullptr) {
84 AERROR << "Nullptr error.";
85 return;
86 }
87 const auto it = sensors_.find(sensor_id);
88 if (it == sensors_.end()) {
89 return;
90 }
91 return it->second->QueryLatestFrames(timestamp, frames);
92}
93
95 double timestamp, std::vector<SensorFramePtr>* frames) const {
96 if (frames == nullptr) {
97 AERROR << "Nullptr error.";
98 return;
99 }
100
101 frames->clear();
102 for (auto it = sensors_.begin(); it != sensors_.end(); ++it) {
103 SensorFramePtr frame = it->second->QueryLatestFrame(timestamp);
104 if (frame != nullptr) {
105 frames->push_back(frame);
106 }
107 }
108
109 if (frames->empty()) {
110 return;
111 }
112
113 std::sort(frames->begin(), frames->end(),
114 [](const SensorFramePtr& p1, const SensorFramePtr& p2) {
115 return p1->GetTimestamp() < p2->GetTimestamp();
116 });
117}
118
119bool SensorDataManager::GetPose(const std::string& sensor_id, double timestamp,
120 Eigen::Affine3d* pose) const {
121 if (pose == nullptr) {
122 AERROR << "Nullptr error.";
123 return false;
124 }
125
126 const auto it = sensors_.find(sensor_id);
127 if (it == sensors_.end()) {
128 AERROR << "Failed to find sensor " << sensor_id << " for get pose.";
129 return false;
130 }
131
132 return it->second->GetPose(timestamp, pose);
133}
134
136 const std::string& sensor_id) const {
137 return sensor_manager_->GetUndistortCameraModel(sensor_id);
138}
139
140} // namespace fusion
141} // namespace perception
142} // namespace apollo
bool IsRadar(const std::string &name) const
bool IsCamera(const std::string &name) const
bool IsSensorExist(const std::string &name) const
std::shared_ptr< BaseCameraModel > GetUndistortCameraModel(const std::string &name) const
bool IsLidar(const std::string &name) const
void GetLatestSensorFrames(double timestamp, const std::string &sensor_id, std::vector< SensorFramePtr > *frames) const
Get the latest sensor frames
bool IsRadar(const base::FrameConstPtr &frame_ptr)
Is the data frame detected by radar
bool IsLidar(const base::FrameConstPtr &frame_ptr)
Is the data frame detected by lidar
void GetLatestFrames(double timestamp, std::vector< SensorFramePtr > *frames) const
Get the latest sensor frames
bool GetPose(const std::string &sensor_id, double timestamp, Eigen::Affine3d *pose) const
Get the Pose object
bool IsCamera(const base::FrameConstPtr &frame_ptr)
Is the data frame detected by camera
base::BaseCameraModelPtr GetCameraIntrinsic(const std::string &sensor_id) const
Get the Camera Intrinsic object
void AddSensorMeasurements(const base::FrameConstPtr &frame_ptr)
Add the data frame, which contains the obstacles detected by the sensor
#define AERROR
Definition log.h:44
std::shared_ptr< BaseCameraModel > BaseCameraModelPtr
Definition camera.h:75
SensorType
Sensor types are set in the order of lidar, radar, camera, ultrasonic Please make sure SensorType has...
Definition sensor_meta.h:29
std::shared_ptr< const Frame > FrameConstPtr
Definition frame.h:61
std::shared_ptr< SensorFrame > SensorFramePtr
std::shared_ptr< Sensor > SensorPtr
class register implement
Definition arena_queue.h:37