Skip to content

Commit

Permalink
Prepare for first release (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowhatter authored Sep 22, 2023
1 parent c4ddf31 commit f6b5398
Show file tree
Hide file tree
Showing 26 changed files with 1,491 additions and 935 deletions.
317 changes: 146 additions & 171 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ async-std = "=1.12.0"
clap = "3.2.23"
ctrlc = "3.2.5"
env_logger = "0.9.1"
flume = "0.10.14"
futures = "0.3.24"
git-version = "0.3.5"
lazy_static = "1.4.0"
Expand All @@ -52,8 +51,10 @@ zenoh-ext = { git = "https://github.com/eclipse-zenoh/zenoh.git", features = ["u
zenoh-core = { git = "https://github.com/eclipse-zenoh/zenoh.git" }
zenoh-plugin-trait = { git = "https://github.com/eclipse-zenoh/zenoh.git", default-features = false }
rosrust = { git = "https://github.com/ZettaScaleLabs/rosrust.git", branch = "feature/fix_bugs" }
rustc_version = "0.4"
flume = "0.11"
hex = "0.4.3"
xml-rpc = "0.0.12"
rustc_version = "0.4"

[profile.release]
debug = false
Expand Down
14 changes: 9 additions & 5 deletions zenoh-bridge-ros1/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ r#"--client_bridging_mode=[String] \
.arg(Arg::from_usage(
r#"--subscriber_topic_custom_bridging_mode=[JSON] 'A JSON Map describing custom bridging modes for particular topics.
Custom bridging mode overrides the global one.
Format: {[topic, mode]}
Format: {"topic", "mode"}
Example: {\"/my/topic1\":\"lazy_auto\",\"/my/topic2\":\"auto\"}
where
- topic: ROS1 topic name
- mode (auto/lazy_auto/disabled) as described above
Expand All @@ -147,7 +148,8 @@ The default is empty'"#
.arg(Arg::from_usage(
r#"--publisher_topic_custom_bridging_mode=[JSON] 'A JSON Map describing custom bridging modes for particular topics.
Custom bridging mode overrides the global one.
Format: {[topic, mode]}
Format: {"topic", "mode"}
Example: {\"/my/topic1\":\"lazy_auto\",\"/my/topic2\":\"auto\"}
where
- topic: ROS1 topic name
- mode (auto/lazy_auto/disabled) as described above
Expand All @@ -156,7 +158,8 @@ The default is empty'"#
.arg(Arg::from_usage(
r#"--service_topic_custom_bridging_mode=[JSON] 'A JSON Map describing custom bridging modes for particular topics.
Custom bridging mode overrides the global one.
Format: {[topic, mode]}
Format: {"topic", "mode"}
Example: {\"/my/topic1\":\"lazy_auto\",\"/my/topic2\":\"auto\"}
where
- topic: ROS1 topic name
- mode (auto/lazy_auto/disabled) as described above
Expand All @@ -165,10 +168,11 @@ The default is empty'"#
.arg(Arg::from_usage(
r#"--client_topic_custom_bridging_mode=[JSON] 'A JSON Map describing custom bridging modes for particular topics.
Custom bridging mode overrides the global one.
Format: {[topic, mode]}
Format: {"topic", "mode"}
Example: {\"/my/topic1\":\"auto\",\"/my/topic2\":\"auto\"}
where
- topic: ROS1 topic name
- mode (auto/lazy_auto/disabled) as described above
- mode (auto/disabled) as described above
The default is empty'"#
))
.arg(Arg::from_usage(
Expand Down
1 change: 1 addition & 0 deletions zenoh-plugin-ros1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ zenoh-core = { workspace = true }
zenoh-plugin-trait = { workspace = true }
rosrust = { workspace = true }
hex = { workspace = true }
xml-rpc = { workspace = true }

[dev-dependencies]
serial_test = "0.10.0"
Expand Down
10 changes: 7 additions & 3 deletions zenoh-plugin-ros1/src/ros_to_zenoh_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,18 @@ pub mod bridging_mode;
#[cfg(feature = "test")]
pub mod discovery;
#[cfg(feature = "test")]
pub mod resource_cache;
#[cfg(feature = "test")]
pub mod ros1_client;
#[cfg(feature = "test")]
pub mod ros1_to_zenoh_bridge_impl;
#[cfg(feature = "test")]
pub mod rosclient_test_helpers;
#[cfg(feature = "test")]
pub mod service_cache;
#[cfg(feature = "test")]
pub mod test_helpers;
#[cfg(feature = "test")]
pub mod topic_descriptor;
#[cfg(feature = "test")]
pub mod topic_utilities;
#[cfg(feature = "test")]
pub mod zenoh_client;
Expand All @@ -61,11 +63,13 @@ mod bridging_mode;
#[cfg(not(feature = "test"))]
mod discovery;
#[cfg(not(feature = "test"))]
mod resource_cache;
#[cfg(not(feature = "test"))]
mod ros1_client;
#[cfg(not(feature = "test"))]
mod ros1_to_zenoh_bridge_impl;
#[cfg(not(feature = "test"))]
mod service_cache;
mod topic_descriptor;
#[cfg(not(feature = "test"))]
mod topic_utilities;
#[cfg(not(feature = "test"))]
Expand Down
39 changes: 21 additions & 18 deletions zenoh-plugin-ros1/src/ros_to_zenoh_bridge/abstract_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ use std::sync::Arc;
use log::{debug, error, info};

use rosrust::RawMessageDescription;
use zenoh::{plugins::ZResult, prelude::SplitBuffer};
use zenoh::{
plugins::ZResult,
prelude::{keyexpr, SplitBuffer},
};
use zenoh_core::{AsyncResolve, SyncResolve};

use super::{bridge_type::BridgeType, ros1_client, topic_utilities::make_zenoh_key, zenoh_client};
use super::{
bridge_type::BridgeType, ros1_client, topic_descriptor::TopicDescriptor,
topic_utilities::make_zenoh_key, zenoh_client,
};

pub struct AbstractBridge {
_impl: BridgeIml,
Expand All @@ -29,7 +35,7 @@ pub struct AbstractBridge {
impl AbstractBridge {
pub async fn new(
b_type: BridgeType,
topic: &rosrust::api::Topic,
topic: &TopicDescriptor,
ros1_client: &ros1_client::Ros1Client,
zenoh_client: &Arc<zenoh_client::ZenohClient>,
) -> ZResult<Self> {
Expand Down Expand Up @@ -65,16 +71,13 @@ struct Ros1ToZenohClient {
}
impl Ros1ToZenohClient {
async fn new(
topic: &rosrust::api::Topic,
topic: &TopicDescriptor,
ros1_client: &ros1_client::Ros1Client,
zenoh_client: Arc<zenoh_client::ZenohClient>,
) -> ZResult<Ros1ToZenohClient> {
info!(
"Creating ROS1 -> Zenoh Client bridge for topic {}, datatype {}",
topic.name, topic.datatype
);
info!("Creating ROS1 -> Zenoh Client bridge for {:?}", topic);

let zenoh_key = make_zenoh_key(topic).to_string();
let zenoh_key = make_zenoh_key(topic);
match ros1_client.service::<rosrust::RawMessage, _>(
topic,
move |q| -> rosrust::ServiceResult<rosrust::RawMessage> {
Expand All @@ -83,22 +86,22 @@ impl Ros1ToZenohClient {
) {
Ok(service) => Ok(Ros1ToZenohClient { _service: service }),
Err(e) => {
zenoh_core::bail!("Ros error: {}", e.to_string())
zenoh_core::bail!("Ros error: {}", e)
}
}
}

//PRIVATE:
fn on_query(
key: &str,
key: &keyexpr,
query: rosrust::RawMessage,
zenoh_client: &zenoh_client::ZenohClient,
) -> rosrust::ServiceResult<rosrust::RawMessage> {
return async_std::task::block_on(Self::do_zenoh_query(key, query, zenoh_client));
}

async fn do_zenoh_query(
key: &str,
key: &keyexpr,
query: rosrust::RawMessage,
zenoh_client: &zenoh_client::ZenohClient,
) -> rosrust::ServiceResult<rosrust::RawMessage> {
Expand Down Expand Up @@ -145,7 +148,7 @@ struct Ros1ToZenohService {
}
impl Ros1ToZenohService {
async fn new<'b>(
topic: &rosrust::api::Topic,
topic: &TopicDescriptor,
ros1_client: &ros1_client::Ros1Client,
zenoh_client: &'b zenoh_client::ZenohClient,
) -> ZResult<Ros1ToZenohService> {
Expand Down Expand Up @@ -181,7 +184,7 @@ impl Ros1ToZenohService {
async fn on_query(
ros1_client: Arc<rosrust::Client<rosrust::RawMessage>>,
query: zenoh::queryable::Query,
topic: Arc<rosrust::api::Topic>,
topic: Arc<TopicDescriptor>,
) {
match query.value() {
Some(val) => {
Expand All @@ -202,14 +205,14 @@ impl Ros1ToZenohService {
ros1_client: Arc<rosrust::Client<rosrust::RawMessage>>,
query: zenoh::queryable::Query,
payload: Vec<u8>,
topic: Arc<rosrust::api::Topic>,
topic: Arc<TopicDescriptor>,
) {
// rosrust is synchronous, so we will use spawn_blocking. If there will be an async mode some day for the rosrust,
// than reply_to_query can be refactored to async very easily
let res = async_std::task::spawn_blocking(move || {
let description = RawMessageDescription {
msg_definition: String::from("*"),
md5sum: String::from("*"),
md5sum: topic.md5.clone(),
msg_type: topic.datatype.clone(),
};
ros1_client.req_with_description(&rosrust::RawMessage(payload), description)
Expand Down Expand Up @@ -278,7 +281,7 @@ struct Ros1ToZenoh {
}
impl Ros1ToZenoh {
async fn new<'b>(
topic: &rosrust::api::Topic,
topic: &TopicDescriptor,
ros1_client: &ros1_client::Ros1Client,
zenoh_client: &'b zenoh_client::ZenohClient,
) -> ZResult<Ros1ToZenoh> {
Expand Down Expand Up @@ -312,7 +315,7 @@ struct ZenohToRos1 {
}
impl ZenohToRos1 {
async fn new(
topic: &rosrust::api::Topic,
topic: &TopicDescriptor,
ros1_client: &ros1_client::Ros1Client,
zenoh_client: &Arc<zenoh_client::ZenohClient>,
) -> ZResult<Self> {
Expand Down
38 changes: 18 additions & 20 deletions zenoh-plugin-ros1/src/ros_to_zenoh_bridge/bridges_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ use super::{
ros1_client,
ros1_to_zenoh_bridge_impl::BridgeStatus,
topic_bridge::TopicBridge,
topic_descriptor::TopicDescriptor,
topic_mapping::Ros1TopicMapping,
zenoh_client,
};

struct Bridges {
publisher_bridges: HashMap<rosrust::api::Topic, TopicBridge>,
subscriber_bridges: HashMap<rosrust::api::Topic, TopicBridge>,
service_bridges: HashMap<rosrust::api::Topic, TopicBridge>,
client_bridges: HashMap<rosrust::api::Topic, TopicBridge>,
publisher_bridges: HashMap<TopicDescriptor, TopicBridge>,
subscriber_bridges: HashMap<TopicDescriptor, TopicBridge>,
service_bridges: HashMap<TopicDescriptor, TopicBridge>,
client_bridges: HashMap<TopicDescriptor, TopicBridge>,
}
impl Bridges {
fn new() -> Self {
Expand All @@ -44,10 +45,7 @@ impl Bridges {
}
}

fn container_mut(
&mut self,
b_type: BridgeType,
) -> &mut HashMap<rosrust::api::Topic, TopicBridge> {
fn container_mut(&mut self, b_type: BridgeType) -> &mut HashMap<TopicDescriptor, TopicBridge> {
match b_type {
BridgeType::Publisher => &mut self.publisher_bridges,
BridgeType::Subscriber => &mut self.subscriber_bridges,
Expand All @@ -58,7 +56,7 @@ impl Bridges {

fn status(&self) -> BridgeStatus {
let fill = |status: &mut (usize, usize),
bridges: &HashMap<rosrust::api::Topic, TopicBridge>| {
bridges: &HashMap<TopicDescriptor, TopicBridge>| {
for (_topic, bridge) in bridges.iter() {
status.0 += 1;
if bridge.is_bridging() {
Expand All @@ -84,7 +82,7 @@ impl Bridges {
}

struct Access<'a> {
container: &'a mut HashMap<rosrust::api::Topic, TopicBridge>,
container: &'a mut HashMap<TopicDescriptor, TopicBridge>,
b_type: BridgeType,
ros1_client: Arc<ros1_client::Ros1Client>,
zenoh_client: Arc<zenoh_client::ZenohClient>,
Expand All @@ -94,7 +92,7 @@ struct Access<'a> {
impl<'a> Access<'a> {
fn new(
b_type: BridgeType,
container: &'a mut HashMap<rosrust::api::Topic, TopicBridge>,
container: &'a mut HashMap<TopicDescriptor, TopicBridge>,
ros1_client: Arc<ros1_client::Ros1Client>,
zenoh_client: Arc<zenoh_client::ZenohClient>,
declaration_interface: Arc<LocalResources>,
Expand All @@ -116,7 +114,7 @@ pub struct ComplementaryElementAccessor<'a> {
impl<'a> ComplementaryElementAccessor<'a> {
fn new(
b_type: BridgeType,
container: &'a mut HashMap<rosrust::api::Topic, TopicBridge>,
container: &'a mut HashMap<TopicDescriptor, TopicBridge>,
ros1_client: Arc<ros1_client::Ros1Client>,
zenoh_client: Arc<zenoh_client::ZenohClient>,
declaration_interface: Arc<LocalResources>,
Expand All @@ -132,7 +130,7 @@ impl<'a> ComplementaryElementAccessor<'a> {
}
}

pub async fn complementary_entity_lost(&mut self, topic: rosrust::api::Topic) {
pub async fn complementary_entity_lost(&mut self, topic: TopicDescriptor) {
match self.access.container.entry(topic) {
Entry::Occupied(mut val) => {
let bridge = val.get_mut();
Expand All @@ -144,7 +142,7 @@ impl<'a> ComplementaryElementAccessor<'a> {
}
}

pub async fn complementary_entity_discovered(&mut self, topic: rosrust::api::Topic) {
pub async fn complementary_entity_discovered(&mut self, topic: TopicDescriptor) {
let b_mode = bridging_mode(self.access.b_type, topic.name.as_str());
if b_mode != BridgingMode::Disabled {
match self.access.container.entry(topic) {
Expand Down Expand Up @@ -175,7 +173,7 @@ pub struct ElementAccessor<'a> {
impl<'a> ElementAccessor<'a> {
fn new(
b_type: BridgeType,
container: &'a mut HashMap<rosrust::api::Topic, TopicBridge>,
container: &'a mut HashMap<TopicDescriptor, TopicBridge>,
ros1_client: Arc<ros1_client::Ros1Client>,
zenoh_client: Arc<zenoh_client::ZenohClient>,
declaration_interface: Arc<LocalResources>,
Expand All @@ -193,7 +191,7 @@ impl<'a> ElementAccessor<'a> {

async fn receive_ros1_state(
&mut self,
part_of_ros_state: &mut HashSet<rosrust::api::Topic>,
part_of_ros_state: &mut HashSet<TopicDescriptor>,
) -> bool {
let mut smth_changed = false;
// Run through bridges and actualize their state based on ROS1 state, removing corresponding entries from ROS1 state.
Expand All @@ -214,16 +212,16 @@ impl<'a> ElementAccessor<'a> {
}

// run through the topics and create corresponding bridges
for ros_topic in part_of_ros_state.iter() {
let b_mode = bridging_mode(self.access.b_type, ros_topic.name.as_str());
for topic in part_of_ros_state.iter() {
let b_mode = bridging_mode(self.access.b_type, &topic.name);
if b_mode != BridgingMode::Disabled {
match self.access.container.entry(ros_topic.clone()) {
match self.access.container.entry(topic.clone()) {
Entry::Occupied(_val) => {
debug_assert!(false); // that shouldn't happen
}
Entry::Vacant(val) => {
let inserted = val.insert(TopicBridge::new(
ros_topic.clone(),
topic.clone(),
self.access.b_type,
self.access.declaration_interface.clone(),
self.access.ros1_client.clone(),
Expand Down
1 change: 1 addition & 0 deletions zenoh-plugin-ros1/src/ros_to_zenoh_bridge/bridging_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use super::{bridge_type::BridgeType, environment::Environment};
#[derive(PartialEq, Eq, EnumString, Clone, Display)]
#[strum(serialize_all = "snake_case")]
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "snake_case")]
pub enum BridgingMode {
LazyAuto,
Auto,
Expand Down
Loading

0 comments on commit f6b5398

Please sign in to comment.