Skip to content

Commit

Permalink
update the pcd saving to one map
Browse files Browse the repository at this point in the history
  • Loading branch information
XW-HKU committed Jul 6, 2021
1 parent bd88639 commit ae6a013
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
1 change: 1 addition & 0 deletions PCD/1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ Connect to your PC to Livox Avia LiDAR by following [Livox-ros-driver installat

### 3.2 For Livox serials with external IMU

mapping_avia.launch theratically supports mid-70, mid-40 or other livox serial lidar, but need to setup some parameters befor run:
mapping_avia.launch theratically supports mid-70, mid-40 or other livox serial LiDAR, but need to setup some parameters befor run:

Edit ``` config/avia.yaml ``` to set the below parameters:

1. lidar point cloud topic name: ``` lid_topic ```
1. LiDAR point cloud topic name: ``` lid_topic ```
2. IMU topic name: ``` imu_topic ```
3. Translational extrinsic: ``` extrinsic_T ```
4. Rotational extrinsic: ``` extrinsic_R ``` (only support rotation matrix)
Expand All @@ -117,7 +117,7 @@ Step A: Setup before run

Edit ``` config/velodyne.yaml ``` to set the below parameters:

1. lidar point cloud topic name: ``` lid_topic ```
1. LiDAR point cloud topic name: ``` lid_topic ```
2. IMU topic name: ``` imu_topic ``` (both internal and external, 6-aixes or 9-axies are fine)
3. Line number (we tested 16 and 32 line, but not tested 64 or above): ``` scan_line ```
4. Translational extrinsic: ``` extrinsic_T ```
Expand All @@ -138,7 +138,7 @@ Step C: Run LiDAR's ros driver or play rosbag.

### 3.4 PCD file save

Set ``` pcd_save_enable ``` in launchfile to ``` 1 ```, every frame will be saved as an independent .PCD file in ``` FAST_LIO/PCD/ ``` directory.
Set ``` pcd_save_enable ``` in launchfile to ``` 1 ```. All the scans (in global frame) will be accumulated and saved to the file ``` FAST_LIO/PCD/scans.pcd ``` after the FAST-LIO is terminated.

## 4. Rosbag Example
### 4.1 Indoor rosbag (Livox Avia LiDAR)
Expand Down
27 changes: 17 additions & 10 deletions src/laserMapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ void map_incremental()
}

PointCloudXYZI::Ptr pcl_wait_pub(new PointCloudXYZI(500000, 1));
int ind = 0;
PointCloudXYZI::Ptr pcl_wait_save(new PointCloudXYZI());
void publish_frame_world(const ros::Publisher & pubLaserCloudFullRes)
{
PointCloudXYZI::Ptr laserCloudFullRes(dense_map_en ? feats_undistort : feats_down_body);
Expand All @@ -434,30 +434,25 @@ void publish_frame_world(const ros::Publisher & pubLaserCloudFullRes)
&laserCloudWorld->points[i]);
}

*pcl_wait_pub += *laserCloudWorld;
// *pcl_wait_pub += *laserCloudWorld;
if(1)
{
sensor_msgs::PointCloud2 laserCloudmsg;
pcl::toROSMsg(*pcl_wait_pub, laserCloudmsg);
pcl::toROSMsg(*laserCloudWorld, laserCloudmsg);
laserCloudmsg.header.stamp = ros::Time::now();
laserCloudmsg.header.frame_id = "camera_init";
pubLaserCloudFullRes.publish(laserCloudmsg);
publish_count -= PUBFRAME_PERIOD;
pcl_wait_pub->clear();
// pcl_wait_pub->clear();
}

/**************** save map ****************/
/* 1. make sure you have enough memories
/* 2. pcd save will largely influence the real-time performences **/
if (laserCloudWorld->size() > 0 && pcd_save_en)
{
string file_name = string("scans_"+to_string(ind)+".pcd");
string all_points_dir(string(string(ROOT_DIR) + "PCD/") + file_name);
pcl::PCDWriter pcd_writer;
cout << "current scan saved to /PCD/" << file_name<<endl;
pcd_writer.writeBinary(all_points_dir, *laserCloudWorld);
*pcl_wait_save += *laserCloudWorld;
}
ind ++;
}

void publish_effect_world(const ros::Publisher & pubLaserCloudEffect)
Expand Down Expand Up @@ -898,6 +893,18 @@ int main(int argc, char** argv)
rate.sleep();
}

/**************** save map ****************/
/* 1. make sure you have enough memories
/* 2. pcd save will largely influence the real-time performences **/
if (pcl_wait_save->size() > 0 && pcd_save_en)
{
string file_name = string("scans.pcd");
string all_points_dir(string(string(ROOT_DIR) + "PCD/") + file_name);
pcl::PCDWriter pcd_writer;
cout << "current scan saved to /PCD/" << file_name<<endl;
pcd_writer.writeBinary(all_points_dir, *pcl_wait_save);
}

fout_out.close();
fout_pre.close();

Expand Down
3 changes: 3 additions & 0 deletions src/preprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ void Preprocess::give_feature(pcl::PointCloud<PointType> &pl, vector<orgtype> &t
ap.x = pl[j].x;
ap.y = pl[j].y;
ap.z = pl[j].z;
ap.intensity = pl[j].intensity;
ap.curvature = pl[j].curvature;
pl_surf.push_back(ap);

Expand All @@ -744,11 +745,13 @@ void Preprocess::give_feature(pcl::PointCloud<PointType> &pl, vector<orgtype> &t
ap.x += pl[k].x;
ap.y += pl[k].y;
ap.z += pl[k].z;
ap.intensity += pl[k].intensity;
ap.curvature += pl[k].curvature;
}
ap.x /= (j-last_surface);
ap.y /= (j-last_surface);
ap.z /= (j-last_surface);
ap.intensity /= (j-last_surface);
ap.curvature /= (j-last_surface);
pl_surf.push_back(ap);
}
Expand Down

0 comments on commit ae6a013

Please sign in to comment.