Skip to content

Commit

Permalink
ROS2 testing (#12)
Browse files Browse the repository at this point in the history
* add humble tests

* simpler names

* fix linking problem with r2r v0.7

* tidy and badges

* cargo publish on release
  • Loading branch information
stelzo committed Mar 21, 2024
1 parent 1dedd9c commit 152fce7
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 32 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/crates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
on:
release:
types: [created]

jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true

- name: Publish to crates.io
uses: actions-rs/cargo@v1
with:
command: publish
args: --token ${{ secrets.CRATES_IO_TOKEN }}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: galactic_r2r_test
name: r2r_galactic

on:
push:
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/r2r_humble.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: r2r_humble

on:
push:
pull_request:
workflow_dispatch:

env:
CARGO_TERM_COLOR: always

jobs:
tests_humble:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: docker build . --file ./tests/Dockerfile_r2r_humble --tag r2r_humble
- run: docker run r2r_humble cargo test --features r2r_msg
17 changes: 17 additions & 0 deletions .github/workflows/r2r_iron.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: r2r_iron

on:
push:
pull_request:
workflow_dispatch:

env:
CARGO_TERM_COLOR: always

jobs:
tests_humble:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: docker build . --file ./tests/Dockerfile_r2r_iron --tag r2r_iron
- run: docker run r2r_iron cargo test --features r2r_msg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Ubuntu 20.04 Noetic from rosrust
name: rosrust_noetic

on:
push:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Pure latest Ubuntu without integrations
name: Tests

on:
push:
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "ros_pointcloud2"
version = "0.3.1"
version = "0.3.2"
edition = "2021"
authors = ["Christopher Sieh <stelzo@steado.de>"]
description = "Customizable conversions for working with sensor_msgs/PointCloud2."
repository = "https://github.com/stelzo/ros_pointcloud2"
license = "MIT"
keywords = ["ros", "rosrust", "pointcloud2", "pointcloud", "message",]
keywords = ["ros", "pointcloud2", "pointcloud", "message"]
categories = ["science::robotics", "encoding", "data-structures", "api-bindings"]
readme = "README.md"
documentation = "https://docs.rs/ros_pointcloud2"
Expand All @@ -19,7 +19,7 @@ num-traits = "0.2.15"
fallible-iterator = "0.3.0"
rosrust_msg = { version = "0.1", optional = true }
rosrust = { version = "0.9.11", optional = true }
r2r = { version = "0.8.0", optional = true }
r2r = { version = "0.8.4", optional = true }

[features]
rosrust_msg = ["dep:rosrust_msg", "dep:rosrust"]
Expand Down
45 changes: 26 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
# ROS PointCloud2

Customizable conversions to and from the `sensor_msgs/PointCloud2` ROS message.
<p align="center">
<h3 align="center">ROS PointCloud2</h3>
<p align="center">Customizable conversions to and from the PointCloud2 ROS message.</p>
<p align="center"><a href="https://crates.io/crates/ros_pointcloud2"><img src="https://img.shields.io/crates/v/ros_pointcloud2.svg" alt=""></a> <a href="https://github.com/stelzo/ros_pointcloud2/tree/main/tests"><img src="https://github.com/stelzo/ros_pointcloud2/actions/workflows/tests.yml/badge.svg" alt=""></a>
</p>
</p>

Providing a memory efficient way for message conversion while allowing user defined types without the cost of iterations.
Instead of converting the entire cloud into a `Vec`, you get an iterable type that converts each point from the message on the fly.

Instead of converting the entire cloud into a `Vec`, you get an `Iterator` that converts each point from the message on the fly.
An example for using this crate is [this filter node](https://github.com/stelzo/cloudfilter). It is also a good starting point for
implementing ROS1 nodes in Rust inside a catkin environment.

To keep the crate a general purpose library for the problem and support ROS1 and ROS2, it uses its own type for the message.
To keep the crate a general purpose library for the problem and support ROS1 and ROS2, it uses its own type for the message `ros_types::PointCloud2Msg`.
```rust
use ros_pointcloud2::fallible_iterator::FallibleIterator;
use ros_pointcloud2::pcl_utils::PointXYZ;
use ros_pointcloud2::ros_types::PointCloud2Msg;
use ros_pointcloud2::ConvertXYZ;
use ros_pointcloud2::{
fallible_iterator::FallibleIterator,
pcl_utils::PointXYZ,
ros_types::PointCloud2Msg,
ConvertXYZ,
};

// Your points (here using the predefined type PointXYZ).
let cloud_points = vec![
Expand All @@ -29,9 +31,9 @@ let cloud_points = vec![
},
];

let cloud_copy = cloud_points.clone(); // Only for checking equality later.
let cloud_copy = cloud_points.clone(); // For checking equality later.

// Vector -> Convert -> Message
// Vector -> Converter -> Message
let internal_msg: PointCloud2Msg = ConvertXYZ::try_from(cloud_points)
.unwrap()
.try_into()
Expand All @@ -43,13 +45,14 @@ let internal_msg: PointCloud2Msg = ConvertXYZ::try_from(cloud_points)
// Back to this crate's message type.
// let internal_msg: PointCloud2Msg = msg.into();

// Message -> Convert -> Vector
// Message -> Converter -> Vector
let convert: ConvertXYZ = ConvertXYZ::try_from(internal_msg).unwrap();
let new_cloud_points = convert
.map(|point: PointXYZ| {
// Insert your point business logic here or use other methods like .for_each().
// I will just copy the points into a vector as an example.
// Also, since we are using a fallible iterator, we need to return a Result.
// Insert your point business logic here
// or use other methods like .for_each().

// We are using a fallible iterator so we need to return a Result.
Ok(point)
})
.collect::<Vec<PointXYZ>>()
Expand Down Expand Up @@ -81,9 +84,13 @@ impl From<YourROSPointCloud2> for PointCloud2Msg {

## Integrations

There are currently 2 integrations for common ROS crates such as rosrust for ROS1 and R2R for ROS2 (Galactic).
There are currently 2 integrations for common ROS crates such as rosrust for ROS1 and R2R for ROS2.
- [rosrust_msg](https://github.com/adnanademovic/rosrust)
- [![Tests](https://github.com/stelzo/ros_pointcloud2/actions/workflows/rosrust_noetic.yml/badge.svg)](https://github.com/stelzo/ros_pointcloud2/actions/workflows/rosrust_noetic.yml)
- [r2r_msg](https://github.com/sequenceplanner/r2r)
- [![Tests](https://github.com/stelzo/ros_pointcloud2/actions/workflows/r2r_galactic.yml/badge.svg)](https://github.com/stelzo/ros_pointcloud2/actions/workflows/r2r_galactic.yml)
- [![Tests](https://github.com/stelzo/ros_pointcloud2/actions/workflows/r2r_humble.yml/badge.svg)](https://github.com/stelzo/ros_pointcloud2/actions/workflows/r2r_humble.yml)
- [![Tests](https://github.com/stelzo/ros_pointcloud2/actions/workflows/r2r_iron.yml/badge.svg)](https://github.com/stelzo/ros_pointcloud2/actions/workflows/r2r_iron.yml)

You can use them by enabling the corresponding feature. Example:
```toml
Expand Down
4 changes: 2 additions & 2 deletions tests/Dockerfile_r2r_galactic
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ RUN curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | bash -s -- -y
RUN echo 'source $HOME/.cargo/env' >> $HOME/.bashrc

COPY . /r2r
RUN chmod +x /r2r/tests/r2r_20.04_test.bash
ENTRYPOINT [ "/r2r/tests/r2r_20.04_test.bash" ]
RUN chmod +x /r2r/tests/r2r_test.bash
ENTRYPOINT [ "/r2r/tests/r2r_test.bash" ]
22 changes: 22 additions & 0 deletions tests/Dockerfile_r2r_humble
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# syntax=docker/dockerfile:1
FROM ros:humble

# Update default packages
RUN apt-get update

# Get Ubuntu packages
RUN apt-get install -y \
build-essential \
curl \
libclang-dev

# Get ros test messages
RUN apt-get install -y ros-humble-test-msgs ros-humble-example-interfaces

# Get Rust
RUN curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | bash -s -- -y
RUN echo 'source $HOME/.cargo/env' >> $HOME/.bashrc

COPY . /r2r
RUN chmod +x /r2r/tests/r2r_test.bash
ENTRYPOINT [ "/r2r/tests/r2r_test.bash" ]
22 changes: 22 additions & 0 deletions tests/Dockerfile_r2r_iron
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# syntax=docker/dockerfile:1
FROM ros:iron

# Update default packages
RUN apt-get update

# Get Ubuntu packages
RUN apt-get install -y \
build-essential \
curl \
libclang-dev

# Get ros test messages
RUN apt-get install -y ros-iron-test-msgs ros-iron-example-interfaces

# Get Rust
RUN curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | bash -s -- -y
RUN echo 'source $HOME/.cargo/env' >> $HOME/.bashrc

COPY . /r2r
RUN chmod +x /r2r/tests/r2r_test.bash
ENTRYPOINT [ "/r2r/tests/r2r_test.bash" ]
5 changes: 3 additions & 2 deletions tests/r2r_msg_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ fn convertxyz_r2r_msg() {
use ros_pointcloud2::pcl_utils::PointXYZ;
use ros_pointcloud2::ros_types::PointCloud2Msg;
use ros_pointcloud2::ConvertXYZ;
use r2r::sensor_msgs::msg::PointCloud2;

let cloud = vec![
PointXYZ {
Expand All @@ -25,8 +26,8 @@ fn convertxyz_r2r_msg() {
];
let copy = cloud.clone();
let internal_cloud: PointCloud2Msg = ConvertXYZ::try_from(cloud).unwrap().try_into().unwrap();
let rosrust_msg_cloud: r2r::sensor_msgs::msg::PointCloud2 = internal_cloud.into();
let convert_back_internal: PointCloud2Msg = rosrust_msg_cloud.into();
let r2r_msg_cloud: PointCloud2 = internal_cloud.into();
let convert_back_internal: PointCloud2Msg = r2r_msg_cloud.into();
let to_convert: ConvertXYZ = ConvertXYZ::try_from(convert_back_internal).unwrap();
let back_to_type = to_convert.map(|point| Ok(point)).collect::<Vec<PointXYZ>>();
assert_eq!(copy, back_to_type.unwrap());
Expand Down
8 changes: 5 additions & 3 deletions tests/r2r_20.04_test.bash → tests/r2r_test.bash
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
# run rustup to test with latest rust version
rustup update

if [ -e "/opt/ros/iron/setup.bash" ]; then
source "/opt/ros/iron/setup.bash"
fi

if [ -e "/opt/ros/humble/setup.bash" ]; then
source "/opt/ros/humble/setup.bash"
fi

if [ -e "/opt/ros/galactic/setup.bash" ]; then
source "/opt/ros/galactic/setup.bash"
fi
if [ -e "/opt/ros/foxy/setup.bash" ]; then
source "/opt/ros/foxy/setup.bash"
fi

cd /r2r/ || exit

Expand Down

0 comments on commit 152fce7

Please sign in to comment.