Skip to content

Conversation

@luca-della-vedova
Copy link

Split off ros2-rust/ros2_rust#492 now that examples are in a different repo.
Will need the upstream merged and re-released with a new version for it to actually work (otherwise I can hardcode a branch / path if we want CI to be tested)

Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
Copy link
Contributor

@esteve esteve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luca-della-vedova thanks! Does this work for you without a package.xml file? Perhaps we don't need it for the examples, anyway.


[dependencies]
# TODO(luca) change this to the correct version once dynamic message support is released on crates.io
rclrs = { version = "0.4", features = ["dyn_msg"] }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that dyn_msg is no longer a flag in rclrs, could you remove it here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it in 7f8ac88 but note that as the TODO says this will only be merge-able after the upstream PR is merged and we have a re-release.
To make it compile-able I temporarily set it as a git dependency on my branch, otherwise this can't really be tested.

Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
@luca-della-vedova luca-della-vedova force-pushed the luca/dynamic_message_example branch from 9826150 to 7f8ac88 Compare November 21, 2025 00:46
Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
@luca-della-vedova
Copy link
Author

luca-della-vedova commented Nov 21, 2025

I haven't really put a lot of work into this PR and was leaving it as a "cleanup after the upstream is merged" but after your comment I realized that this could really be a good test platform to make sure the upstream PR is working as intended, so I cleaned this up and added functionality.

@luca-della-vedova thanks! Does this work for you without a package.xml file? Perhaps we don't need it for the examples, anyway.

It's an interesting question, "it builds" but upon further inspection it's more complicated than that.
Technically, it builds because it doesn't strictly depend on any message to compile, since those are only loaded dynamically at runtime.
Furthermore, since it doesn't need rust bindings for the messages but just the dynamic library to be available we don't really need the colcon-ros-cargo machinery to make sure cargo can find the message at build time, but we just need the C++ library to be available in the ament_prefix.
Still, there is a mechanism for this kind of dependency, and it's called exec_depend in package.xml so indeed you are right and we should have a package.xml to be fully safe. I added it in 14d032e.

I also noticed that there was no dynamic_publisher examples, so I added that in 5816dbd. I also changed the message type into the standard example_interfaces/msg/String, which is the same used in the minimal_pub_sub example.
Finally, I noticed that building it through colcon-cargo rather than colcon-ros-cargo I couldn't ros2 run it, unsure why at this moment, I'll investigate in colcon-cargo itself.

This means that, after all these changes, you can finally use this PR to test the upstream PR and even mix and match normal and dynamic pub sub! For example:

# You can of course try this
ros2 run examples_rclrs_dynamic_pub_sub dynamic_publisher
ros2 run examples_rclrs_dynamic_pub_sub dynamic_subscriber

# But also
ros2 run examples_rclrs_minimal_pub_sub minimal_publisher
ros2 run examples_rclrs_dynamic_pub_sub dynamic_subscriber

# And also!
ros2 run examples_rclrs_dynamic_pub_sub dynamic_publisher
ros2 run examples_rclrs_minimal_pub_sub minimal_subscriber

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

Successfully merging this pull request may close these issues.

2 participants