Expand description
§Easy to use, runtime-agnostic async rust bindings for ROS2.
Minimal bindings for ROS2 that do not require hooking in to the
ROS2 build infrastructure – cargo build
is all you
need. Convenience Rust types are created by calling into the c
introspection libraries. This circumvents the ROS2 .msg/.idl
pipeline by relying on already generated C code. By default, the
behavior is to build bindings to the RCL and all message types
that can be found in the currently sourced ros environment.
§What works?
- Up to date with ROS2
DashingEloquentFoxy Galactic Humble - Building Rust types
- Publish/subscribe
- Services
- Actions
- Parameter handling
After having sourced ROS2 (see README for more details), you can try the following example:
use futures::{executor::LocalPool, future, stream::StreamExt, task::LocalSpawnExt};
use r2r::QosProfile;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let ctx = r2r::Context::create()?;
let mut node = r2r::Node::create(ctx, "node", "namespace")?;
let subscriber =
node.subscribe::<r2r::std_msgs::msg::String>("/topic", QosProfile::default())?;
let publisher =
node.create_publisher::<r2r::std_msgs::msg::String>("/topic", QosProfile::default())?;
let mut timer = node.create_wall_timer(std::time::Duration::from_millis(1000))?;
// Set up a simple task executor.
let mut pool = LocalPool::new();
let spawner = pool.spawner();
// Run the subscriber in one task, printing the messages
spawner.spawn_local(async move {
subscriber
.for_each(|msg| {
println!("got new msg: {}", msg.data);
future::ready(())
})
.await
})?;
// Run the publisher in another task
spawner.spawn_local(async move {
let mut counter = 0;
loop {
let _elapsed = timer.tick().await.unwrap();
let msg = r2r::std_msgs::msg::String {
data: format!("Hello, world! ({})", counter),
};
publisher.publish(&msg).unwrap();
counter += 1;
}
})?;
// Main loop spins ros.
loop {
node.spin_once(std::time::Duration::from_millis(100));
pool.run_until_stalled();
}
}
Re-exports§
pub extern crate indexmap;
pub extern crate uuid;
pub use qos::QosProfile;
Modules§
- action_
msgs - builtin_
interfaces - diagnostic_
msgs - geometry_
msgs - lifecycle_
msgs - nav_
msgs - qos
- QoS (Quality of Service) full credit goes to https://github.com/rclrust/rclrust/blob/main/rclrust/src/qos.rs
- rcl_
interfaces - rosgraph_
msgs - sensor_
msgs - shape_
msgs - statistics_
msgs - std_
msgs - stereo_
msgs - test_
msgs - tf2_
msgs - trajectory_
msgs - unique_
identifier_ msgs - visualization_
msgs
Macros§
- assert_
compiled_ with_ use_ sim_ time_ support - Causes compile time error if
use_sim_time
is unsupported. - log_
debug - Debug log message.
- log_
error - Error log message.
- log_
fatal - Fatal log message.
- log_
info - Info log message.
- log_
warn - Warning log message.
Structs§
- Action
Client - Action client
- Action
Client Goal - Action client goal handle
- Action
Client Goal Untyped - Action client goal handle (untyped)
- Action
Client Untyped - Action client (untyped)
- Action
Server Cancel Request - Request to cancel an active goal.
- Action
Server Goal - A handle to an active
Goal
- Action
Server Goal Request - Request to the action server to accept a new
Goal
. - Client
- ROS service client.
- Client
Untyped - ROS “untyped” service client.
- Clock
- A ROS clock.
- Context
- A ROS context. Needed to create nodes etc.
- Native
Msg - This struct wraps a RCL message.
- Node
- A ROS Node.
- Parameter
- ROS parameter.
- Publisher
- A ROS (typed) publisher.
- Publisher
Untyped - A ROS (untyped) publisher.
- Service
Request - Encapsulates a service request.
- Timer
- A ROS timer.
- Wrapped
Native MsgUntyped - Wrong
Parameter Type
Enums§
- Clock
Type - Different ROS clock types.
- Error
- r2r Error type.
- Goal
Status - The status of a goal.
- LogSeverity
- Logging severity
- Parameter
Value - ROS parameter value.
Constants§
Traits§
- RosParams
- Trait for use it with
Node::make_derived_parameter_handler()
. - Wrapped
Action Type Support - Wrapped
Service Type Support - Wrapped
Typesupport
Type Aliases§
- Result
- r2r Result type.
Derive Macros§
- RosParams
- Derives RosParams trait for a structure to use it with
r2r::Node::make_derived_parameter_handler()
.