Crate ros2_client
source ·Expand description
ROS 2 interface using RustDDS
Example
use futures::StreamExt;
use ros2_client::*;
let context = Context::new().unwrap();
let mut node = context
.new_node(
NodeName::new("/rustdds", "rustdds_listener").unwrap(),
NodeOptions::new().enable_rosout(true),
)
.unwrap();
let chatter_topic = node
.create_topic(
&Name::new("/","topic").unwrap(),
MessageTypeName::new("std_msgs", "String"),
&ros2_client::DEFAULT_SUBSCRIPTION_QOS,
)
.unwrap();
let chatter_subscription = node
.create_subscription::<String>(&chatter_topic, None)
.unwrap();
let subscription_stream = chatter_subscription
.async_stream()
.for_each(|result| async {
match result {
Ok((msg, _)) => println!("I heard: {msg}"),
Err(e) => eprintln!("Receive request error: {:?}", e),
}
});
// Since we enabled rosout, let's log something
rosout!(
node,
ros2::LogLevel::Info,
"wow. very listening. such topics. much subscribe."
);
// Uncomment this to execute until interrupted.
// --> smol::block_on( subscription_stream );
Modules
- ROS 2 Action machinery
- Some builtin interfaces for ROS2 communication
- Some builtin datatypes needed for ROS2 communication Some convenience topic infos for ROS2 communication
- Message types for ROS 2 Discovery
rosout
logging data types- Defines
Message
trait - This module defines types to represent ROS 2 names for
- Module for stuff we do not want to export from top level;
- Implementation of ROS 2 Services
Macros
- Macro for writing to rosout topic.
Structs
- AService is a means of constructing a descriptor for a Service on the fly. This allows generic code to construct a Service from the types of request and response.
- This is used to construct an ActionType implementation from pre-existing component types.
- Similar to
MessageTypeName
, but names an Action type. - Client end of a ROS2 Service
- Context communicates with other participants information in ROS2 network. It keeps track of
NodeEntitiesInfo
s. Also acts as a wrapper for a RustDDS instance. - Builder for configuring a
Context
- Message metadata
- Name for
.msg
type, or a data type carried over a Topic. - Names for Topics, Services
- Node in ROS2 network. Holds necessary readers and writers for rosout and parameter events topics internally.
- Names for Nodes
- Configuration of Node This is a builder-like struct.
- A ROS2 Publisher
- Server end of a ROS2 Service
- Similar to
MessageTypeName
, but names a Service type. - Spinner implements Node’s background event loop.
- A ROS2 Subscription
- UTF-16 strings, as required by the ROS type system.
Enums
- DDS or ROS 2 Discovery events.
- There are different and incompatible ways to map Services onto DDS Topics. The mapping used by ROS2 depends on the DDS implementation used and its configuration. For details, see OMG Specification RPC over DDS Section “7.2.4 Basic and Enhanced Service Mapping for RPC over DDS” RPC over DDS“ . which defines Service Mappings “Basic” and “Enhanced” ServiceMapping::Cyclone represents a third mapping used by RMW for CycloneDDS.
Statics
Traits
- A trait to define an Action type
- Trait to ensure Messages can be (de)serialized
- Service trait pairs the Request and Response types together. Additionally, it ensures that Response and Request are Messages (Serializable), and we have a means to name the types.