@@ -63,7 +63,6 @@ bool LaserMapping::LoadParams(ros::NodeHandle &nh) {
6363 std::vector<double > extrinT_IMU_BOT{3 , 0.0 }; // lidar-imu translation
6464 std::vector<double > extrinR_IMU_BOT{9 , 0.0 }; // lidar-imu rotation
6565
66- nh.param <bool >(" icp/use_icp" , use_icp_, false );
6766 nh.param <bool >(" path_save_en" , path_save_en_, true );
6867 nh.param <bool >(" publish/path_publish_en" , path_pub_en_, true );
6968 nh.param <bool >(" publish/scan_publish_en" , scan_pub_en_, true );
@@ -129,11 +128,6 @@ bool LaserMapping::LoadParams(ros::NodeHandle &nh) {
129128 ivox_options_.nearby_type_ = IVoxType::NearbyType::NEARBY18;
130129 }
131130
132- if (use_icp_)
133- {
134- init_localization_ = true ;
135- }
136-
137131 path_.header .stamp = ros::Time::now ();
138132 path_.header .frame_id = " odom" ;
139133
@@ -402,71 +396,6 @@ void LaserMapping::Run() {
402396 return ;
403397 }
404398
405- if (use_icp_ && init_localization_)
406- {
407- if (!relocalization_.IsInit ())
408- relocalization_.InitParams (nh_, color_info_);
409-
410- if (lidar_buffer_.size () < 10 )
411- // if (lidar_buffer_.empty())
412- return ;
413-
414- LOG (INFO) << " Localization Initing!" ;
415- PointCloudType::Ptr cloud_xyzi (new PointCloudType ());
416-
417- mtx_buffer_.lock ();
418- for (int i = 0 ; i < 10 ; i++)
419- {
420- *cloud_xyzi += *(lidar_buffer_.back ());
421- lidar_buffer_.pop_back ();
422- }
423- // cloud_xyzi = lidar_buffer_.back();
424- lidar_buffer_.clear ();
425- time_buffer_.clear ();
426- imu_buffer_.clear ();
427- imu_buf_.clear ();
428- mtx_buffer_.unlock ();
429-
430- int size = cloud_xyzi->size ();
431- pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_xyz (new pcl::PointCloud<pcl::PointXYZ>(size, 1 ));
432- int i = 0 ;
433- for (const PointType& point_xyzi : *cloud_xyzi)
434- {
435- common::V3D p_lidar (point_xyzi.x , point_xyzi.y , point_xyzi.z );
436- common::V3D p_BOT (R_wrt_ * p_lidar + T_wrt_);
437-
438- pcl::PointXYZ point_xyz;
439- point_xyz.x = p_BOT (0 );
440- point_xyz.y = p_BOT (1 );
441- point_xyz.z = p_BOT (2 );
442- cloud_xyz->points [i] = point_xyz;
443- i++;
444- }
445-
446- Eigen::Isometry3d result = Eigen::Isometry3d::Identity ();
447- if (relocalization_.InitExtrinsic (result, cloud_xyz))
448- {
449- icp_R_wrt_ = result.rotation ();
450- icp_T_wrt_ = result.translation ();
451- R_wrt_ = result.rotation () * R_wrt_;
452- T_wrt_ = result.rotation () * T_wrt_ + result.translation ();
453- R_wrt_inv_ = R_wrt_.inverse ();
454- init_localization_ = false ;
455- // relocalization_.clear();
456- LOG (INFO) << " \033 [1;32m----> Init Localization Finished.\033 [0m" ;
457- lidar_buffer_.clear ();
458- time_buffer_.clear ();
459- imu_buffer_.clear ();
460- imu_buf_.clear ();
461- }
462- else
463- {
464- LOG (WARNING) << " ----> Init Localization Failed!" ;
465- }
466-
467- return ;
468- }
469-
470399 if (!SyncPackages ()) {
471400 if (flg_first_odom_ && IMUUpdate ())
472401 {
@@ -533,8 +462,20 @@ void LaserMapping::Run() {
533462
534463 state_imu_ = state_point_;
535464 imu_buf_ = imu_buffer_;
536- sensor_msgs::Imu::Ptr msg (new sensor_msgs::Imu (*(measures_.imu_ .back ())));
537- msg->header .stamp = ros::Time ().fromSec (measures_.lidar_end_time_ );
465+ sensor_msgs::Imu::Ptr msg;
466+ if (!measures_.imu_ .empty ()) {
467+ msg = sensor_msgs::Imu::Ptr (new sensor_msgs::Imu (*(measures_.imu_ .back ())));
468+ msg->header .stamp = ros::Time ().fromSec (measures_.lidar_end_time_ );
469+ } else {
470+ msg = sensor_msgs::Imu::Ptr (new sensor_msgs::Imu ());
471+ msg->header .stamp = ros::Time ().fromSec (measures_.lidar_end_time_ );
472+ msg->angular_velocity .x = 0 ;
473+ msg->angular_velocity .y = 0 ;
474+ msg->angular_velocity .z = 0 ;
475+ msg->linear_acceleration .x = 0 ;
476+ msg->linear_acceleration .y = 0 ;
477+ msg->linear_acceleration .z = 0 ;
478+ }
538479 last_imu_ = msg;
539480 flg_first_odom_ = true ;
540481
@@ -550,7 +491,7 @@ void LaserMapping::Run() {
550491 if (scan_pub_en_ || pcd_save_en_) {
551492 PublishFrameWorld ();
552493 }
553- if (use_icp_ || ( scan_pub_en_ && scan_body_pub_en_) ) {
494+ if (scan_pub_en_ && scan_body_pub_en_) {
554495 PublishFrameBody (pub_laser_cloud_body_);
555496 }
556497 if (scan_pub_en_ && scan_effect_pub_en_) {
@@ -881,8 +822,6 @@ void LaserMapping::PublishOdometry(const ros::Publisher &pub_odom_aft_mapped, na
881822 odom_lidar.pose .pose .orientation .z );
882823 common::M3D init_R_lidar = eigen_quat.toRotationMatrix ();
883824 common::M3D MAP_R_BOT = BOT_R_wrt_IMU_ * init_R_lidar * IMU_R_wrt_BOT_;
884- if (use_icp_)
885- MAP_R_BOT = icp_R_wrt_ * MAP_R_BOT;
886825
887826 // 转换为tf与odom
888827 Eigen::Quaterniond q (MAP_R_BOT);
@@ -895,8 +834,6 @@ void LaserMapping::PublishOdometry(const ros::Publisher &pub_odom_aft_mapped, na
895834 odom_lidar.pose .pose .position .z );
896835 common::V3D MAP_T_lidar (BOT_R_wrt_IMU_ * init_T_lidar + BOT_T_wrt_IMU_);
897836 common::V3D MAP_T_BOT (MAP_T_lidar - MAP_R_BOT * BOT_T_wrt_IMU_);
898- if (use_icp_)
899- MAP_T_BOT = icp_R_wrt_ * MAP_T_BOT + icp_T_wrt_;
900837
901838 odom_base.pose .pose .position .x = MAP_T_BOT (0 );
902839 odom_base.pose .pose .position .y = MAP_T_BOT (1 );
0 commit comments