Apollo  6.0
Open source self driving car software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lidar_locator_ndt.h
Go to the documentation of this file.
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>
41 void 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 
62 namespace apollo {
63 namespace localization {
64 namespace ndt {
65 
73 
74 struct 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:
88  ~LidarLocatorNdt();
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
apollo::localization::msf::pyramid_map::NdtMapNode NdtMapNode
Definition: lidar_locator_ndt.h:68
const NdtMap & GetMap() const
Get the locator map.
Definition: lidar_locator_ndt.h:127
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
The data structure of ndt Map cell.
Definition: ndt_map_matrix.h:97
bool IsInitialized() const
Is the locator initialized.
Definition: lidar_locator_ndt.h:123
Eigen::Vector2d Vector2d
Definition: base_map_fwd.h:36
Eigen::Vector3d Vector3d
Definition: frame_transform.h:27
apollo::localization::msf::pyramid_map::NdtMapMatrix NdtMapMatrix
Definition: lidar_locator_ndt.h:71
double GetFitnessScore() const
Get ndt matching score.
Definition: lidar_locator_ndt.h:129
apollo::localization::msf::pyramid_map::NdtMapNodePool NdtMapNodePool
Definition: lidar_locator_ndt.h:70
double measurement_time
Definition: lidar_locator_ndt.h:76
bool IsMaploaded() const
Is the map data loaded.
Definition: lidar_locator_ndt.h:125
std::vector< unsigned char > intensities
Definition: lidar_locator_ndt.h:80
apollo::localization::msf::pyramid_map::MapNodeIndex MapNodeIndex
Definition: lidar_locator_ndt.h:72
std::vector< float > pt_xs
Definition: lidar_locator_ndt.h:77
Definition: lidar_locator_ndt.h:83
apollo::localization::msf::pyramid_map::NdtMapConfig NdtMapConfig
Definition: lidar_locator_ndt.h:67
bool Init(const char *binary_name)
std::vector< float > pt_zs
Definition: lidar_locator_ndt.h:79
apollo::localization::msf::pyramid_map::NdtMap NdtMap
Definition: lidar_locator_ndt.h:66
The options of the reflectance map.
Definition: ndt_map_config.h:29
apollo::cyber::base::std value
The memory pool for the data structure of BaseMapNode.
Definition: ndt_map_pool.h:30
std::vector< float > pt_ys
Definition: lidar_locator_ndt.h:78
Definition: base_map_node_index.h:33
Eigen::Affine3d Affine3d
Definition: base_map_fwd.h:34
Eigen::Matrix3d Matrix3d
Definition: base_map_fwd.h:33
The data structure of ndt Map matrix.
Definition: ndt_map_matrix.h:141
Definition: lidar_locator_ndt.h:74
LidarFrame()
Definition: lidar_locator_ndt.h:75
apollo::localization::msf::pyramid_map::NdtMapCells NdtMapCells
Definition: lidar_locator_ndt.h:69