Skip to content

Commit 3d90897

Browse files
authored
Support bridge namespaces (#225)
1 parent b933733 commit 3d90897

File tree

7 files changed

+42
-24
lines changed

7 files changed

+42
-24
lines changed

DEFAULT_CONFIG.json5

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,18 @@
2020
// ros_hostname: "hostname",
2121

2222
////
23-
//// ros_name: A bridge node's name for ROS1, the default is "ros1_to_zenoh_bridge"
23+
//// ros_name: A bridge node's name for ROS1, the default is "ros1_to_zenoh_bridge"
2424
////
2525
// ros_name: "ros1_to_zenoh_bridge",
2626

2727
////
28-
//// with_rosmaster: An option wether the bridge should run it's own rosmaster process, the default is "false"
28+
//// bridge_namespace: A bridge's namespace in terms of zenoh keys, the default is "*", the wildcard namespace.
29+
//// The generated zenoh keys will be in the form of {data_type}/{md5}/{bridge_namespace}/{topic}.
30+
////
31+
// bridge_namespace: "*",
32+
33+
////
34+
//// with_rosmaster: An option wether the bridge should run it's own rosmaster process, the default is "false"
2935
////
3036
// with_rosmaster: "false",
3137

@@ -59,13 +65,13 @@
5965
//// - ROS1 doesn't allow multiple services on the same topic
6066
//// Due to this, client's bridging works differently compared to pub\sub bridging:
6167
//// - lazy bridging mode is not available as there is no way to discover local ROS1 clients
62-
//// - client bridging is disabled by default, as it may brake the local ROS1 system if it intends to have client and service interacting on the same topic
68+
//// - client bridging is disabled by default, as it may break the local ROS1 system if it intends to have client and service interacting on the same topic
6369
//// In order to use client bridging, you have two options:
6470
//// - globally select auto bridging mode (with caution!) with this option
6571
//// - bridge specific topics using 'client_topic_custom_bridging_mode' option (with a little bit less caution!)"#
6672
// client_bridging_mode: "disabled",
6773

68-
////
74+
////
6975
//// subscriber_topic_custom_bridging_mode: A JSON Map describing custom bridging modes for particular topics.
7076
//// Custom bridging mode overrides the global one.
7177
//// Format: {"topic1":"mode", "topic2":"mode"}
@@ -76,7 +82,7 @@
7682
//// The default is empty
7783
// subscriber_topic_custom_bridging_mode: ""
7884

79-
////
85+
////
8086
//// publisher_topic_custom_bridging_mode: A JSON Map describing custom bridging modes for particular topics.
8187
//// Custom bridging mode overrides the global one.
8288
//// Format: {"topic1":"mode", "topic2":"mode"}
@@ -87,7 +93,7 @@
8793
//// The default is empty
8894
// publisher_topic_custom_bridging_mode: ""
8995

90-
////
96+
////
9197
//// service_topic_custom_bridging_mode: A JSON Map describing custom bridging modes for particular topics.
9298
//// Custom bridging mode overrides the global one.
9399
//// Format: {"topic1":"mode", "topic2":"mode"}
@@ -98,7 +104,7 @@
98104
//// The default is empty
99105
// service_topic_custom_bridging_mode: ""
100106

101-
////
107+
////
102108
//// client_topic_custom_bridging_mode: A JSON Map describing custom bridging modes for particular topics.
103109
//// Custom bridging mode overrides the global one.
104110
//// Format: {"topic1":"mode", "topic2":"mode"}
@@ -120,19 +126,19 @@
120126
// ros_master_polling_interval: "100ms",
121127

122128
////
123-
//// This plugin uses Tokio (https://tokio.rs/) for asynchronous programming.
129+
//// This plugin uses Tokio (https://tokio.rs/) for asynchronous programming.
124130
//// When running as a plugin within a Zenoh router, the plugin creates its own Runtime managing 2 pools of threads:
125131
//// - worker threads for non-blocking tasks. Those threads are spawn at Runtime creation.
126132
//// - blocking threads for blocking tasks (e.g. I/O). Those threads are spawn when needed.
127133
//// For more details see https://github.com/tokio-rs/tokio/discussions/3858#discussioncomment-869878
128134
//// When running as a standalone bridge the Zenoh Session's Runtime is used and can be configured via the
129135
//// `ZENOH_RUNTIME` environment variable. See https://docs.rs/zenoh-runtime/latest/zenoh_runtime/enum.ZRuntime.html
130136
////
131-
137+
132138
//// work_thread_num: The number of worker thread in the asynchronous runtime will use. (default: 2)
133139
//// Only for a plugin, no effect on a bridge.
134140
// work_thread_num: 2,
135-
141+
136142
//// max_block_thread_num: The number of blocking thread in the asynchronous runtime will use. (default: 50)
137143
//// Only for a plugin, no effect on a bridge.
138144
// max_block_thread_num: 50,
@@ -176,7 +182,7 @@
176182

177183
////
178184
//// Which endpoints to listen on. E.g. tcp/localhost:7447.
179-
//// By configuring the endpoints, it is possible to tell zenoh which are the endpoints that other routers,
185+
//// By configuring the endpoints, it is possible to tell zenoh which are the endpoints that other routers,
180186
//// peers, or client can use to establish a zenoh session.
181187
////
182188
listen: {

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<img src="https://raw.githubusercontent.com/eclipse-zenoh/zenoh/main/zenoh-dragon.png" height="150">
22

3-
<!---
3+
<!---
44
[![CI](https://github.com/eclipse-zenoh/zenoh-plugin-ros1/workflows/Rust/badge.svg)](https://github.com/eclipse-zenoh/zenoh-plugin-ros1/actions?query=workflow%3ARust)
55
--->
66
[![Discussion](https://img.shields.io/badge/discussion-on%20github-blue)](https://github.com/eclipse-zenoh/roadmap/discussions)
@@ -36,17 +36,17 @@ To install the latest release of either the ROS1 plugin for the Zenoh router, ei
3636

3737
### Manual installation (all platforms)
3838

39-
All release packages can be downloaded from:
39+
All release packages can be downloaded from:
4040

4141
- [https://download.eclipse.org/zenoh/zenoh-plugin-ros1/latest/](https://download.eclipse.org/zenoh/zenoh-plugin-ros1/latest/)
4242

4343
Each subdirectory has the name of the Rust target. See the platforms each target corresponds to on [https://doc.rust-lang.org/stable/rustc/platform-support.html](https://doc.rust-lang.org/stable/rustc/platform-support.html)
4444

4545
Choose your platform and download:
4646

47-
- the `zenoh-plugin-ros1-<version>-<platform>.zip` file for the plugin.
47+
- the `zenoh-plugin-ros1-<version>-<platform>.zip` file for the plugin.
4848
Then unzip it in the same directory than `zenohd` or to any directory where it can find the plugin library (e.g. /usr/lib)
49-
- the `zenoh-bridge-ros1-<version>-<platform>.zip` file for the standalone executable.
49+
- the `zenoh-bridge-ros1-<version>-<platform>.zip` file for the standalone executable.
5050
Then unzip it where you want, and run the extracted `zenoh-bridge-ros1` binary.
5151

5252
### Linux Debian
@@ -104,7 +104,7 @@ The **`zenoh-bridge-ros1`** standalone executable is also available as a [Docker
104104
- `docker pull eclipse/zenoh-bridge-ros1:latest` for the latest release
105105
- `docker pull eclipse/zenoh-bridge-ros1:main` for the main branch version (nightly build)
106106

107-
Usage: **`docker run --init --net host eclipse/zenoh-bridge-ros1`**
107+
Usage: **`docker run --init --net host eclipse/zenoh-bridge-ros1`**
108108
It supports the same command line arguments than the `zenoh-bridge-ros1` (see below or check with `-h` argument).
109109

110110
## A quick test with built-in examples
@@ -115,7 +115,7 @@ If you want to run examples or tests, you need to install ROS1:
115115
sudo apt install -y ros-base
116116
```
117117

118-
There is a set of example utilities illustarating bridge in operation.
118+
There is a set of example utilities illustrating bridge in operation.
119119
Here is a description on how to configure the following schema:
120120

121121
```raw

zenoh-bridge-ros1/src/main.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ r#"--ros_name=[String] 'A bridge node's name for ROS1, the default is "ros1_to
101101
r#"--ros_namespace=[String] 'A bridge's namespace in terms of ROS1, the default is empty'"#
102102
))
103103
.arg(Arg::from_usage(
104+
r#"--bridge_namespace=[String] 'A bridge's namespace in terms of zenoh keys, the default is "*", the wildcard namespace'"#
105+
))
106+
.arg(Arg::from_usage(
104107
r#"--with_rosmaster=[bool] 'Start rosmaster with the bridge, the default is "false"'"#
105108
))
106109
.arg(Arg::from_usage(
@@ -134,7 +137,7 @@ r#"--client_bridging_mode=[String] \
134137
- ROS1 doesn't allow multiple services on the same topic
135138
Due to this, client's bridging works differently compared to pub\sub bridging:
136139
- lazy bridging mode is not available as there is no way to discover local ROS1 clients
137-
- client bridging is disabled by default, as it may brake the local ROS1 system if it intends to have client and service interacting on the same topic
140+
- client bridging is disabled by default, as it may break the local ROS1 system if it intends to have client and service interacting on the same topic
138141
In order to use client bridging, you have two options:
139142
- globally select auto bridging mode (with caution!) with this option
140143
- bridge specific topics using 'client_topic_custom_bridging_mode' option (with a little bit less caution!)"#
@@ -283,7 +286,7 @@ async fn main() {
283286
plugins_mgr.declare_static_plugin::<zenoh_plugin_rest::RestPlugin, &str>("ros1", true);
284287
}
285288

286-
// declare ROS2DDS plugin
289+
// declare ROS 1 plugin
287290
plugins_mgr.declare_static_plugin::<zenoh_plugin_ros1::Ros1Plugin, &str>("ros1", true);
288291

289292
// create a zenoh Runtime.

zenoh-plugin-ros1/src/ros_to_zenoh_bridge/discovery.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ impl RemoteResources {
154154
let md5 = discovery.md5().to_string();
155155

156156
let resource_class = discovery.resource_class().to_string();
157-
//let bridge_namespace = discovery.bridge_namespace().ok_or("No bridge_namespace present!")?.to_string();
158157
let topic = discovery.topic().ok_or("No topic present!")?;
159158

160159
let ros1_topic = make_topic(datatype, &md5, topic);

zenoh-plugin-ros1/src/ros_to_zenoh_bridge/environment.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ impl Environment {
127127
return Entry::new("ROS_NAMESPACE", namespace());
128128
}
129129

130+
pub fn bridge_namespace() -> Entry<'static, String> {
131+
return Entry::new("BRIDGE_NAMESPACE", "*".to_string());
132+
}
133+
130134
pub fn with_rosmaster() -> Entry<'static, bool> {
131135
return Entry::new("WITH_ROSMASTER", false);
132136
}
@@ -192,6 +196,7 @@ impl Environment {
192196
Self::ros_hostname(),
193197
Self::ros_name(),
194198
Self::ros_namespace(),
199+
Self::bridge_namespace(),
195200
Self::subscriber_bridging_mode().into(),
196201
Self::publisher_bridging_mode().into(),
197202
Self::service_bridging_mode().into(),

zenoh-plugin-ros1/src/ros_to_zenoh_bridge/ros1_to_zenoh_bridge_impl.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ where
8282

8383
let local_resources = Arc::new(LocalResources::new(
8484
"*".to_string(),
85-
"*".to_string(),
85+
Environment::bridge_namespace().get(),
8686
session.clone(),
8787
));
8888

@@ -108,7 +108,11 @@ async fn make_remote_resources_discovery<'a>(
108108
) -> RemoteResources {
109109
let bridges2 = bridges.clone();
110110

111-
let builder = RemoteResourcesBuilder::new("*".to_string(), "*".to_string(), session);
111+
let builder = RemoteResourcesBuilder::new(
112+
"*".to_string(),
113+
Environment::bridge_namespace().get(),
114+
session,
115+
);
112116
builder
113117
.on_discovered(move |b_type, topic| {
114118
let bridges = bridges.clone();

zenoh-plugin-ros1/src/ros_to_zenoh_bridge/topic_utilities.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ use zenoh::key_expr::{
1717
keyexpr, OwnedKeyExpr,
1818
};
1919

20-
use super::topic_descriptor::TopicDescriptor;
20+
use super::{environment::Environment, topic_descriptor::TopicDescriptor};
2121

2222
kedefine!(
23-
pub ros_mapping_format: "${data_type:*}/${md5:*}/${topic:**}",
23+
pub ros_mapping_format: "${data_type:*}/${md5:*}/${bridge_ns:*}/${topic:**}",
2424
);
2525

2626
pub fn make_topic_key(topic: &TopicDescriptor) -> &str {
@@ -31,6 +31,7 @@ pub fn make_zenoh_key(topic: &TopicDescriptor) -> OwnedKeyExpr {
3131
let mut formatter = ros_mapping_format::formatter();
3232
keformat!(
3333
formatter,
34+
bridge_ns = Environment::bridge_namespace().get(),
3435
data_type = hex::encode(topic.datatype.as_bytes()),
3536
md5 = topic.md5.clone(),
3637
topic = make_topic_key(topic)

0 commit comments

Comments
 (0)