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;
75pub mod entities_info;
76mod gid;
77pub mod log;
78pub mod message;
79pub mod message_info;
80pub mod names;
81pub mod parameters;
82#[doc(hidden)]
83pub mod pubsub;
84pub mod rcl_interfaces;
85pub mod ros_time;
86pub mod rosout;
87pub mod service;
88
89pub mod steady_time;
90mod wide_string;
91
92#[doc(hidden)]
93pub(crate) mod node;
94
95// Re-exports from crate root to simplify usage
96#[doc(inline)]
97pub use context::*;
98#[doc(inline)]
99pub use message::Message;
100#[doc(inline)]
101pub use names::{ActionTypeName, MessageTypeName, Name, NodeName, ServiceTypeName};
102#[doc(inline)]
103pub use message_info::MessageInfo;
104#[doc(inline)]
105pub use node::*;
106#[doc(inline)]
107pub use parameters::{Parameter, ParameterValue};
108#[doc(inline)]
109pub use pubsub::*;
110#[doc(inline)]
111pub use service::{AService, Client, Server, Service, ServiceMapping};
112#[doc(inline)]
113pub use action::{Action, ActionTypes};
114#[doc(inline)]
115pub use wide_string::WString;
116#[doc(inline)]
117pub use ros_time::{ROSTime, SystemTime};
118#[doc(inline)]
119pub use rosout::{NodeLoggingHandle, RosoutRaw};
120
121/// Module for stuff we do not want to export from top level;
122pub mod ros2 {
123  pub use rustdds::{qos::policy, Duration, QosPolicies, QosPolicyBuilder, Timestamp};
124  //TODO: re-export RustDDS error types until ros2-client defines its own
125  pub use rustdds::dds::{CreateError, ReadError, WaitError, WriteError};
126
127  pub use crate::log::LogLevel;
128  // TODO: What to do about SecurityError (exists based on feature "security")
129  pub use crate::names::Name; // import Name as ros2::Name if there is clash
130                              // otherwise
131}