20namespace localization {
24 : lidar_locator_(new LidarLocator()),
30 lidar_map_node_(nullptr),
33 map_node_pool_(25, 8),
35 is_map_loaded_(false),
36 vehicle_lidar_height_(1.7),
37 pre_vehicle_ground_height_(0.0),
38 is_pre_ground_height_valid_(false),
39 velodyne_extrinsic_(Eigen::Affine3d::Identity()) {
54 const unsigned int search_range_x,
55 const unsigned int search_range_y,
57 const unsigned int resolution_id) {
62 LOG(FATAL) <<
"Reflectance map folder is invalid!";
86 Eigen::Vector3d trans = pose.translation();
87 Eigen::Quaterniond quat = Eigen::Quaterniond(pose.linear());
89 lidar_locator_->SetVelodyneExtrinsic(trans.x(), trans.y(), trans.z(),
90 quat.x(), quat.y(), quat.z(), quat.w());
119 const Eigen::Affine3d& pose,
120 const Eigen::Vector3d velocity,
121 const LidarFrame& lidar_frame,
bool use_avx) {
127 AINFO <<
"Reflectance locator map first loading is done.";
130 Eigen::Affine3d imu_pose = pose;
133 Eigen::Vector3d pose_trans = imu_pose.translation();
134 Eigen::Quaterniond pose_quat(imu_pose.linear());
135 pose_quat.normalize();
147 int node_level_num = 1;
156 int size =
static_cast<int>(lidar_frame.
pt_xs.size());
158 size, lidar_frame.
pt_xs.data(), lidar_frame.
pt_ys.data(),
163 pose_trans(0), pose_trans(1), pose_trans(2), pose_quat.x(), pose_quat.y(),
164 pose_quat.z(), pose_quat.w(), use_avx);
170 Eigen::Matrix3d* covariance,
171 double* location_score) {
172 if (!location || !covariance) {
184 Eigen::Quaterniond quatd(qw, qx, qy, qz);
185 Eigen::Translation3d transd(Eigen::Vector3d(x, y, z));
186 *location = transd * quatd;
192 const double* data =
nullptr;
197 if (width >= 3 && height >= 3 && data !=
nullptr) {
198 for (
int row = 0; row < 3; ++row) {
199 for (
int col = 0; col < 3; ++col) {
200 (*covariance)(row, col) = data[row * 3 + col];
207 Eigen::MatrixXd* distribution) {
208 CHECK_NOTNULL(distribution);
212 const double* data =
nullptr;
215 if (width > 0 && height > 0 && data !=
nullptr) {
216 *distribution = Eigen::MatrixXd::Zero(height, width);
217 for (
int row = 0; row < height; ++row) {
218 for (
int col = 0; col < width; ++col) {
219 (*distribution)(row, col) = data[row * width + col];
229 Eigen::Vector3d lidar_trans = lidar_pose.translation();
246 float vehicle_ground_alt = 0.0f;
255 vehicle_ground_alt = *ground_alt;
260 vehicle_ground_alt = *altitude;
268 lidar_pose.translation()(2) = vehicle_ground_alt + height_diff;
270 pose->translation() = transform_tmp.translation();
274 Eigen::Vector2d center(trans(0), trans(1));
284 map_node_idx[0][1] = map_node_idx[0][0];
285 map_node_idx[0][1].
n_ += 1;
287 map_node_idx[1][0] = map_node_idx[0][0];
288 map_node_idx[1][0].
m_ += 1;
290 map_node_idx[1][1] = map_node_idx[0][0];
291 map_node_idx[1][1].
n_ += 1;
292 map_node_idx[1][1].
m_ += 1;
296 for (
unsigned int y = 0; y < 2; ++y) {
297 for (
unsigned int x = 0; x < 2; ++x) {
304 unsigned int coord_x = 0;
305 unsigned int coord_y = 0;
306 map_node[0][0]->
GetCoordinate(left_top_corner, &coord_x, &coord_y);
309 int coord_xi = coord_x;
310 int coord_yi = coord_y;
311 int range_xs[2][2] = {0};
312 int range_ys[2][2] = {0};
315 range_xs[0][1] = coord_xi;
316 range_xs[1][1] = coord_xi;
319 range_ys[1][0] = coord_yi;
320 range_ys[1][1] = coord_yi;
322 int src_xs[2][2] = {0};
323 int src_ys[2][2] = {0};
324 src_xs[0][0] = coord_xi;
325 src_xs[1][0] = coord_xi;
328 src_ys[0][0] = coord_yi;
329 src_ys[0][1] = coord_yi;
333 int dst_xs[2][2] = {0};
334 int dst_ys[2][2] = {0};
344 for (
int i = 0; i < 2; ++i) {
345 for (
int j = 0; j < 2; ++j) {
346 int range_x = range_xs[i][j];
347 int range_y = range_ys[i][j];
348 int src_x = src_xs[i][j];
349 int src_y = src_ys[i][j];
350 int dst_x = dst_xs[i][j];
351 int dst_y = dst_ys[i][j];
358 for (
int y = 0; y < range_y; ++y) {
360 for (
int x = 0; x < range_x; ++x) {
361 int dst_idx = dst_base_x + x;
363 (*intensity_matrix)[src_y + y][src_x + x];
365 (*intensity_var_matrix)[src_y + y][src_x + x];
367 (*altitude_matrix)[src_y + y][src_x + x];
369 (*count_matrix)[src_y + y][src_x + x];
double vehicle_lidar_height_
void SetLocalizationMode(int mode)
double pre_vehicle_ground_height_
unsigned int resolution_id_
int Update(const unsigned int frame_idx, const Eigen::Affine3d &pose, const Eigen::Vector3d velocity, const LidarFrame &lidar_frame, bool use_avx=false)
void SetDeltaYawLimit(double limit)
Eigen::Vector2d map_left_top_corner_
void SetImageAlignMode(int mode)
bool Init(const std::string &map_path, const unsigned int search_range_x, const unsigned int search_range_y, const int zone_id, const unsigned int resolution_id=0)
void GetResult(Eigen::Affine3d *location, Eigen::Matrix3d *covariance, double *location_score)
void ComposeMapNode(const Eigen::Vector3d &trans)
PyramidMapNodePool map_node_pool_
void SetVehicleHeight(double height)
MapNodeData * lidar_map_node_
Eigen::Affine3d velodyne_extrinsic_
bool is_pre_ground_height_valid_
void GetLocalizationDistribution(Eigen::MatrixXd *distribution)
~LocalizationLidar()
The deconstructor.
void SetDeltaPitchRollLimit(double limit)
void SetValidThreshold(float valid_threashold)
void SetVelodyneExtrinsic(const Eigen::Affine3d &pose)
void RefineAltitudeFromMap(Eigen::Affine3d *pose)
LidarLocator * lidar_locator_
LocalizationLidar()
The constructor.
unsigned int map_node_size_y_
The map node size in pixels.
std::vector< float > map_resolutions_
The pixel resolutions in the map in meters.
unsigned int map_node_size_x_
The map node size in pixels.
void Initial(const BaseMapConfig *map_config, bool is_fixed_size=true)
Initialize the pool.
const BaseMapMatrix & GetMapCellMatrix() const
Get map cell matrix.
bool SetMapFolderPath(const std::string folder_path)
Set the directory of the map.
BaseMapNode * GetMapNodeSafe(const MapNodeIndex &index)
Return the map node, if it's not in the cache, safely load it.
virtual void InitMapNodeCaches(int cacheL1_size, int cahceL2_size)
const BaseMapConfig & GetMapConfig() const
Get the map config.
virtual bool LoadMapArea(const Eigen::Vector3d &seed_pt3d, unsigned int resolution_id, unsigned int zone_id, int filter_size_x, int filter_size_y)
Load map nodes for the location calculate of this frame.
virtual void PreloadMapArea(const Eigen::Vector3d &location, const Eigen::Vector3d &trans_diff, unsigned int resolution_id, unsigned int zone_id)
Preload map nodes for the next frame location calculation.
void AttachMapNodePool(BaseMapNodePool *p_map_node_pool)
Attach map node pointer.
unsigned int m_
The map node ID at the northing direction.
unsigned int n_
The map node ID at the easting direction.
static MapNodeIndex GetMapNodeIndex(const BaseMapConfig &option, const Eigen::Vector3d &coordinate, unsigned int resolution_id, int zone_id)
Construct a map node index, given a global coordinate, eigen version.
FloatMatrix * GetIntensityMatrix(unsigned int level=0)
const float * GetAltitudeSafe(unsigned int row, unsigned int col, unsigned int level=0) const
Get an altitude value by check.
FloatMatrix * GetIntensityVarMatrix(unsigned int level=0)
const unsigned int * GetCountSafe(unsigned int row, unsigned int col, unsigned int level=0) const
Get a count value by check.
bool HasGroundAltitude() const
UIntMatrix * GetCountMatrix(unsigned int level=0)
FloatMatrix * GetAltitudeMatrix(unsigned int level=0)
const float * GetGroundAltitudeSafe(unsigned int row, unsigned int col, unsigned int level=0) const
Get an altitude ground value by check.
bool GetCoordinate(const Eigen::Vector2d &coordinate, unsigned int level, unsigned int *x, unsigned int *y) const
Given the global coordinate, get the local 2D coordinate of the map cell matrix.
std::vector< double > pt_ys
std::vector< double > pt_xs
std::vector< unsigned char > intensities
std::vector< double > pt_zs