Skip to main content

ros2_client/
lib.rs

1//! ROS 2 client library, similar to the [rclcpp](https://docs.ros.org/en/rolling/p/rclcpp/) or
2//! [rclpy](https://docs.ros.org/en/rolling/p/rclpy/) libraries, in native Rust. The underlying DDS
3//! implementation, [RustDDS](https://atostek.com/en/products/rustdds/), is also native Rust.
4//!
5//! # Example
6//!
7//! ```
8//! use futures::StreamExt;
9//! use ros2_client::*;
10//!
11//!   let context = Context::new().unwrap();
12//!   let mut node = context
13//!     .new_node(
14//!       NodeName::new("/rustdds", "rustdds_listener").unwrap(),
15//!       NodeOptions::new().enable_rosout(true),
16//!     )
17//!     .unwrap();
18//!
19//!   let chatter_topic = node
20//!     .create_topic(
21//!       &Name::new("/","topic").unwrap(),
22//!       MessageTypeName::new("std_msgs", "String"),
23//!       &ros2_client::DEFAULT_SUBSCRIPTION_QOS,
24//!     )
25//!     .unwrap();
26//!   let chatter_subscription = node
27//!     .create_subscription::<String>(&chatter_topic, None)
28//!     .unwrap();
29//!
30//!   let subscription_stream = chatter_subscription
31//!     .async_stream()
32//!     .for_each(|result| async {
33//!       match result {
34//!         Ok((msg, _)) => println!("I heard: {msg}"),
35//!         Err(e) => eprintln!("Receive request error: {:?}", e),
36//!       }
37//!     });
38//!
39//!   // Since we enabled rosout, let's log something
40//!   rosout!(
41//!     node,
42//!     ros2::LogLevel::Info,
43//!     "wow. very listening. such topics. much subscribe."
44//!   );
45//!
46//!   // Uncomment this to execute until interrupted.
47//!   // --> smol::block_on( subscription_stream );
48//! ```
49
50#[macro_use]
51extern crate lazy_static;
52
53/// Some builtin datatypes needed for ROS2 communication
54/// Some convenience topic infos for ROS2 communication
55pub mod builtin_topics;
56
57#[doc(hidden)]
58pub mod action_msgs; // action mechanism implementation
59
60/// Some builtin interfaces for ROS2 communication
61pub mod builtin_interfaces;
62
63#[doc(hidden)]
64pub mod context;
65
66#[doc(hidden)] // needed for actions implementation
67pub mod unique_identifier_msgs;
68
69#[doc(hidden)]
70#[deprecated] // we should remove the rest of these
71pub mod interfaces;
72
73/// ROS 2 Action machinery
74pub mod action;
75/// ROS 2 distribution identification (compile-time selection + runtime check)
76pub mod distributions;
77pub mod entities_info;
78mod gid;
79pub mod log;
80pub mod message;
81pub mod message_info;
82pub mod names;
83pub mod parameters;
84#[doc(hidden)]
85pub mod pubsub;
86pub mod rcl_interfaces;
87pub mod ros_time;
88pub mod rosout;
89pub mod service;
90
91pub mod steady_time;
92mod wide_string;
93
94#[doc(hidden)]
95pub(crate) mod node;
96
97// Re-exports from crate root to simplify usage
98#[doc(inline)]
99pub use context::*;
100#[doc(inline)]
101pub use distributions::{RosDistro, COMPILED_ROS_DISTRO};
102#[doc(inline)]
103pub use message::Message;
104#[doc(inline)]
105pub use names::{ActionTypeName, MessageTypeName, Name, NodeName, ServiceTypeName};
106#[doc(inline)]
107pub use message_info::MessageInfo;
108#[doc(inline)]
109pub use node::*;
110#[doc(inline)]
111pub use parameters::{Parameter, ParameterValue};
112#[doc(inline)]
113pub use pubsub::*;
114#[doc(inline)]
115pub use service::{AService, Client, Server, Service, ServiceMapping};
116#[doc(inline)]
117pub use action::{Action, ActionTypes};
118#[doc(inline)]
119pub use wide_string::WString;
120#[doc(inline)]
121pub use ros_time::{ROSTime, SystemTime};
122#[doc(inline)]
123pub use rosout::{NodeLoggingHandle, RosoutRaw};
124
125/// Module for stuff we do not want to export from top level;
126pub mod ros2 {
127  pub use rustdds::{qos::policy, Duration, QosPolicies, QosPolicyBuilder, Timestamp};
128  //TODO: re-export RustDDS error types until ros2-client defines its own
129  pub use rustdds::dds::{CreateError, ReadError, WaitError, WriteError};
130
131  pub use crate::log::LogLevel;
132  // TODO: What to do about SecurityError (exists based on feature "security")
133  pub use crate::names::Name; // import Name as ros2::Name if there is clash
134                              // otherwise
135}
136
137/// Re-export of the entire RustDDS,
138/// to provide access to the same version that ros2-client uses.
139pub use rustdds;