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

Trying to convert from Pointcloud2Msg to r2r::msg::PointCloud2 #21

Closed
TheMotonaut opened this issue May 18, 2024 · 6 comments
Closed

Trying to convert from Pointcloud2Msg to r2r::msg::PointCloud2 #21

TheMotonaut opened this issue May 18, 2024 · 6 comments

Comments

@TheMotonaut
Copy link

TheMotonaut commented May 18, 2024

Hi

Im trying publish a PointCloud2 message in the r2r library, but I am having trouble getting it to compile correctly.

let msg = PointCloud2Msg::try_from_iter(xyz).unwrap();

let r2r_msg: PointCloud2= msg.into();

publisher.publish(&r2r_msg).unwrap();

xyz is a vector with PointXYZ types. When I compile I get the error:

error[E0277]: the trait bound `PointCloud2: From<ros_pointcloud2::PointCloud2Msg>` is not satisfied
let r2r_msg: PointCloud2= msg.into();
^^^^ the trait `From<ros_pointcloud2::PointCloud2Msg>` is not implemented for `PointCloud2`

I have imported
use ros_pointcloud2::prelude::*;
use r2r::{
QosProfile, sensor_msgs::msg::PointCloud2,
};

I am using 0.5.0-rc.1 since there were going to be so many changes anyway.

Im a new to Rust so I am not sure what exactly I am doing wrong
Thank you!

@stelzo
Copy link
Owner

stelzo commented May 18, 2024

Hi!

Did you activate the r2r_msg feature? The missing implementation is behind a feature flag, which needs to be specified in your import inside the Cargo.toml file like this:

ros_pointcloud2 = { version = "0.5.0-rc.1", features = ["r2r_msg"] }

A full list of features can be found in the docs.

Since you said you are new to Rust, I think that could be the problem. Every library has the ability to give features that are mostly additive, so you could add rayon in there as well for parallel processing.

@TheMotonaut
Copy link
Author

The feature is active
I thought it might had something to do with #[cfg(feature = "r2r_msg")] but this removes the next line from the scope so no luck

@stelzo
Copy link
Owner

stelzo commented May 19, 2024

Ok, I don't know enough about your code to see what happened. Could you share more? You also can compare it with the r2r CI test.

@TheMotonaut
Copy link
Author

TheMotonaut commented May 21, 2024

I found the problem!

The problem was that the version imported by cargo for r2r was 9.0.0, I had not specified a certain version, and the dependency for ros_pointcloud2 was 0.8.4 so something weird happend there-

So I specified the version to download for r2r to 0.8.4 and now it works!

Thank you for your work, now the package works great

@stelzo
Copy link
Owner

stelzo commented May 21, 2024

I just had the same problem with a different tool (tf_r2r) in a node of mine and thought this package will have the same problem for diverging major versions.

Since the message types are highly likely to not change over time. I could do some macro things here, but that would still be hacky and won't assure compatibility. I think a better solution would be for the ROS client implementations to depend on a centralized message crate(s) for the system messages. Then we could have tooling regardless of the ROS library. This is also discussed here.

For now, I'll update the dependency to the newest version. You can change to 0.5.0-rc.3 for r2r 0.9 if you need that.

@stelzo stelzo closed this as completed May 21, 2024
@TheMotonaut
Copy link
Author

Cool thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants