Apollo 10.0
自动驾驶开放平台
lidar_locator_ndt.h
浏览该文件的文档.
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 *****************************************************************************/
16
17#pragma once
18
19#include <string>
20#include <vector>
21
22#include "Eigen/Core"
23#include "Eigen/Geometry"
24#include "pcl/point_cloud.h"
25#include "pcl/point_types.h"
26
33
34#define USE_PRELOAD_MAP_NODE
35
36#ifdef VIS_USE_OPENCV
37#define VIS_USE_OPENCV_ON
38#endif
39#ifdef VIS_USE_OPENCV_ON
40#include <opencv2/opencv.hpp>
41void color_mapping(float value, float midvalue, unsigned char* r,
42 unsigned char* g, unsigned char* b) {
43 if (value > 1.f) {
44 value = 1.f;
45 } else if (value < 0.f) {
46 value = 0.f;
47 }
48 if (value > midvalue) {
49 value = (value - midvalue) / (1.f - midvalue);
50 *r = value * 255.0;
51 *g = (1.0 - value) * 255.0;
52 *b = 0.0;
53 } else {
54 value /= midvalue;
55 *r = 0.0;
56 *g = value * 255.0;
57 *b = (1 - value) * 255.0;
58 }
59}
60#endif
61
62namespace apollo {
63namespace localization {
64namespace ndt {
65
73
74struct LidarFrame {
76 double measurement_time; // unix time
77 std::vector<float> pt_xs;
78 std::vector<float> pt_ys;
79 std::vector<float> pt_zs;
80 std::vector<unsigned char> intensities;
81};
82
84 public:
89
91 void LoadMap(const Eigen::Affine3d& init_location, unsigned int resolution_id,
92 int zone_id);
94 void Init(const Eigen::Affine3d& init_location, unsigned int resolution_id,
95 int zone_id);
97 void SetMapFolderPath(const std::string folder_path);
99 void SetVelodyneExtrinsic(const Eigen::Affine3d& extrinsic);
101 void SetLidarHeight(double height);
102
104 void ComposeMapCells(const Eigen::Vector2d& left_top_coord2d, int zone_id,
105 unsigned int resolution_id, float map_pixel_resolution,
106 const Eigen::Affine3d& inverse_transform);
107
109 void SetOnlineCloudResolution(const float& online_resolution);
110
114 int Update(unsigned int frame_idx, const Eigen::Affine3d& pose,
115 const LidarFrame& lidar_frame);
117 Eigen::Affine3d GetPose() const;
118 /*@brief Get the predict location from the odometry motion model*/
119 Eigen::Vector3d GetPredictLocation() const;
121 Eigen::Matrix3d GetLocationCovariance() const;
123 inline bool IsInitialized() const { return is_initialized_; }
125 inline bool IsMaploaded() const { return is_map_loaded_; }
127 inline const NdtMap& GetMap() const { return map_; }
129 inline double GetFitnessScore() const { return fitness_score_; }
130
131 private:
133 bool is_initialized_ = false;
135 bool is_map_loaded_ = false;
136
138 Eigen::Affine3d location_;
140 Eigen::Matrix3d location_covariance_;
142 Eigen::Affine3d predict_location_;
144 Eigen::Affine3d pre_input_location_;
146 Eigen::Affine3d pre_estimate_location_;
147
149 unsigned int resolution_id_ = 0;
151 int zone_id_ = 10;
152
154 double lidar_height_ = 1.7;
156 double pre_imu_height_ = 0;
158 Eigen::Affine3d velodyne_extrinsic_;
159
161 int filter_x_ = 0;
162 int filter_y_ = 0;
164 float proj_reslution_ = 1.0;
165
167 NdtMapConfig config_;
169 NdtMap map_;
171 NdtMapNodePool map_preload_node_pool_;
173 std::vector<Leaf> cell_map_;
175 Eigen::Vector3d map_left_top_corner_;
178
180 double fitness_score_ = 0.0;
181
183 int ndt_max_iterations_ = 10;
184 double ndt_target_resolution_ = 1.0;
185 double ndt_line_search_step_size_ = 0.1;
186 double ndt_transformation_epsilon_ = 0.01;
187
188 public:
189 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
190};
191
192} // namespace ndt
193} // namespace localization
194} // namespace apollo
The data structure of ndt Map matrix.
The memory pool for the data structure of BaseMapNode.
void SetVelodyneExtrinsic(const Eigen::Affine3d &extrinsic)
Set the extrinsic calibration.
bool IsInitialized() const
Is the locator initialized.
void SetMapFolderPath(const std::string folder_path)
Set the map folder.
int Update(unsigned int frame_idx, const Eigen::Affine3d &pose, const LidarFrame &lidar_frame)
Update the histogram filter.
const NdtMap & GetMap() const
Get the locator map.
void Init(const Eigen::Affine3d &init_location, unsigned int resolution_id, int zone_id)
Initialize the locator.
void SetOnlineCloudResolution(const float &online_resolution)
Set online cloud resolution.
Eigen::Matrix3d GetLocationCovariance() const
Get the covariance of estimated location.
Eigen::Affine3d GetPose() const
Get the current optimal pose result.
void SetLidarHeight(double height)
Set the lidar height.
void ComposeMapCells(const Eigen::Vector2d &left_top_coord2d, int zone_id, unsigned int resolution_id, float map_pixel_resolution, const Eigen::Affine3d &inverse_transform)
Compose candidate map area.
bool IsMaploaded() const
Is the map data loaded.
void LoadMap(const Eigen::Affine3d &init_location, unsigned int resolution_id, int zone_id)
Load map data.
double GetFitnessScore() const
Get ndt matching score
apollo::localization::msf::pyramid_map::NdtMapConfig NdtMapConfig
apollo::localization::msf::pyramid_map::NdtMapCells NdtMapCells
apollo::localization::msf::pyramid_map::NdtMap NdtMap
apollo::localization::msf::pyramid_map::MapNodeIndex MapNodeIndex
apollo::localization::msf::pyramid_map::NdtMapMatrix NdtMapMatrix
apollo::localization::msf::pyramid_map::NdtMapNode NdtMapNode
apollo::localization::msf::pyramid_map::NdtMapNodePool NdtMapNodePool
class register implement
Definition arena_queue.h:37
std::vector< unsigned char > intensities