Skip to content

Commit

Permalink
ROS2 migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris7462 committed Nov 7, 2022
1 parent 9fdb2ca commit 8b1bd87
Show file tree
Hide file tree
Showing 41 changed files with 2,237 additions and 2,274 deletions.
138 changes: 101 additions & 37 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,65 +1,129 @@
cmake_minimum_required(VERSION 2.8.3)
cmake_minimum_required(VERSION 3.5)
project(floam)

set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_CXX_FLAGS "-std=c++11")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wall -g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wall -g -pthread")

find_package(catkin REQUIRED COMPONENTS
geometry_msgs
nav_msgs
sensor_msgs
roscpp
rospy
rosbag
std_msgs
tf
eigen_conversions
)
# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()

find_package(Eigen3)
if(NOT EIGEN3_FOUND)
# Fallback to cmake_modules
find_package(cmake_modules REQUIRED)
find_package(Eigen REQUIRED)
set(EIGEN3_INCLUDE_DIRS ${EIGEN_INCLUDE_DIRS})
set(EIGEN3_LIBRARIES ${EIGEN_LIBRARIES}) # Not strictly necessary as Eigen is head only
# Possibly map additional variables to the EIGEN3_ prefix.
else()
set(EIGEN3_INCLUDE_DIRS ${EIGEN3_INCLUDE_DIR})
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)
find_package(rclcpp REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(tf2 REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(pcl_conversions REQUIRED)
find_package(PCL REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(Ceres REQUIRED)

include_directories(
include
${catkin_INCLUDE_DIRS}
${PCL_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIR}
${CERES_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIRS}
)

link_directories(
include
${PCL_LIBRARY_DIRS}
${CERES_LIBRARY_DIRS}
)

add_executable(laser_processing_node
src/laser_processing_node.cpp
src/laser_processing.cpp
src/laser_processing_class.cpp
src/lidar.cpp
)

catkin_package(
CATKIN_DEPENDS geometry_msgs nav_msgs roscpp rospy std_msgs
DEPENDS EIGEN3 PCL Ceres
INCLUDE_DIRS include
ament_target_dependencies(laser_processing_node
rclcpp
sensor_msgs
pcl_conversions
)

target_link_libraries(laser_processing_node
${PCL_LIBRARIES}
)

add_executable(odom_estimation_node
src/odom_estimation_node.cpp
src/odom_estimation.cpp
src/odom_estimation_class.cpp
src/lidar_optimization.cpp
src/lidar.cpp
)

add_executable(floam_laser_processing_node src/laserProcessingNode.cpp src/laserProcessingClass.cpp src/lidar.cpp)
target_link_libraries(floam_laser_processing_node ${EIGEN3_LIBRARIES} ${catkin_LIBRARIES} ${PCL_LIBRARIES} ${CERES_LIBRARIES})
ament_target_dependencies(odom_estimation_node
rclcpp
sensor_msgs
nav_msgs
geometry_msgs
tf2
tf2_ros
pcl_conversions
Eigen3
#CERES
)

add_executable(floam_odom_estimation_node src/odomEstimationNode.cpp src/lidarOptimization.cpp src/lidar.cpp src/odomEstimationClass.cpp)
target_link_libraries(floam_odom_estimation_node ${EIGEN3_LIBRARIES} ${catkin_LIBRARIES} ${PCL_LIBRARIES} ${CERES_LIBRARIES})
target_link_libraries(odom_estimation_node
${PCL_LIBRARIES}
#${EIGEN3_LIBRARIES}
${CERES_LIBRARIES}
)

add_executable(floam_laser_mapping_node src/laserMappingNode.cpp src/laserMappingClass.cpp src/lidar.cpp)
target_link_libraries(floam_laser_mapping_node ${EIGEN3_LIBRARIES} ${catkin_LIBRARIES} ${PCL_LIBRARIES} ${CERES_LIBRARIES})
add_executable(laser_mapping_node
src/laser_mapping_node.cpp
src/laser_mapping.cpp
src/laser_mapping_class.cpp
src/lidar.cpp
)

ament_target_dependencies(laser_mapping_node
rclcpp
sensor_msgs
nav_msgs
pcl_conversions
Eigen3
)

target_link_libraries(laser_mapping_node
${PCL_LIBRARIES}
)

install(TARGETS laser_processing_node odom_estimation_node laser_mapping_node
DESTINATION lib/${PROJECT_NAME}
)

install(DIRECTORY launch
DESTINATION share/${PROJECT_NAME}
)

install(DIRECTORY rviz
DESTINATION share/${PROJECT_NAME}
)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# uncomment the line when a copyright and license is not present in all source files
#set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# uncomment the line when this package is not in a git repo
#set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()

ament_package()
85 changes: 35 additions & 50 deletions README.md → ReadMe.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# FLOAM
# FLOAM
## Fast LOAM (Lidar Odometry And Mapping)

This work is an optimized version of A-LOAM and LOAM with the computational cost reduced by up to 3 times.
This code is modified from [LOAM](https://github.com/laboshinl/loam_velodyne) and [A-LOAM](https://github.com/HKUST-Aerial-Robotics/A-LOAM) .

**Modifier:** [Wang Han](http://wanghan.pro), Nanyang Technological University, Singapore

**ROS2 Migration:** [Yi-Chen Zhang](chris7462.github.io/), Isuzu Technical Center of America, USA

## 1. Demo Highlights
Watch our demo at [Video Link](https://youtu.be/PzZly1SQtng)
<p align='center'>
Expand All @@ -17,7 +19,7 @@ Watch our demo at [Video Link](https://youtu.be/PzZly1SQtng)
## 2. Evaluation
### 2.1. Computational efficiency evaluation
Computational efficiency evaluation (based on KITTI dataset):
Platform: Intel® Core™ i7-8700 CPU @ 3.20GHz
Platform: Intel® Core™ i7-8700 CPU @ 3.20GHz
| Dataset | ALOAM | FLOAM |
|----------------------------------------------|----------------------------|------------------------|
| `KITTI` | 151ms | 59ms |
Expand All @@ -43,85 +45,68 @@ Localization error:

## 3. Prerequisites
### 3.1 **Ubuntu** and **ROS**
Ubuntu 64-bit 18.04.
Ubuntu 64-bit 20.04.

ROS Melodic. [ROS Installation](http://wiki.ros.org/ROS/Installation)
ROS2 Foxy. [ROS Installation](https://docs.ros.org/en/foxy/Installation.html)

### 3.2. **Ceres Solver**
Follow [Ceres Installation](http://ceres-solver.org/installation.html).
Please checkout to 2.0.0 tag. ROS2 migrated version doest not support Ceres 2.1.0 yet.

### 3.3. **PCL**
Follow [PCL Installation](http://www.pointclouds.org/downloads/linux.html).

### 3.4. **Trajectory visualization**
For visualization purpose, this package uses hector trajectory sever, you may install the package by
For PCL library, please install by the following:
```bash
sudo apt-get install libpcl-dev ros-foxy-pcl-ros
```
sudo apt-get install ros-melodic-hector-trajectory-server
```
Alternatively, you may remove the hector trajectory server node if trajectory visualization is not needed

## 4. Build
## 4. Build
### 4.1 Clone repository:
```
cd ~/catkin_ws/src
git clone https://github.com/wh200720041/floam.git
cd ..
catkin_make
source ~/catkin_ws/devel/setup.bash
```bash
cd ~/colcon_ws/src
git clone https://github.com/chris7462/floam.git
cd ..
colcon build
source ./install/setup.bash
```
### 4.2 Download test rosbag
Download [KITTI sequence 05](https://drive.google.com/file/d/1eyO0Io3lX2z-yYsfGHawMKZa5Z0uYJ0W/view?usp=sharing) or [KITTI sequence 07](https://drive.google.com/file/d/1_qUfwUw88rEKitUpt1kjswv7Cv4GPs0b/view?usp=sharing)

Unzip compressed file 2011_09_30_0018.zip. If your system does not have unzip. please install unzip by
Unzip compressed file 2011_09_30_0018.zip. If your system does not have unzip. please install unzip by
```
sudo apt-get install unzip
sudo apt-get install unzip
```

And this may take a few minutes to unzip the file
```bash
cd ~/Downloads
unzip ~/Downloads/2011_09_30_0018.zip
```
cd ~/Downloads
unzip ~/Downloads/2011_09_30_0018.zip
```
Then convert the ROS1 bag to ROS2 bag. See [here](https://ternaris.gitlab.io/rosbags/topics/convert.html) for reference

### 4.3 Launch ROS
```
roslaunch floam floam.launch
```bash
ros2 launch floam floam.launch.py
```
if you would like to create the map at the same time, you can run (more cpu cost)
```bash
ros2 launch floam floam_mapping.launch.py
```
roslaunch floam floam_mapping.launch
```
If the mapping process is slow, you may wish to change the rosbag speed by replacing "--clock -r 0.5" with "--clock -r 0.2" in your launch file, or you can change the map publish frequency manually (default is 10 Hz)

If the mapping process is slow, you may wish to change the rosbag speed by replacing "-r 0.5" with "-r 0.2" in your launch file, or you can change the map publish frequency manually (default is 10 Hz)

## 5. Test on other sequence
To generate rosbag file of kitti dataset, you may use the tools provided by
[kitti_to_rosbag](https://github.com/ethz-asl/kitti_to_rosbag) or [kitti2bag](https://github.com/tomas789/kitti2bag)

## 6. Test on Velodyne VLP-16 or HDL-32
You may wish to test FLOAM on your own platform and sensor such as VLP-16
You can install the velodyne sensor driver by
```
sudo apt-get install ros-melodic-velodyne-pointcloud
```
launch floam for your own velodyne sensor
```
roslaunch floam floam_velodyne.launch
```
If you are using HDL-32 or other sensor, please change the scan_line in the launch file


## 7.Acknowledgements
Thanks for [A-LOAM](https://github.com/HKUST-Aerial-Robotics/A-LOAM) and LOAM(J. Zhang and S. Singh. LOAM: Lidar Odometry and Mapping in Real-time) and [LOAM_NOTED](https://github.com/cuitaixiang/LOAM_NOTED).
To generate rosbag file of kitti dataset, you may use the tools provided by
[kitti_to_rosbag](https://github.com/ethz-asl/kitti_to_rosbag) or [kitti2bag](https://github.com/tomas789/kitti2bag)

## 6. Acknowledgements
Thanks for [A-LOAM](https://github.com/HKUST-Aerial-Robotics/A-LOAM) and LOAM (J. Zhang and S. Singh. LOAM: Lidar Odometry and Mapping in Real-time) and [LOAM_NOTED](https://github.com/cuitaixiang/LOAM_NOTED).

## 8. Citation
## 7. Citation
If you use this work for your research, you may want to cite
```
@inproceedings{wang2021,
author={H. {Wang} and C. {Wang} and C. {Chen} and L. {Xie}},
booktitle={2021 IEEE/RSJ International Conference on Intelligent Robots and Systems (IROS)},
title={F-LOAM : Fast LiDAR Odometry and Mapping},
booktitle={2021 IEEE/RSJ International Conference on Intelligent Robots and Systems (IROS)},
title={F-LOAM : Fast LiDAR Odometry and Mapping},
year={2020},
volume={},
number={}
Expand Down
49 changes: 49 additions & 0 deletions include/floam/laser_mapping_class.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Author of FLOAM: Wang Han
// ROS2 Migration: Yi-Chen Zhang

#pragma once

// pcl header
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/filters/voxel_grid.h>

// c++ header
#include <vector>

#define LASER_CELL_WIDTH 50.0
#define LASER_CELL_HEIGHT 50.0
#define LASER_CELL_DEPTH 50.0

// separate map as many sub point clouds

#define LASER_CELL_RANGE_HORIZONTAL 2
#define LASER_CELL_RANGE_VERTICAL 2


class LaserMappingClass
{
public:
LaserMappingClass() = default;
void init(double map_resolution);
void updateCurrentPointsToMap(const pcl::PointCloud<pcl::PointXYZI>::Ptr& pc_in, const Eigen::Isometry3d& pose_current);
pcl::PointCloud<pcl::PointXYZI>::Ptr getMap();

private:
int origin_in_map_x;
int origin_in_map_y;
int origin_in_map_z;
int map_width;
int map_height;
int map_depth;
std::vector<std::vector<std::vector<pcl::PointCloud<pcl::PointXYZI>::Ptr>>> map;
pcl::VoxelGrid<pcl::PointXYZI> downSizeFilter;

void addWidthCellNegative();
void addWidthCellPositive();
void addHeightCellNegative();
void addHeightCellPositive();
void addDepthCellNegative();
void addDepthCellPositive();
void checkPoints(int& x, int& y, int& z);
};
40 changes: 40 additions & 0 deletions include/floam/laser_mapping_node.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Author of FLOAM: Wang Han
// ROS2 Migration: Yi-Chen Zhang

#pragma once

// ros header
#include <rclcpp/rclcpp.hpp>
#include <sensor_msgs/msg/point_cloud2.hpp>
#include <nav_msgs/msg/odometry.hpp>

// c++ header
#include <mutex>
#include <queue>

// local header
#include "floam/lidar.hpp"
#include "floam/laser_mapping_class.hpp"


class LaserMappingNode: public rclcpp::Node
{
public:
LaserMappingNode();
void laser_mapping();

private:
LaserMappingClass laserMapping_;
std::queue<nav_msgs::msg::Odometry::ConstSharedPtr> odometryBuf_;
std::queue<sensor_msgs::msg::PointCloud2::ConstSharedPtr> pointCloudBuf_;
std::mutex mutex_lock_;
lidar::Lidar lidar_param_;

rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr subLaserCloud_;
rclcpp::Subscription<nav_msgs::msg::Odometry>::SharedPtr subOdometry_;

rclcpp::Publisher<sensor_msgs::msg::PointCloud2>::SharedPtr pubMap_;

void odomCallback(const nav_msgs::msg::Odometry::ConstSharedPtr odomMsg);
void velodyneHandler(const sensor_msgs::msg::PointCloud2::ConstSharedPtr laserCloudMsg);
};
Loading

0 comments on commit 8b1bd87

Please sign in to comment.