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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ cmake-build-debug/
version.h
*.pb.cc
*.pb.h
package.xml
49 changes: 20 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ cmake_minimum_required(VERSION 3.5)
cmake_policy(SET CMP0048 NEW)
project(rslidar_sdk)

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

#=======================================
# Custom Point Type (XYZI, XYZIRT)
#=======================================
Expand All @@ -32,7 +27,6 @@ if(roscpp_FOUND)
message("-- ROS Found, Ros Support is turned On!")
message(=============================================================)
add_definitions(-DROS_FOUND)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/package_ros1.xml ${CMAKE_CURRENT_SOURCE_DIR}/package.xml COPYONLY)

find_package(roslib QUIET)
include_directories(${roscpp_INCLUDE_DIRS} ${roslib_INCLUDE_DIRS})
Expand All @@ -46,12 +40,11 @@ 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(=============================================================)
add_definitions(-DROS2_FOUND)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/package_ros2.xml ${CMAKE_CURRENT_SOURCE_DIR}/package.xml COPYONLY)
set(CMAKE_CXX_STANDARD 14)

find_package(ament_cmake REQUIRED)
Expand All @@ -61,11 +54,11 @@ if(rclcpp_FOUND AND ${COMPILE_METHOD} STREQUAL "COLCON")
find_package(pcl_conversions REQUIRED)
include_directories(${rclcpp_INCLUDE_DIRS})

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)

#Protobuf#
find_package(Protobuf QUIET)
Expand Down Expand Up @@ -100,7 +93,7 @@ link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

#Catkin#
if(${COMPILE_METHOD} STREQUAL "CATKIN")
if(roscpp_FOUND)
add_definitions(-DRUN_IN_ROS_WORKSPACE)
find_package(catkin REQUIRED
COMPONENTS
Expand All @@ -118,7 +111,7 @@ if(${COMPILE_METHOD} STREQUAL "CATKIN")
roslib
pcl_conversions
)
endif(${COMPILE_METHOD} STREQUAL "CATKIN")
endif(roscpp_FOUND)

#Include directory#
include_directories(${PROJECT_SOURCE_DIR}/src)
Expand Down Expand Up @@ -173,25 +166,23 @@ endif(NOT PROTOC MATCHES "NOTFOUND" AND Protobuf_FOUND)
#Ros#
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})
install(DIRECTORY launch/
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/launch
PATTERN ".svn" EXCLUDE)
install(DIRECTORY config/
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/config
PATTERN ".svn" EXCLUDE)
install(DIRECTORY rviz/
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/rviz
PATTERN ".svn" EXCLUDE)
endif()
install(TARGETS rslidar_sdk_node
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})
install(DIRECTORY launch/
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/launch
PATTERN ".svn" EXCLUDE)
install(DIRECTORY config/
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/config
PATTERN ".svn" EXCLUDE)
install(DIRECTORY rviz/
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/rviz
PATTERN ".svn" EXCLUDE)
endif(roscpp_FOUND)

#Ros2#
if(rclcpp_FOUND AND ${COMPILE_METHOD} STREQUAL "COLCON")
if(rclcpp_FOUND)
ament_target_dependencies(rslidar_sdk_node rclcpp sensor_msgs std_msgs rslidar_msg)
install(TARGETS
rslidar_sdk_node
Expand All @@ -203,4 +194,4 @@ if(rclcpp_FOUND AND ${COMPILE_METHOD} STREQUAL "COLCON")
DESTINATION share/${PROJECT_NAME}
)
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 @@ -130,20 +130,7 @@ cmake .. && make -j4

### 4.2 Compile with ROS catkin tools

(1) Open the *CMakeLists.txt* in the project,modify the line on top of the file **set(COMPILE_METHOD ORIGINAL)** to **set(COMPILE_METHOD CATKIN)**.

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

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

(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 @@ -153,22 +140,7 @@ roslaunch rslidar_sdk start.launch

### 4.3 Compile with ROS2-colcon

(1) Open the *CMakeLists.txt* in the project,modify the line on top of the file **set(COMPILE_METHOD ORIGINAL)** to **set(COMPILE_METHOD COLCON)**.

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

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

(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
32 changes: 2 additions & 30 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,7 @@ cmake .. && make -j4

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

(1) 打开工程内的*CMakeLists.txt*文件,将文件顶部的**set(COMPILE_METHOD ORIGINAL)**改为**set(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 @@ -150,22 +137,7 @@ roslaunch rslidar_sdk start.launch

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

(1) 打开工程内的*CMakeLists.txt*文件,将文件顶部的**set(COMPILE_METHOD ORIGINAL)**改为**set(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
27 changes: 27 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<package format="3">
<name>rslidar_sdk</name>
<version>1.3.2</version>
<description>The rslidar_sdk package</description>
<maintainer email="[email protected]">robosense</maintainer>
<license>BSD</license>

<buildtool_depend condition="$ROS_VERSION == 1">catkin</buildtool_depend>
<buildtool_depend condition="$ROS_VERSION == 2">ament_cmake</buildtool_depend>

<depend>libpcap</depend>
<depend>libpcl-all-dev</depend>
<depend>pcl_conversions</depend>
<depend condition="$ROS_VERSION == 1">pcl_ros</depend>
<depend condition="$ROS_VERSION == 2">rclcpp</depend>
<depend condition="$ROS_VERSION == 1">roscpp</depend>
<depend>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>
26 changes: 0 additions & 26 deletions package_ros1.xml

This file was deleted.

25 changes: 0 additions & 25 deletions package_ros2.xml

This file was deleted.