Skip to content

Commit

Permalink
Merge pull request #1 from ros-perception/ros2
Browse files Browse the repository at this point in the history
Port point_cloud_transport_plugins to ROS2
  • Loading branch information
ahcorde authored Aug 24, 2023
2 parents 2751d9a + 543830f commit 21ea68d
Show file tree
Hide file tree
Showing 37 changed files with 2,352 additions and 482 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/build-and-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
set -ev

# Configuration.
export COLCON_WS=~/ws
export COLCON_WS_SRC=${COLCON_WS}/src
export DEBIAN_FRONTEND=noninteractive
export ROS_PYTHON_VERSION=3

apt update -qq
apt install -qq -y lsb-release wget curl build-essential

# Dependencies.
echo "deb http://packages.ros.org/ros2-testing/ubuntu `lsb_release -cs` main" > /etc/apt/sources.list.d/ros2-testing.list
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | apt-key add -
apt-get update -qq
apt-get install -y python3-colcon-common-extensions \
python3-rosdep python3-vcstool python3-vcstools

rosdep init
rosdep update
rosdep install --from-paths ./ -i -y -r --rosdistro $ROS_DISTRO $ROSDEP_ARGS

# Build.
source /opt/ros/$ROS_DISTRO/setup.bash
mkdir -p $COLCON_WS_SRC
cp -r $GITHUB_WORKSPACE $COLCON_WS_SRC
cd $COLCON_WS
echo $1
wget $1
vcs import src < point_cloud_transport.repos
rosdep install --from-paths ./ -i -y -r --rosdistro $ROS_DISTRO $ROSDEP_ARGS
colcon build --event-handlers console_direct+

# Tests.
colcon test --event-handlers console_direct+
colcon test-result
24 changes: 24 additions & 0 deletions .github/workflows/ros2-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: ROS2 CI

on: [push, pull_request]

jobs:
point_cloud_transport_ci:
name: point_cloud_transport CI
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- docker-image: "ubuntu:22.04"
ros-distro: "rolling"
container:
image: ${{ matrix.docker-image }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Build and Test
run: .github/workflows/build-and-test.sh https://raw.githubusercontent.com/${{ github.repository }}/${{ github.sha }}/point_cloud_transport.repos
env:
DOCKER_IMAGE: ${{ matrix.docker-image }}
ROS_DISTRO: ${{ matrix.ros-distro }}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"files.associations": {
"algorithm": "cpp",
"memory": "cpp"
}
}
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Any contribution that you make to this repository will
be under the 3-Clause BSD License, as dictated by that
[license](https://opensource.org/licenses/BSD-3-Clause).
126 changes: 38 additions & 88 deletions draco_point_cloud_transport/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,112 +1,62 @@
cmake_minimum_required(VERSION 3.10.2)

set(CMAKE_CXX_STANDARD 17)

project(draco_point_cloud_transport)

# Use Draco as a standalone cmake project, it gets built thanks to catkin
# package.xml.
find_package(catkin REQUIRED COMPONENTS
cras_cpp_common
dynamic_reconfigure
message_generation
pluginlib
point_cloud_transport
sensor_msgs
std_msgs)
find_package(ament_cmake REQUIRED)
find_package(pluginlib REQUIRED)
find_package(point_cloud_interfaces REQUIRED)
find_package(point_cloud_transport REQUIRED)
find_package(rclcpp REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(std_msgs REQUIRED)

# There are some find_package/naming issues due to name draco/Draco mismatch.
# Currently, with caktin tools only DracoConfig.cmake is found with just two
# variables defined, draco_INCLUDE_DIR and draco_LIBRARY_DIR. In that case we
# try to reconstruct the rest from FindDraco.cmake (module mode).
find_package(Draco REQUIRED)
if(draco_INCLUDE_DIR)
set(draco_FOUND TRUE)
set(draco_LIBRARY_DIRS "${draco_LIBRARY_DIR}")
find_path(draco_INCLUDE_DIRS draco/point_cloud/point_cloud.h PATHS "${draco_INCLUDE_DIR}/..")
find_library(draco_LIBRARIES NAMES draco PATHS "${draco_LIBRARY_DIR}")
message("Draco found: ${draco_INCLUDE_DIRS}, ${draco_LIBRARIES}")
endif()

add_message_files(FILES
CompressedPointCloud2.msg
)

generate_messages(DEPENDENCIES
set(dependencies
pluginlib
point_cloud_interfaces
point_cloud_transport
rclcpp
sensor_msgs
std_msgs
)

generate_dynamic_reconfigure_options(cfg/DracoPublisher.cfg cfg/DracoSubscriber.cfg)

catkin_package(
INCLUDE_DIRS include
LIBRARIES ${PROJECT_NAME}
CATKIN_DEPENDS message_runtime point_cloud_transport sensor_msgs std_msgs
)

include_directories(include ${catkin_INCLUDE_DIRS} SYSTEM ${draco_INCLUDE_DIRS})
include_directories(include ${DRACO_INCLUDE_DIR})

set(SOURCE_FILES
add_library(${PROJECT_NAME}
SHARED
src/cloud.cpp
src/draco_publisher.cpp
src/draco_subscriber.cpp
)

add_library(${PROJECT_NAME}
${SOURCE_FILES}
)
add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS})
target_link_libraries(${PROJECT_NAME} PUBLIC ${catkin_LIBRARIES} PRIVATE ${draco_LIBRARIES})

add_library(${PROJECT_NAME}_plugin
${SOURCE_FILES}
src/manifest.cpp
)
add_dependencies(${PROJECT_NAME}_plugin ${${PROJECT_NAME}_EXPORTED_TARGETS})
target_link_libraries(${PROJECT_NAME}_plugin PUBLIC ${catkin_LIBRARIES} PRIVATE ${draco_LIBRARIES})
class_loader_hide_library_symbols(${PROJECT_NAME}_plugin)

install(TARGETS ${PROJECT_NAME} ${PROJECT_NAME}_plugin
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
)
target_link_libraries(${PROJECT_NAME} ${DRACO_LIBRARY})

install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.h"
)
ament_target_dependencies(${PROJECT_NAME} ${dependencies})

install(FILES draco_plugins.xml
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION lib/${PROJECT_NAME}
)

if (CATKIN_ENABLE_TESTING)
find_package(roslint REQUIRED)

# catkin_lint - checks validity of package.xml and CMakeLists.txt
# ROS buildfarm calls this without any environment and with empty rosdep cache,
# so we have problems reading the list of packages from env
# see https://github.com/ros-infrastructure/ros_buildfarm/issues/923
if(DEFINED ENV{ROS_HOME})
#catkin_lint: ignore_once env_var
set(ROS_HOME "$ENV{ROS_HOME}")
else()
#catkin_lint: ignore_once env_var
set(ROS_HOME "$ENV{HOME}/.ros")
endif()
#catkin_lint: ignore_once env_var
if(DEFINED ENV{ROS_ROOT} AND EXISTS "${ROS_HOME}/rosdep/sources.cache")
roslint_custom(catkin_lint "-W2" .)
endif()

# Roslint C++ - checks formatting and some other rules for C++ files

file(GLOB_RECURSE ROSLINT_INCLUDE include/*.h include/*.hpp)
file(GLOB_RECURSE ROSLINT_SRC src/*.cpp src/*.hpp src/*.h)
#file(GLOB_RECURSE ROSLINT_TEST test/*.cpp)
install(
DIRECTORY include/${PROJECT_NAME}/
DESTINATION include/${PROJECT_NAME}
)

set(ROSLINT_CPP_OPTS "--extensions=h,hpp,hh,c,cpp,cc;--linelength=120;--filter=\
-build/header_guard,-readability/namespace,-whitespace/braces,-runtime/references,\
-build/c++11,-readability/nolint,-readability/todo,-legal/copyright,-build/namespaces")
roslint_cpp(${ROSLINT_INCLUDE} ${ROSLINT_SRC})
pluginlib_export_plugin_description_file(point_cloud_transport draco_plugins.xml)

roslint_add_test()
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
endif()

ament_export_include_directories(include)
ament_export_libraries(${PROJECT_NAME})
ament_export_dependencies(${dependencies})
ament_package()
12 changes: 6 additions & 6 deletions draco_point_cloud_transport/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ By adjusting the **encode_speed** and **dedode_speed** parameters, one can adjus
- "ny" - NORMAL
- "nz" - NORMAL
- all others are encoded as GENERIC

To specify custom quantization, one can either edit the list of recognized names or use **expert_quantization** and **expert_attribute_type** options.

### Expert Quantization

**Expert_quantization** option tell the encoder to use custom quantization values for point cloud attributes. Multiple POSITION attribute can therefore be encoded with varying quantization levels.
Expand All @@ -55,7 +55,7 @@ To set a quantization for a PointField entry "x" of point cloud which will be ad
Example:

```bash
$ rosparam set /base_topic/draco/attribute_mapping/quantization_bits/x 16
ros2 param set <node name> /<base_topic>/draco/attribute_mapping/quantization_bits/x 16
```

When using **expert_quantization**, user must specify the quantization bits for all PointField entries of point cloud.
Expand All @@ -70,11 +70,11 @@ To set a type for a PointField entry "x" of point cloud which will be advertised
Example:

```bash
$ rosparam set /base_topic/draco/attribute_mapping/attribute_type/x "'POSITION'"
ros2 param set <node name> /<base_topic>/draco/attribute_mapping/attribute_type/x "'POSITION'"
```

When using **expert_attribute_types**, user must specify the type for all PointField entries of point cloud. Accepted types are:
- POSITION
- POSITION
- NORMAL
- COLOR
- TEX_COORD
Expand All @@ -83,7 +83,7 @@ When using **expert_attribute_types**, user must specify the type for all PointF
When encoding rgb/rgba COLOR, user can specify to use the common rgba tweak of ROS (encoding rgba as 4 instances of 1 Byte instead of 1 instance of float32). To inform the encoder, that PointField entry "rgb" should be handled with the tweak, set parameter:

```bash
$ rosparam set /base_topic/draco/attribute_mapping/rgba_tweak/rgb true
ros2 param set <node name> /<base_topic>/draco/attribute_mapping/rgba_tweak/rgb true
```

## Subscriber
Expand Down
42 changes: 0 additions & 42 deletions draco_point_cloud_transport/cfg/DracoPublisher.cfg

This file was deleted.

15 changes: 0 additions & 15 deletions draco_point_cloud_transport/cfg/DracoSubscriber.cfg

This file was deleted.

12 changes: 9 additions & 3 deletions draco_point_cloud_transport/draco_plugins.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
<library path="lib/libdraco_point_cloud_transport_plugin">
<class name="point_cloud_transport/draco_pub" type="draco_point_cloud_transport::DracoPublisher" base_class_type="point_cloud_transport::PublisherPlugin">
<library path="draco_point_cloud_transport">
<class
name="point_cloud_transport/draco_pub"
type="draco_point_cloud_transport::DracoPublisher"
base_class_type="point_cloud_transport::PublisherPlugin">
<description>
This plugin publishes a CompressedPointCloud2 using KD tree compression.
</description>
</class>

<class name="point_cloud_transport/draco_sub" type="draco_point_cloud_transport::DracoSubscriber" base_class_type="point_cloud_transport::SubscriberPlugin">
<class
name="point_cloud_transport/draco_sub"
type="draco_point_cloud_transport::DracoSubscriber"
base_class_type="point_cloud_transport::SubscriberPlugin">
<description>
This plugin decompresses a CompressedPointCloud2 topic.
</description>
Expand Down
Loading

0 comments on commit 21ea68d

Please sign in to comment.