Rust crate for PointCloud2 ROS1/ROS2 message conversion.
Go to file
stelzo 2bb8bab5f0
merge iterator
2024-04-29 21:30:46 +02:00
.github iron testing 2024-03-25 13:07:58 +01:00
src merge iterator 2024-04-29 21:30:46 +02:00
tests merge iterator 2024-04-29 21:30:46 +02:00
.gitignore first commit 2023-04-25 18:30:54 +02:00
Cargo.toml merge iterator 2024-04-29 21:30:46 +02:00
LICENSE first commit 2023-04-25 18:30:54 +02:00
README.md docs and clippy 2024-04-29 20:32:55 +02:00
package.xml add testing deps 2024-03-25 12:37:34 +01:00

README.md

ROS PointCloud2

Customizable conversions to and from the PointCloud2 ROS message.

Providing an easy to use, generics defined, point-wise iterator abstraction over the byte buffer in PointCloud2 to minimize iterations in your processing pipeline.

To keep the crate a general purpose library for the problem and support ROS1 and ROS2, it uses its own type for the message PointCloud2Msg.

Examples

Using a Vec<>.

use ros_pointcloud2::{
  pcl_utils::PointXYZ, reader::ReaderXYZ, writer::WriterXYZ, PointCloud2Msg,
};

// Your points (here using the predefined type PointXYZ).
let cloud_points = vec![
  PointXYZ {
    x: 91.486,
    y: -4.1,
    z: 42.0001,
  },

  PointXYZ {
    x: f32::MAX,
    y: f32::MIN,
    z: f32::MAX,
  },
];

// For equality test later
let cloud_copy = cloud_points.clone();

// Vector -> Writer -> Message.
// You can also just give the Vec or anything that implements `IntoIter`.
let internal_msg: PointCloud2Msg = WriterXYZ::from(cloud_points.into_iter())
  .try_into() // iterating points here O(n)
  .unwrap();

// Convert to your ROS crate message type, we will use r2r here.
// let msg: r2r::sensor_msgs::msg::PointCloud2 = internal_msg.into();

// Publish ...

// ... now incoming from a topic.
// let internal_msg: PointCloud2Msg = msg.into();

// Message -> Reader. The Reader implements the Iterator trait.
let reader = ReaderXYZ::try_from(internal_msg).unwrap();
let new_cloud_points = reader
  .map(|point: PointXYZ| {
    // Some logic here

    point
  })
  .collect::<Vec<PointXYZ>>(); // iterating points here O(n)

assert_eq!(new_cloud_points, cloud_copy);

Integrations

There are currently 3 integrations for common ROS crates.

You can use rosrust and r2r by enabling the respective feature:

[dependencies]
ros_pointcloud2 = { version = "*", features = ["r2r_msg"]}
# or
ros_pointcloud2 = { version = "*", features = ["rosrust_msg"]}

rclrs (ros2_rust)

Features do not work properly with rcrls because the messages are linked externally. You need to use tags instead:

[dependencies]
ros_pointcloud2 = { git = "https://github.com/stelzo/ros_pointcloud2", tag = "v0.4.0_rclrs" }

Also, indicate the following dependencies to your linker inside the package.xml of your package.

<depend>std_msgs</depend>
<depend>sensor_msgs</depend>
<depend>builtin_interfaces</depend>

Please open an issue or PR if you want to see support for other crates.

Future Work

  • Benchmark vs PCL
  • Add more predefined types
  • Optional derive macros for custom point implementations

License

MIT