ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A answers.ros.org

Proposal: Rust Working Group for ROS

Will this WG have it’s own dedicated instant-messaging chat, like Matrix? Or is it too early to think about that at the moment?

1 Like

Hey y’all, good to see so much enthusiasm, and no worries about being a Rust expert just yet. While it seems we’re all still learning more about the language, I don’t think there’s a better way to do so than with peers and projects that share your interests. I’ll eventually cross-post to Rust community forms and contact some awesome-rust-mentors to help balance the Rust/ROS experience within the WG:

Before reaching out just yet, I’d like to hold a few smaller meetings to start with, including current ROS users using Rust, so we can effectively onboard more rustaceans into the ROS community and WG.


Yeah, the build setup is a bit awkward just yet. Although I recently added a Dockerfile that provides a simple and reproducible build environment, and should help with further development.


I had intended to @ you, but discovered I can only ping 10 folks at a time.
However, I knew you frequent discourse and would spot this in any event. :mag:


That’s a good point. It would be great for the rust client library to support async/await functionality. @wjwwood or @gbiggs , Is there a good adherence resource documenting which surfaces of the public rlc API are Thread-Safe? Can’t seem to find the doxygen pages for Foxy, like for Bouncy:


That reminds me of another limitation noted in rclrs; the message interface has much room to improve.

  • messages are deep-copied and this can be terribly inefficient for big messages like images; the current solution leverages C typesupport implementations and might benefits from a direct serialization/deserialization

Yes, I have a Matrix Room/Community ready :wink: , but haven’t linked to it just yet to keep the discussion centralized on this thread. After our first meeting and need for more synchronous communication, I’ll update the top post and WG contact details in the governance page in the ROS2 index.

2 Likes

I’m one of the most heavy user of rosrust (ROS1).

This robot we published last month uses rosrust heavily.

And i’m personally collecting useful rust libraries for roboticists here,

So, we (I’m CEO of Smile Robotics, Inc) can test the robustness and usefulness of ROS2 rust on our robot and demonstrate its power on real robot when we’ve built the ROS2 rust something!
If our company were very large, we want to provide more power but it will be difficult.

We have some problem in generation of messages when we use rosrust. We can learn a lot of things from the experience of rosrust made by https://github.com/adnanademovic .

4 Likes

There is not, unfortunately. It’s being worked on, but we’re starting from the bottom and working our way up. The RMW interface has recently got excellent documentation.

I spent quite a bit of time in the type support system recently. This could be a good place for me to start, if I can get the time.

CC: @gbiggs

I think most of rcl API are not thread-safe. it is described in the header files, i just did grep with Thread-Safe. besides, there is no mutex lock rcl, i think that design is to make sure the lock in frontend such as rclcpp.

The docs are there:

I don’t think it will be easy to integrate into async/await just based on my knowledge of similar systems like Python’s asyncio and the underlying libraries like libevent, libev, or libuv. As they generally require a file handle like object that can be used with even lower level interfaces like select, kqueue, or epoll, and the way that most DDS implementations are structured they cannot give us access to those handles and/or they are not portable. So you typically end up with a sub optimal solution which requires extra threads, synchronization, and context switching overhead which you’d prefer to avoid I think. So it’s possible, but complicated. That being said, it’s possible the framework is more flexible than I’m used to and allows you to integrate them more nicely, but I can’t imagine how atm.

Very little of the rcl API is thread-safe, the idea being that the calling code is usually a client library for a specific programming language and therefore is better suited to handling things like threading and synchronization. Also, it allows you to write client libraries that are explicitly not thread-safe (maybe always single threaded) and therefore get some benefits.

The only functions that are required to be thread-safe in a non-trivial way, that I know of off hand, are rcl_publish(), rcl_take(), and maybe similar functions for Services. These are not enforced at the rcl level, but instead rely on the middleware implementation to ensure this via rmw_publish() and rmw_take().

2 Likes

Yes! Rust WG! ADLINK is all in on rust. Eclipse Cyclone DDS sister project Zenoh is 100% Rust. zenoh-plugin-dds gives ROS 2 scalable fault tolerant discovery; bridging via wireless (WiFi, 4G, 5G, LoRa) for swarms, V2X, cloud; and micro-controller support with rmw_zenoh for micro-ROS being released soon. Here is presentation & ROS 2 demo done for Autoware TSC https://youtu.be/VQ-Fvm4vIYg

Here is a cyclonedds rust binding https://github.com/atolab/cdds-rust
… and here is another because our friend Sojan James of Samsung HARMAN Automotive “wanted to give my favorite DDS a binding for my favorite language” https://github.com/sjames/cyclonedds-sys
Read Sojan’s “The case for using Rust for Automotive software

8 Likes

To be honest, I really love the little love dragon logo :smile:

3 Likes

My current job is to work on ROS 2 development, and my company supports my working on rclrs; so if any of you feel like you have ideas of things to work on, but don’t have the time/support to work on it, let me know. I can try and help you.

For example: @gbiggs - You wanted to work on setting up the type support system in rclrs. I’ve been trying to get rclrs to play nicely with VSCode + Rust-Analyzer, and one of the hangups is it gets confused by messages, and can’t recognize them as types. I’d be very interested in lending a hand if you have some ideas on that.

I don’t think it will be easy to integrate into async/await just based on my knowledge of similar systems like Python’s asyncio and the underlying libraries like libevent , libev , or libuv . As they generally require a file handle like object that can be used with even lower level interfaces like select , kqueue , or epoll , and the way that most DDS implementations are structured they cannot give us access to those handles and/or they are not portable. So you typically end up with a sub optimal solution which requires extra threads, synchronization, and context switching overhead which you’d prefer to avoid I think. So it’s possible, but complicated. That being said, it’s possible the framework is more flexible than I’m used to and allows you to integrate them more nicely, but I can’t imagine how atm.

I just took a look into this. According to Ferrous Systems, async/await is currently supported as a source code transformation in the compiler: https://ferrous-systems.com/blog/stable-async-on-embedded/. As of May, they used Thread Local Storage, but Ferrous Systems pushed a change to the compiler to get away from that. They also worked on enabling async/await for no_std, which means we’d have access to it in embedded systems.

However, I’m not sure it’s on stable yet. According to the post, they said it’d be 4 weeks until stable, but I’ve not located the exact stable release this was implemented in. Of course, I could just be blind…

If I’ve said anything incorrect, please feel free to correct me! I’ve not used async/await functionality yet!

EDIT: Found the release: no_std support was added in Rust 1.44: https://github.com/rust-lang/rust/blob/master/RELEASES.md

This would be great. We use ROS 1 at work and are looking at ROS 2. As for building https://github.com/AndrewGaspar/corrosion/ is very close to working with catkin on ROS 1. It wouldn’t take much to make it work with ament.

1 Like

@jhdcs I haven’t tried rust-analyzer with rclrs yet but does settings rust-analyzer.cargo.loadOutDirsFromCheck and rust-analyzer.procMacro.enable help? If not please file an issue with a simple test case and I can take a look at it.

A bit relevant: This reminded me about the recent improvements around const-generics this year:

For those who don’t know, const generics refers to generics that are constant values, rather than types. This allows types to be parameterized by, for example, specific integer values. In stable Rust, only the special array type - [T; N] - has a const parameter (the length of the array), and there is no way to be abstract over all values of N , even for arrays. Const generics will allow creating new types parameterized by values, as well as implementing traits and functions that are abstract over those values.

This might be useful for IDL fields that are array types of fixed lengths. I’m not sure it would have much of an advantage over vectors with primitive values, but perhaps still advantageous for more advance or nested message types.

1 Like

Hi everyone!
I’m interested. I would like to join the meeting but I’m not able to find the meeting link.

This is cool! I must admit I haven’t played around with Ros yet, but I certainly will vouch for Rust for complex projects where safety and performance are top on the list. For those who are on the fence with Rust (as I was two years ago), you need to try it out. It took me a project or two to “get it”, but once that happens you need to work quite hard to avoid looking like a fanatic. :slight_smile:

DDS is a great way to build a data-oriented system which I think is the essence of a distributed system, but I guess I’m preaching to the choir here. CycloneDDS is my favourite implementation as it is small, performs well and it is written in C, allowing easy bindings to other languages. I’m eagerly awaiting version 1.0.

Rust is great and Cargo makes it complete. It is amazing to see how Cargo is used to put together an easy to use build environment with access to lots of packages. The cyclonedds Rust binding allows you to put interfaces into their own crate. Publishing and using interfaces becomes as easy as importing the interface crate in the Cargo.toml. You also get semantic versioning for the interfaces.

Thank you @joespeed for the links!

What is a good weekend project to try out Ros2?

Cheers!

I think the best way to get started with Ros2 is to work through the tutorials. They’ll get you up and running and trying out (admittedly simple) cases. If you run into trouble, feel free to shoot me a message, I can try and smooth things over. I’m sure several others around here will help too, but I’ll let them decide if they want to do that via message or not. Alternatively, you can post your question in Ros Answers, and let the community respond.

I just checked both those options (thanks for the suggestion!), but they didn’t help.

I think the root of the problem is that std_msgs is not exactly a crate. It’s a bunch of .msg files that define message types that can be passed between ROS 2 nodes, and Rust-Analyzer has no idea how to parse that. Not that I would expect it to - It’s not Rust! But we should probably figure out a way for these files to be, I guess, interpreted? Make them recognizable as types, so that we get Rust’s safety guarantees on them.

The std_msgs code is here: https://github.com/ros2/common_interfaces/tree/foxy/std_msgs.

1 Like

Okay! So you need to enable the options I mentioned and then if you look at the CMakeLists.txt in the rclrs_examples you’ll notice that they copy the Cargo.toml to ${CMAKE_BINARY_DIR} and then append a bunch of crates including std_msgs. If you open THAT directory (/opt/overlay_ws/build/rclrs_examples/ in the build docker container) then rust-analyzer will be able to find the messages in rclrs_publisher.rs and rclrs_subscriber.rs. This certainly isn’t ideal but it does give you all the rust-analyzer goodies.

https://github.com/adnanademovic/rosrust handles this much better since it’s pure rust. I’ll have to read up on ament/colcon and understand why corrosion wouldn’t work since it does with catkin (though you need to copy some files in your CMakeLists.txt).