Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single package.xml file for both ROS1 and ROS2 #48

Merged
merged 14 commits into from
Aug 27, 2024
56 changes: 17 additions & 39 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ project(rslidar_sdk)
#=======================================
set(POINT_TYPE XYZI)

#=======================================
# Compile setup (ORIGINAL, CATKIN, COLCON)
#=======================================
set(COMPILE_METHOD CATKIN)

option(ENABLE_TRANSFORM "Enable transform functions" OFF)
if(${ENABLE_TRANSFORM})
add_definitions("-DENABLE_TRANSFORM")
Expand Down Expand Up @@ -63,12 +58,7 @@ if (CMAKE_BUILD_TYPE STREQUAL "")
add_definitions(-O3)
endif()

if($ENV{ROS_DISTRO} STREQUAL "humble") # the ros2 humble requires c++17
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition, why is the restriction of ros version removed here?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im not sure, but as this software is C++17 compatible, @Timple set it c++17 as default.

For new ROS2 distros you would need to add it here (iron, jazzy and rolling) if new distros are released.

Also, as you are using cmake version > 3.1. Is better define these variables:
set (CMAKE_CXX_STANDARD 17)
https://cmake.org/cmake/help/latest/variable/CMAKE_CXX_STANDARD.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition, why is the restriction of ros version removed here?

It's not removed, it is still implicitly there. But the statement overlooked iron, jazzy and rolling. Currently humble is the oldest supported distro at the moment: ros_clock. So all can use c++17

add_definitions(-std=c++17)
else()
add_definitions(-std=c++14)
endif()

add_compile_options(-Wall)

#========================
Expand Down Expand Up @@ -103,21 +93,16 @@ if(roscpp_FOUND)
include_directories(${roscpp_INCLUDE_DIRS} ${roslib_INCLUDE_DIRS})
set(ROS_LIBS ${roscpp_LIBRARIES} ${roslib_LIBRARIES})

#Catkin#
if(${COMPILE_METHOD} STREQUAL "CATKIN")

add_definitions(-DRUN_IN_ROS_WORKSPACE)

find_package(catkin REQUIRED COMPONENTS
roscpp
sensor_msgs
roslib)
add_definitions(-DRUN_IN_ROS_WORKSPACE)

catkin_package(CATKIN_DEPENDS
sensor_msgs
roslib)
find_package(catkin REQUIRED COMPONENTS
roscpp
sensor_msgs
roslib)

endif(${COMPILE_METHOD} STREQUAL "CATKIN")
catkin_package(CATKIN_DEPENDS
sensor_msgs
roslib)

else(roscpp_FOUND)

Expand All @@ -130,8 +115,7 @@ endif(roscpp_FOUND)
#ROS2#
find_package(rclcpp QUIET)

if(rclcpp_FOUND AND ${COMPILE_METHOD} STREQUAL "COLCON")

if(rclcpp_FOUND)
message(=============================================================)
message("-- ROS2 Found. ROS2 Support is turned On.")
message(=============================================================)
Expand All @@ -145,13 +129,11 @@ if(rclcpp_FOUND AND ${COMPILE_METHOD} STREQUAL "COLCON")
find_package(rslidar_msg REQUIRED)
find_package(std_msgs REQUIRED)

else(rclcpp_FOUND AND ${COMPILE_METHOD} STREQUAL "COLCON")

else(rclcpp_FOUND)
message(=============================================================)
message("-- ROS2 Not Found. ROS2 Support is turned Off.")
message(=============================================================)

endif(rclcpp_FOUND AND ${COMPILE_METHOD} STREQUAL "COLCON")
endif(rclcpp_FOUND)

#Others#
find_package(yaml-cpp REQUIRED)
Expand Down Expand Up @@ -182,19 +164,15 @@ if(roscpp_FOUND)
target_link_libraries(rslidar_sdk_node
${ROS_LIBS})

if(${COMPILE_METHOD} STREQUAL "CATKIN")

install(TARGETS rslidar_sdk_node
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})

endif()
install(TARGETS rslidar_sdk_node
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})

endif(roscpp_FOUND)

#Ros2#
if(rclcpp_FOUND AND ${COMPILE_METHOD} STREQUAL "COLCON")
if(rclcpp_FOUND)

ament_target_dependencies(rslidar_sdk_node
rclcpp
Expand All @@ -213,5 +191,5 @@ if(rclcpp_FOUND AND ${COMPILE_METHOD} STREQUAL "COLCON")

ament_package()

endif(rclcpp_FOUND AND ${COMPILE_METHOD} STREQUAL "COLCON")
endif(rclcpp_FOUND)

32 changes: 2 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,7 @@ cmake .. && make -j4

### 4.2 Compile with ROS catkin tools

(1) On top of the file *CMakeLists.txt*,set the variable **COMPILE_METHOD** to **CATKIN**.

```cmake
#=======================================
# Compile setup (ORIGINAL,CATKIN,COLCON)
#=======================================
set(COMPILE_METHOD CATKIN)
```

(2) Copy the file *package_ros1.xml* to *package.xml* in the rslidar_sdk .

(3) Create a new workspace folder, and create a *src* folder in it. Then put the rslidar_sdk project into the *src* folder.

(4) Go back to the root of workspace, run the following commands to compile and run. (if using zsh, replace the 2nd command with *source devel/setup.zsh*).
(1) Run the following commands to compile and run. (if using zsh, replace the 2nd command with *source devel/setup.zsh*).

```sh
catkin_make
Expand All @@ -168,22 +155,7 @@ roslaunch rslidar_sdk start.launch

### 4.3 Compile with ROS2 colcon

(1) On top of the file *CMakeLists.txt*,set the variable **COMPILE_METHOD** to **COLCON**.

```cmake
#=======================================
# Compile setup (ORIGINAL,CATKIN,COLCON)
#=======================================
set(COMPILE_METHOD COLCON)
```

(2) Copy the file *package_ros2.xml* to *package.xml* in the rslidar_sdk.

(3) Create a new workspace folder, and create a *src* folder in it. Then put the rslidar_sdk project in the *src* folder.

(4) Download the packet definition project in ROS2 through [link](https://github.com/RoboSense-LiDAR/rslidar_msg), then put the project rslidar_msg in the *src* folder you just created.

(5) Go back to the root of workspace, run the following commands to compile and run. (if using zsh, replace the 2nd command with *source install/setup.zsh*).
(1) Run the following commands to compile and run. (if using zsh, replace the 2nd command with *source install/setup.zsh*).

```sh
colcon build
Expand Down
33 changes: 2 additions & 31 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,7 @@ cmake .. && make -j4

### 1.4.2 依赖于ROS-catkin编译

(1) 打开工程内的*CMakeLists.txt*文件,将文件顶部的变量**COMPILE_METHOD**改为**CATKIN**.


```cmake
#=======================================
# Compile setup (ORIGINAL,CATKIN,COLCON)
#=======================================
set(COMPILE_METHOD CATKIN)
```

(2) 将rslidar_sdk工程目录下的*package_ros1.xml*文件复制到*package.xml*。

(3) 新建一个文件夹作为工作空间,然后再新建一个名为*src*的文件夹, 将rslidar_sdk工程放入*src*文件夹内。

(4) 返回工作空间目录,执行以下命令即可编译、运行。如果使用.zsh,将第二行替换成 *source devel/setup.zsh*。
(1) 返回工作空间目录,执行以下命令即可编译&运行(若使用.zsh,将第二句指令替换为 *source devel/setup.zsh*)。

```sh
catkin_make
Expand All @@ -165,22 +151,7 @@ roslaunch rslidar_sdk start.launch

### 1.4.3 依赖于ROS2-colcon编译

(1) 打开工程内的*CMakeLists.txt*文件,将文件顶部的变量**COMPILE_METHOD**改为**COLCON**.

```cmake
#=======================================
# Compile setup (ORIGINAL,CATKIN,COLCON)
#=======================================
set(COMPILE_METHOD COLCON)
```

(2) 将rslidar_sdk工程目录下的*package_ros2.xml*文件重命名为*package.xml*。

(3) 新建一个文件夹作为工作空间,然后再新建一个名为*src*的文件夹, 将rslidar_sdk工程放入*src*文件夹内。

(4) 通过[链接](https://github.com/RoboSense-LiDAR/rslidar_msg),下载ROS2环境下的雷达packet消息定义,将rslidar_msg工程也放在刚刚新建的*src*文件夹内,与rslidar_sdk并列。

(5) 返回工作空间目录,执行以下命令即可编译、运行。如果使用.zsh,将第二行替换为*source install/setup.zsh*。
(1) 返回工作空间目录,执行以下命令即可编译&运行(若使用.zsh,将第二句指令替换为 *source install/setup.zsh*)。

```sh
colcon build
Expand Down
24 changes: 16 additions & 8 deletions package.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
<?xml version="1.0"?>
<package>
<package format="3">
<name>rslidar_sdk</name>
<version>1.5.15</version>
<description>The rslidar_sdk package</description>
<maintainer email="ron.zheng@robosense.cn">robosense</maintainer>
<license>BSD</license>
<buildtool_depend>catkin</buildtool_depend>

<build_depend>roscpp</build_depend>
<build_depend>sensor_msgs</build_depend>
<build_depend>roslib</build_depend>
<buildtool_depend condition="$ROS_VERSION == 1">catkin</buildtool_depend>
<buildtool_depend condition="$ROS_VERSION == 2">ament_cmake</buildtool_depend>

<run_depend>roscpp</run_depend>
<run_depend>sensor_msgs</run_depend>
<run_depend>roslib</run_depend>
<depend>libpcap</depend>
<depend condition="$ROS_VERSION == 1">pcl_ros</depend>
<depend condition="$ROS_VERSION == 2">rclcpp</depend>
<depend condition="$ROS_VERSION == 1">roscpp</depend>
<depend condition="$ROS_VERSION == 1">roslib</depend>
<depend condition="$ROS_VERSION == 2">rslidar_msg</depend>
<depend>sensor_msgs</depend>
<depend>std_msgs</depend>
<depend>yaml-cpp</depend>

<export>
<build_type condition="$ROS_VERSION == 2">ament_cmake</build_type>
</export>
</package>
17 changes: 0 additions & 17 deletions package_ros1.xml

This file was deleted.

21 changes: 0 additions & 21 deletions package_ros2.xml

This file was deleted.