Skip to content

Commit 4ed509f

Browse files
committed
Use correct quality of service
1 parent e93f672 commit 4ed509f

File tree

2 files changed

+32
-59
lines changed

2 files changed

+32
-59
lines changed

crates/zenoh_bridge/src/main.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use zenoh::Session;
1616
use crate::{
1717
bridge::{forward_ros_to_zenoh, forward_zenoh_to_ros},
1818
error::Error,
19-
ros::RosNode,
2019
};
2120

2221
#[tokio::main(flavor = "multi_thread")]
@@ -200,8 +199,10 @@ fn spawn_ros_to_zenoh_forwarder<T: 'static + Serialize + DeserializeOwned + Send
200199
ros_type_name: MessageTypeName,
201200
zenoh_topic_name: &'static str,
202201
) -> Result<Fuse<JoinHandle<Result<()>>>> {
203-
let ros_subscription: Subscription<T> =
204-
ros_node.subscribe(ros_namespace, ros_topic_name, ros_type_name)?;
202+
let ros_topic = ros::create_topic(ros_node, ros_namespace, ros_topic_name, ros_type_name)?;
203+
let ros_subscription: Subscription<T> = ros_node
204+
.create_subscription(&ros_topic, None)
205+
.wrap_err("failed to create subscription")?;
205206

206207
Ok(tokio::spawn(forward_ros_to_zenoh(
207208
ros_subscription,
@@ -219,8 +220,10 @@ fn spawn_zenoh_to_ros_forwarder<T: 'static + Serialize + DeserializeOwned + Send
219220
ros_type_name: MessageTypeName,
220221
zenoh_topic_name: &'static str,
221222
) -> Result<Fuse<JoinHandle<Result<()>>>> {
222-
let ros_publisher: Publisher<T> =
223-
ros_node.publisher(ros_namespace, ros_topic_name, ros_type_name)?;
223+
let ros_topic = ros::create_topic(ros_node, ros_namespace, ros_topic_name, ros_type_name)?;
224+
let ros_publisher: Publisher<T> = ros_node
225+
.create_publisher(&ros_topic, None)
226+
.wrap_err("failed to create publisher")?;
224227

225228
Ok(tokio::spawn(forward_zenoh_to_ros(
226229
zenoh_session,

crates/zenoh_bridge/src/ros.rs

Lines changed: 24 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,28 @@
11
use color_eyre::eyre::Context;
22
use color_eyre::Result;
3-
use ros2_client::{MessageTypeName, Name, Node, Publisher, Subscription};
4-
use serde::Serialize;
3+
use ros2_client::{
4+
ros2::{
5+
policy::{Durability, History},
6+
Duration, QosPolicyBuilder,
7+
},
8+
rustdds::Topic,
9+
MessageTypeName, Name, Node,
10+
};
511

6-
pub trait RosNode {
7-
fn subscribe<T: 'static>(
8-
&mut self,
9-
namespace: &'static str,
10-
topic_name: &'static str,
11-
type_name: MessageTypeName,
12-
) -> Result<Subscription<T>>;
13-
14-
fn publisher<T: Serialize>(
15-
&mut self,
16-
namespace: &'static str,
17-
topic_name: &'static str,
18-
type_name: MessageTypeName,
19-
) -> Result<Publisher<T>>;
20-
}
21-
22-
impl RosNode for Node {
23-
fn subscribe<T: 'static>(
24-
&mut self,
25-
namespace: &'static str,
26-
topic_name: &'static str,
27-
type_name: MessageTypeName,
28-
) -> Result<Subscription<T>> {
29-
let topic = self
30-
.create_topic(
31-
&Name::new(namespace, topic_name).wrap_err("failed to create ROS topic name")?,
32-
type_name,
33-
&ros2_client::DEFAULT_SUBSCRIPTION_QOS,
34-
)
35-
.wrap_err("failed to create ROS topic")?;
36-
37-
self.create_subscription(&topic, None)
38-
.wrap_err("failed to create subscription")
39-
}
40-
41-
fn publisher<T: Serialize>(
42-
&mut self,
43-
namespace: &'static str,
44-
topic_name: &'static str,
45-
type_name: MessageTypeName,
46-
) -> Result<Publisher<T>> {
47-
let topic = self
48-
.create_topic(
49-
&Name::new(namespace, topic_name).wrap_err("failed to create ROS topic name")?,
50-
type_name,
51-
&ros2_client::DEFAULT_SUBSCRIPTION_QOS,
52-
)
53-
.wrap_err("failed to create ROS topic")?;
54-
55-
self.create_publisher(&topic, None)
56-
.wrap_err("failed to create publisher")
57-
}
12+
pub fn create_topic(
13+
node: &mut Node,
14+
namespace: &'static str,
15+
topic_name: &'static str,
16+
type_name: MessageTypeName,
17+
) -> Result<Topic> {
18+
node.create_topic(
19+
&Name::new(namespace, topic_name).wrap_err("failed to create ROS topic name")?,
20+
type_name,
21+
&QosPolicyBuilder::new()
22+
.reliable(Duration::INFINITE)
23+
.history(History::KeepLast { depth: 1 })
24+
.durability(Durability::TransientLocal)
25+
.build(),
26+
)
27+
.wrap_err("failed to create ROS topic")
5828
}

0 commit comments

Comments
 (0)