MCPcopy Index your code
hub / github.com/RosLibRust/roslibrust

github.com/RosLibRust/roslibrust @v0.21.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.21.0 ↗ · + Follow
1,512 symbols 2,699 edges 119 files 271 documented · 18%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

RosLibRust

ROS1 ROS2 License:MIT

Documentation about the crate is on docs.rs, extended guides can be found on roslibrust.github.io

An async rust library for interfacing with ROS1 and ROS2, built on Tokio.

  • One Trait Based API - Write your behavior once and use it with any backend! Select the backend you want to use at compile time.
  • Pure Rust - No ROS1 or ROS2 dependencies or installation required! Compile time message generation from .msg/.srv files.

This allows writing generic behaviors like:

```rust ,no_run

use roslibrust_test::ros1::*;

use roslibrust::{TopicProvider, Publish, Subscribe};

async fn relay(ros: T) -> roslibrust::Result<()> { let mut subscriber = ros.subscribe::("/in").await?; let mut publisher = ros.advertise::("/out").await?; while let Ok(msg) = subscriber.next().await { println!("Got message: {}", msg.data); publisher.publish(&msg).await?; } Ok(()) }

[tokio::main]

async fn main() -> roslibrust::Result<()> { // Experimental support in roslibrust_ros2, not yet released on crates.io // Relay messages over a native ROS2 connection using Zenoh // #[cfg(feature = "ros2")] // { // let ros = roslibrust::ros2::NodeHandle::new("http://localhost:11311", "relay").await?; // relay(ros).await?; // }

// Relay messages over a native ROS1 connection via TCPROS
#[cfg(feature = "ros1")]
{
let ros = roslibrust::ros1::NodeHandle::new("http://localhost:11311", "relay").await?;
relay(ros).await?;
}

// Relay messages over a zenoh connection compatible with zenoh-ros1-plugin / zenoh-ros1-bridge
#[cfg(feature = "zenoh")]
{
let ros = roslibrust::zenoh::ZenohClient::new(zenoh::open(zenoh::Config::default()).await.unwrap());
relay(ros).await?;
}

// Relay messages over a rosbridge_server connection with either ROS1 or ROS2!
#[cfg(feature = "rosbridge")]
{
let ros = roslibrust::rosbridge::ClientHandle::new("ws://localhost:9090").await?;
relay(ros).await?;
}

// Relay messages over a mock ROS connection for testing
#[cfg(feature = "mock")]
{
let ros = roslibrust::mock::MockRos::new();
relay(ros).await?;
}

Ok(())

}


All of this is backed by common traits for ROS messages, topics, and services. `roslibrust_codegen` provides generation of Rust types from both ROS1 and ROS2 .msg/.srv files and
`roslibrust_codegen_macro` provides a convenient macro for generating these types:

```rust,ignore
// Will generate types from all packages in ROS_PACKAGE_PATH, AMENT_PREFIX_PATH, and COLCON_PREFIX_PATH
roslibrust_codegen_macro::generate_ros_types_with_env!();

If you want to see what the generated code looks like checkout our generated messages in our test crate. While the macro is useful for getting started, we recommend using roslibrust_codegen with a build.rs as shown in example_package. This allows cargo to know when message files are edited and automatically re-generate the code.

Getting Started / Examples

Contributing

Contribution through reporting of issues encountered and implementation in PRs is welcome! Before landing a large PR with lots of code implemented, please open an issue if there isn't a relevant one already available and chat with a maintainer to make sure the design fits well with all supported platforms and any in-progress implementation efforts.

We uphold the rust lang Code of Conduct.

Minimum Supported Rust Version / MSRV

MSRV is currently 1.90.

Extension points exported contracts — how you extend this code

RosMessageType (Interface)
Fundamental traits for message types this crate works with This trait will be satisfied for any types generated with thi [498 …
roslibrust_common/src/traits.rs
RosTimestamp (Interface)
Conversion between ROS header timestamps and transform timestamps. [3 implementers]
roslibrust_transforms/src/lib.rs
RosApi (Interface)
Represents the ability to interact with the interfaces provided by the rosapi node. This trait is implemented for Client [1 …
roslibrust_rosapi/src/lib.rs
RosBridgeComm (Interface)
Describes the low level comm capabilities of talking to a rosbridge server This trait exists because we haven't wrapped [1 …
roslibrust_rosbridge/src/comm.rs
RosServiceType (Interface)
Represents a ROS service type definition corresponding to a `.srv` file. Typically this trait will not be implemented b [49 …
roslibrust_common/src/traits.rs
IntoTransform (Interface)
Trait for converting a TransformStamped message to a `transforms::Transform`. This trait abstracts over the differences [2 …
roslibrust_transforms/src/lib.rs
MapError (Interface)
Defines a conversion from a tungstenite error to a roslibrust error Since neither error type is owned by this crate we u [1 …
roslibrust_rosbridge/src/lib.rs
Publish (Interface)
ANCHOR: publish Indicates that something is a publisher and has our expected publish Implementors of this trait are expe [5 …
roslibrust_common/src/traits.rs

Core symbols most depended-on inside this repo

write
called by 84
roslibrust_mcap/src/writer.rs
next
called by 69
roslibrust_ros1/src/subscriber.rs
publish
called by 38
roslibrust_ros1/src/publisher.rs
as_ref
called by 37
roslibrust_common/src/topic_name.rs
len
called by 35
roslibrust_rosbridge/src/subscriber.rs
finish
called by 32
roslibrust_mcap/src/writer.rs
timeout
called by 29
roslibrust_rosbridge/src/client.rs
to_global_name
called by 26
roslibrust_common/src/topic_name.rs

Shape

Class 705
Method 390
Function 386
Interface 17
Enum 14

Languages

Rust84%
C++14%
Python2%

Modules by API surface

roslibrust_test/src/ros1.rs247 symbols
roslibrust_test/src/ros2.rs161 symbols
roslibrust_transforms/src/messages.rs63 symbols
roslibrust_codegen/src/lib.rs50 symbols
roslibrust_rosapi/src/lib.rs36 symbols
roslibrust_ros1/src/master_client.rs35 symbols
roslibrust_rosbridge/src/client.rs27 symbols
roslibrust_zenoh/src/lib.rs22 symbols
roslibrust_mock/src/lib.rs22 symbols
roslibrust_codegen/src/ros2_hashing.rs22 symbols
roslibrust_transforms/src/lib.rs21 symbols
roslibrust_ros2/src/lib.rs21 symbols

For agents

$ claude mcp add roslibrust \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact