1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! ROS 2 integration built on [r2r](https://docs.rs/r2r).
//!
//! The bridges only register subscriptions/publishers on a node you own.
//! [`spawn_ros_to_moq`] and [`spawn_ros_to_moq_data`] need that node to be spun (e.g.
//! `node.spin_once(..)` in a blocking task) for messages to flow; [`spawn_moq_to_ros`]
//! only publishes, which r2r does without spinning.
//!
//! ```no_run
//! use moqros::ros::{QosProfile, r2r, spawn_ros_to_moq};
//!
//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
//! let ctx = r2r::Context::create()?;
//! let mut node = r2r::Node::create(ctx, "camera_streamer", "")?;
//!
//! let publisher = moqros::Publisher::connect(&moqros::ClientConfig::new(
//! "http://localhost:4443/anon".parse()?,
//! ))?;
//! let broadcast = publisher.create_image_broadcast("camera", moqros::EncoderSettings::default())?;
//! let bridge = spawn_ros_to_moq(&mut node, "/camera/image_raw", QosProfile::sensor_data(), broadcast)?;
//!
//! tokio::task::spawn_blocking(move || loop {
//! node.spin_once(std::time::Duration::from_millis(50));
//! });
//! bridge.await??;
//! # Ok(()) }
//! ```
//!
//! Any other message type goes through a data broadcast:
//!
//! ```no_run
//! use moqros::ros::{QosProfile, spawn_ros_to_moq_data, wait_for_topic_type};
//!
//! # async fn run(mut node: moqros::ros::r2r::Node, publisher: moqros::Publisher) -> moqros::Result<()> {
//! let settings = moqros::DataSettings {
//! format: moqros::DataFormat::Json,
//! mode: moqros::DataMode::Snapshot,
//! ros_type: Some(wait_for_topic_type(&node, "/imu").await?),
//! };
//! let broadcast = publisher.create_data_broadcast("imu", settings)?;
//! let bridge = spawn_ros_to_moq_data(&mut node, "/imu", QosProfile::sensor_data(), broadcast)?;
//! # Ok(()) }
//! ```
//!
//! [`spawn_moq_to_ros`] goes the other way for both kinds of broadcast.
//!
//! Data bridges handle message types at runtime through r2r's untyped API, so they
//! support the message types r2r generated bindings for when it was built.
pub use ;
pub use ;
pub use ;
pub use r2r;
pub use QosProfile;
pub use ;
/// The ROS message type moqros encodes as video.
pub type RosImage = Image;
/// Type name of [`RosImage`], as ROS graph queries report it.
pub const ROS_IMAGE_TYPE: &str = "sensor_msgs/msg/Image";
/// Statistics returned when a bridge stops.