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.
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.
use ;
// Your points (here using the predefined type PointXYZ).
let cloud_points = vec!;
let cloud_copy = cloud_points.clone; // For checking equality later.
// Vector -> Converter -> Message
let internal_msg: PointCloud2Msg = try_from
.unwrap
.try_into
.unwrap;
// Convert to your favorite ROS crate message type, we will use rosrust here.
// let msg: rosrust_msg::sensor_msgs::PointCloud2 = internal_msg.into();
// Back to this crate's message type.
// let internal_msg: PointCloud2Msg = msg.into();
// Message -> Converter -> Vector
let convert: ConvertXYZ = try_from.unwrap;
let new_cloud_points = convert
.map
.
.unwrap; // Handle point conversion or byte errors here.
assert_eq!;
Integrations
There are currently 3 integrations for common ROS crates.
You can use rosrust and r2r by enabling the respective feature:
[]
= { = "*", = ["r2r_msg"]}
# or
= { = "*", = ["rosrust_msg"]}
rclrs (ros2_rust)
Features do not work properly with rcrls because the messages are linked externally. You need to use tags instead:
[]
= { = "https://github.com/stelzo/ros_pointcloud2", = "v0.4.0_rclrs" }
Also, indicate the following dependencies to your linker inside the package.xml of your package.
std_msgs
sensor_msgs
builtin_interfaces
Others
To use ros_pointcloud2 somewhere else, you can also implement the Into and From traits for PointCloud2Msg.
Try to avoid cloning the data: Vec<u8> field.
use PointCloud2Msg;
// Likely to be generated by your ROS crate.
Please open an issue or PR if you want to see support for other crates.
Features
- Easy to integrate into your favorite ROS1 or ROS2 crate
- Custom point types
- Predefined types for common conversions (compared to PCL)
- PointXYZ
- PointXYZI
- PointXYZL
- PointXYZRGB
- PointXYZRGBA
- PointXYZRGBL
- PointXYZNormal
- PointXYZINormal
- PointXYZRGBNormal
- 2D and 3D
Custom Types
You can freely convert to your own point types without reiterating the entire cloud.
You just need to implement some traits.
use size_of;
use PointCloud2Msg;
use ;
const DIM: usize = 3;
const METADIM: usize = 4;
// Converting your custom point to the crate's internal representation
// The mappings for index of meta idx to field names. Example: 0 -> "r", 1 -> "g", 2 -> "b", 3 -> "a"
// Converting crate's internal representation to your custom point
type MyConverter = size_of! }, DIM, METADIM, CustomPoint>;
// Your custom cloud (Vector)
let custom_cloud = vec!;
// Cloud -> ROS message
let custom_msg: PointCloud2Msg = try_from
.unwrap
.try_into
.unwrap;
// ROS message -> Cloud
let to_custom_type = try_from.unwrap;
Future Work
- Benchmark vs PCL
- Proper error passing to the iterator result (currently merged into
PointConversionError) - remove allocations
- introduce no-panic for maximum stability
- Add more predefined types