From 935c1160ad9cfd3d9a4410057ae7af6b0d1fdb2f Mon Sep 17 00:00:00 2001 From: Steven Palma Date: Tue, 2 Apr 2024 17:01:16 +0200 Subject: [PATCH 1/9] [WIP] Restructured Examples directory Python --- examples/python/{ => src}/add_two_ints_client.py | 0 examples/python/{ => src}/fibonnacci_action_client.py | 0 examples/python/{ => src}/listener.py | 0 examples/python/{ => src}/talker.py | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename examples/python/{ => src}/add_two_ints_client.py (100%) rename examples/python/{ => src}/fibonnacci_action_client.py (100%) rename examples/python/{ => src}/listener.py (100%) rename examples/python/{ => src}/talker.py (100%) diff --git a/examples/python/add_two_ints_client.py b/examples/python/src/add_two_ints_client.py similarity index 100% rename from examples/python/add_two_ints_client.py rename to examples/python/src/add_two_ints_client.py diff --git a/examples/python/fibonnacci_action_client.py b/examples/python/src/fibonnacci_action_client.py similarity index 100% rename from examples/python/fibonnacci_action_client.py rename to examples/python/src/fibonnacci_action_client.py diff --git a/examples/python/listener.py b/examples/python/src/listener.py similarity index 100% rename from examples/python/listener.py rename to examples/python/src/listener.py diff --git a/examples/python/talker.py b/examples/python/src/talker.py similarity index 100% rename from examples/python/talker.py rename to examples/python/src/talker.py From 9709d95198595dd7c3651e59dd655b8e3cc5ebd5 Mon Sep 17 00:00:00 2001 From: Steven Palma Date: Tue, 2 Apr 2024 17:02:03 +0200 Subject: [PATCH 2/9] [WIP] Added rust examples sub & pub --- examples/rust/Cargo.toml | 17 ++++++++ examples/rust/README.md | 1 + examples/rust/src/bin/listener.rs | 64 +++++++++++++++++++++++++++++ examples/rust/src/bin/talker.rs | 67 +++++++++++++++++++++++++++++++ 4 files changed, 149 insertions(+) create mode 100644 examples/rust/Cargo.toml create mode 100644 examples/rust/README.md create mode 100644 examples/rust/src/bin/listener.rs create mode 100644 examples/rust/src/bin/talker.rs diff --git a/examples/rust/Cargo.toml b/examples/rust/Cargo.toml new file mode 100644 index 0000000..672405d --- /dev/null +++ b/examples/rust/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "rust_examples" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[workspace] +[dependencies] +async-std = { version = "1.12.0" } +futures = { version = "0.3.28" } +zenoh = { version = "0.10.0-rc" } +clap = { version = "3.2.23" } +env_logger = { version = "0.10.0" } +serde = {version = "1" } +serde_derive = {version = "1"} +cdr = {version = "0.2.4"} +log = { version = "0.4.21"} \ No newline at end of file diff --git a/examples/rust/README.md b/examples/rust/README.md new file mode 100644 index 0000000..30404ce --- /dev/null +++ b/examples/rust/README.md @@ -0,0 +1 @@ +TODO \ No newline at end of file diff --git a/examples/rust/src/bin/listener.rs b/examples/rust/src/bin/listener.rs new file mode 100644 index 0000000..9c1d5f9 --- /dev/null +++ b/examples/rust/src/bin/listener.rs @@ -0,0 +1,64 @@ +// +// Copyright (c) 2023 ZettaScale Technology +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License 2.0 which is available at +// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// +// Contributors: +// ZettaScale Zenoh Team, +// +use clap::{App, Arg}; +use serde::Deserialize; +use zenoh::config::Config; +use zenoh::prelude::r#async::*; + +#[derive(Deserialize, PartialEq, Debug)] +struct Message { + data: String, +} +#[async_std::main] +async fn main() { + // Initiate logging + env_logger::init(); + + let config = parse_args(); + + println!("Opening session..."); + let session = zenoh::open(config).res().await.unwrap(); + + let key_expr = "chatter"; + println!("Declaring Subscriber on '{}'...", &key_expr); + let subscriber = session.declare_subscriber(key_expr).res().await.unwrap(); + + while let Ok(sample) = subscriber.recv_async().await { + match cdr::deserialize_from::<_, Message, _>( + sample.value.payload.reader(), + cdr::size::Infinite, + ) { + Ok(msg) => { + println!("I heard: [{}]", msg.data); + } + Err(e) => log::warn!("Error decoding message: {}", e), + } + } +} + +fn parse_args() -> Config { + let args = App::new("zenoh sub example") + .arg(Arg::from_usage( + "-c, --config=[FILE] 'A configuration file.'", + )) + .get_matches(); + + let config = if let Some(conf_file) = args.value_of("config") { + Config::from_file(conf_file).unwrap() + } else { + Config::default() + }; + + config +} diff --git a/examples/rust/src/bin/talker.rs b/examples/rust/src/bin/talker.rs new file mode 100644 index 0000000..c0a9fc6 --- /dev/null +++ b/examples/rust/src/bin/talker.rs @@ -0,0 +1,67 @@ +// +// Copyright (c) 2023 ZettaScale Technology +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License 2.0 which is available at +// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// +// Contributors: +// ZettaScale Zenoh Team, +// +use async_std::task::sleep; +use cdr::{CdrLe, Infinite}; +use clap::{App, Arg}; +use serde::Serialize; +use std::time::Duration; +use zenoh::config::Config; +use zenoh::prelude::r#async::*; + +#[derive(Serialize, PartialEq, Debug)] +struct Message { + data: String, +} + +#[async_std::main] +async fn main() { + // Initiate logging + env_logger::init(); + + let config = parse_args(); + + println!("Opening session..."); + let session = zenoh::open(config).res().await.unwrap(); + + let key_expr = "chatter"; + + println!("Declaring Publisher on '{key_expr}'..."); + let publisher = session.declare_publisher(key_expr).res().await.unwrap(); + + for idx in 0..u32::MAX { + sleep(Duration::from_secs(1)).await; + let message = Message { + data: format!("Hello World:{idx:4}"), + }; + let buf = cdr::serialize::<_, _, CdrLe>(&message, Infinite).unwrap(); + println!("Putting Data ('{}': '{}')...", &key_expr, message.data); + publisher.put(buf).res().await.unwrap(); + } +} + +fn parse_args() -> Config { + let args = App::new("zenoh talker example") + .arg(Arg::from_usage( + "-c, --config=[FILE] 'A configuration file.'", + )) + .get_matches(); + + let config = if let Some(conf_file) = args.value_of("config") { + Config::from_file(conf_file).unwrap() + } else { + Config::default() + }; + + config +} From 1081cf0cea311429892a80612ff3b16aaeb4899e Mon Sep 17 00:00:00 2001 From: Steven Palma Date: Wed, 3 Apr 2024 13:08:39 +0200 Subject: [PATCH 3/9] [WIP] Added add_two_ints_client Rust --- examples/python/src/add_two_ints_client.py | 2 +- examples/rust/src/bin/add_two_ints_client.rs | 75 ++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 examples/rust/src/bin/add_two_ints_client.rs diff --git a/examples/python/src/add_two_ints_client.py b/examples/python/src/add_two_ints_client.py index f25e83d..857d728 100644 --- a/examples/python/src/add_two_ints_client.py +++ b/examples/python/src/add_two_ints_client.py @@ -28,7 +28,7 @@ class AddTwoInts_Request(IdlStruct, typename="AddTwoInts_Request"): # Equivalent to AddTwoInts.Response class, but serializable by pycdr2 @dataclass -class AddTwoInts_Response(IdlStruct, typename="AddTwoInts_Request"): +class AddTwoInts_Response(IdlStruct, typename="AddTwoInts_Response"): sum: pycdr2.types.int64 def main(): diff --git a/examples/rust/src/bin/add_two_ints_client.rs b/examples/rust/src/bin/add_two_ints_client.rs new file mode 100644 index 0000000..3e6e843 --- /dev/null +++ b/examples/rust/src/bin/add_two_ints_client.rs @@ -0,0 +1,75 @@ +// +// Copyright (c) 2023 ZettaScale Technology +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License 2.0 which is available at +// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// +// Contributors: +// ZettaScale Zenoh Team, +// +use cdr::{CdrLe, Infinite}; +use clap::{App, Arg}; +use serde::{Deserialize, Serialize}; +use zenoh::config::Config; +use zenoh::prelude::r#async::*; + +#[derive(Serialize, PartialEq, Debug)] +struct AddTwoIntsRequest { + a: i64, + b: i64, +} + +#[derive(Deserialize, PartialEq, Debug)] +struct AddTwoIntsResponse { + sum: i64, +} + +#[async_std::main] +async fn main() { + env_logger::init(); + + let config = parse_args(); + + let session = zenoh::open(config).res().await.unwrap(); + + let req = AddTwoIntsRequest { a: 2, b: 3 }; + let buf = cdr::serialize::<_, _, CdrLe>(&req, Infinite).unwrap(); + let replies = session + .get("add_two_ints") + .with_value(buf) + .res() + .await + .unwrap(); + + while let Ok(reply) = replies.recv_async().await { + match cdr::deserialize_from::<_, AddTwoIntsResponse, _>( + reply.sample.unwrap().payload.reader(), + cdr::size::Infinite, + ) { + Ok(res) => { + println!("Result of add_two_ints: {}", res.sum); + } + Err(e) => log::warn!("Error decoding message: {}", e), + } + } +} + +fn parse_args() -> Config { + let args = App::new("zenoh sub example") + .arg(Arg::from_usage( + "-c, --config=[FILE] 'A configuration file.'", + )) + .get_matches(); + + let config = if let Some(conf_file) = args.value_of("config") { + Config::from_file(conf_file).unwrap() + } else { + Config::default() + }; + + config +} From d379fc73d600b0abc9fbfa2c26adf8c9c6017921 Mon Sep 17 00:00:00 2001 From: Steven Palma Date: Wed, 3 Apr 2024 13:54:28 +0200 Subject: [PATCH 4/9] [WIP] Changed prints Python --- examples/python/src/fibonnacci_action_client.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/python/src/fibonnacci_action_client.py b/examples/python/src/fibonnacci_action_client.py index 9a04791..b7483e1 100644 --- a/examples/python/src/fibonnacci_action_client.py +++ b/examples/python/src/fibonnacci_action_client.py @@ -60,7 +60,7 @@ class Fibonacci_Feedback(IdlStruct, typename="Fibonacci_Feedback"): def feedback_callback(sample: zenoh.Sample): # Deserialize the message feedback = Fibonacci_Feedback.deserialize(sample.payload) - print('Received feedback: {0}'.format(feedback.partial_sequence)) + print('Next number in sequence received: {0}'.format(feedback.partial_sequence)) def main(): @@ -84,6 +84,7 @@ def main(): goal_id = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] req = Fibonacci_SendGoal_Request(goal_id, order=10) # Send the query with the serialized request + print('Sending goal') replies = session.get('fibonacci/_action/send_goal', zenoh.Queue(), value=req.serialize()) # Zenoh could get several replies for a request (e.g. from several "Service Servers" using the same name) for reply in replies.receiver: @@ -93,7 +94,7 @@ def main(): print('Goal rejected :(') return - print('Goal accepted :)') + print('Goal accepted by server, waiting for result') req = Fibonacci_GetResult_Request(goal_id) # Send the query with the serialized request From b640e448bfbfcdd6111219704c684c3a04d03846 Mon Sep 17 00:00:00 2001 From: Steven Palma Date: Wed, 3 Apr 2024 13:54:57 +0200 Subject: [PATCH 5/9] [WIP] Added Fibonnacci Rust --- .../rust/src/bin/fibonnacci_action_client.rs | 150 ++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 examples/rust/src/bin/fibonnacci_action_client.rs diff --git a/examples/rust/src/bin/fibonnacci_action_client.rs b/examples/rust/src/bin/fibonnacci_action_client.rs new file mode 100644 index 0000000..f96c01d --- /dev/null +++ b/examples/rust/src/bin/fibonnacci_action_client.rs @@ -0,0 +1,150 @@ +// +// Copyright (c) 2023 ZettaScale Technology +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License 2.0 which is available at +// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// +// Contributors: +// ZettaScale Zenoh Team, +// +use cdr::{CdrLe, Infinite}; +use clap::{App, Arg}; +use serde::{Deserialize, Serialize}; +use zenoh::config::Config; +use zenoh::prelude::r#async::*; + +#[derive(Deserialize, PartialEq, Debug)] +struct Time { + sec: u32, + nsec: u32, +} + +#[derive(Serialize, PartialEq, Debug)] +struct FibonacciSendGoalRequest { + goal_id: [u8; 16], + order: i32, +} + +#[derive(Deserialize, PartialEq, Debug)] +struct FibonacciSendGoalResponse { + accepted: bool, + stamp: Time, +} + +#[derive(Serialize, PartialEq, Debug)] +struct FibonacciGetResultRequest { + goal_id: [u8; 16], +} + +#[derive(Deserialize, PartialEq, Debug)] +struct FibonacciGetResultResponse { + status: i8, + sequence: Vec, +} + +#[derive(Deserialize, PartialEq, Debug)] +struct FibonacciFeedback { + goal_id: [u8; 16], + partial_sequence: Vec, +} + +#[async_std::main] +async fn main() { + env_logger::init(); + + let config = parse_args(); + + let session = zenoh::open(config).res().await.unwrap(); + + let _subscriber = session + .declare_subscriber("fibonacci/_action/feedback") + .callback(|sample| { + match cdr::deserialize_from::<_, FibonacciFeedback, _>( + sample.value.payload.reader(), + cdr::size::Infinite, + ) { + Ok(msg) => { + println!( + "Next number in sequence received: {:?}", + msg.partial_sequence + ); + } + Err(e) => log::warn!("Error decoding message: {}", e), + }; + }) + .res() + .await + .unwrap(); + + let goal_id: [u8; 16] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]; + let req = FibonacciSendGoalRequest { + goal_id: goal_id, + order: 10, + }; + + let buf = cdr::serialize::<_, _, CdrLe>(&req, Infinite).unwrap(); + println!("Sending goal"); + let replies = session + .get("fibonacci/_action/send_goal") + .with_value(buf) + .res() + .await + .unwrap(); + + while let Ok(reply) = replies.recv_async().await { + match cdr::deserialize_from::<_, FibonacciSendGoalResponse, _>( + reply.sample.unwrap().payload.reader(), + cdr::size::Infinite, + ) { + Ok(res) => { + if res.accepted { + println!("Goal accepted by server, waiting for result"); + } else { + println!("Goal rejected :("); + return; + } + } + Err(e) => log::warn!("Error decoding message: {}", e), + } + } + + let req = FibonacciGetResultRequest { goal_id: goal_id }; + let buf = cdr::serialize::<_, _, CdrLe>(&req, Infinite).unwrap(); + let replies = session + .get("fibonacci/_action/get_result") + .with_value(buf) + .res() + .await + .unwrap(); + while let Ok(reply) = replies.recv_async().await { + match cdr::deserialize_from::<_, FibonacciGetResultResponse, _>( + reply.sample.unwrap().payload.reader(), + cdr::size::Infinite, + ) { + Ok(res) => { + println!("Result: {:?}", res.sequence); + } + Err(e) => log::warn!("Error decoding message: {}", e), + } + } +} + +fn parse_args() -> Config { + let args = App::new("zenoh sub example") + .arg(Arg::from_usage( + "-c, --config=[FILE] 'A configuration file.'", + )) + .get_matches(); + + let config = if let Some(conf_file) = args.value_of("config") { + Config::from_file(conf_file).unwrap() + } else { + Config::default() + }; + + config +} From 9a82244a2ba19edfda7482306ca68c8b4745fc97 Mon Sep 17 00:00:00 2001 From: Steven Palma Date: Thu, 4 Apr 2024 10:19:56 +0200 Subject: [PATCH 6/9] [WIP] typo python readme + link --- examples/python/README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/python/README.md b/examples/python/README.md index 628cdbf..af497e3 100644 --- a/examples/python/README.md +++ b/examples/python/README.md @@ -1,30 +1,30 @@ # Examples of Zenoh Python applications communicating with ROS 2 Nodes -## Messages Publication: [talker.py](talker.py) +## Messages Publication: [talker.py](src/talker.py) This code mimics the ROS 2 [Topics "talker" demo](https://github.com/ros2/demos/blob/rolling/demo_nodes_cpp/src/topics/talker.cpp). It's compatible with the ROS 2 [Topics "listener" demo](https://github.com/ros2/demos/blob/rolling/demo_nodes_cpp/src/topics/listener.cpp) running those commands: - `ros2 run demo_nodes_cpp listener` -- `zenho-bridge-ros2dds` +- `zenoh-bridge-ros2dds` - `python ./talker.py` -## Messages Subscription: [listener.py](listener.py) +## Messages Subscription: [listener.py](src/listener.py) This code mimics the ROS 2 [Topics "listener" demo](https://github.com/ros2/demos/blob/rolling/demo_nodes_cpp/src/topics/listener.cpp). It's compatible with the ROS 2 [Topics "talker" demo](https://github.com/ros2/demos/blob/rolling/demo_nodes_cpp/src/topics/talker.cpp) running those commands: - `ros2 run demo_nodes_cpp talker` -- `zenho-bridge-ros2dds` +- `zenoh-bridge-ros2dds` - `python ./listener.py` -## Services Client: [add_two_ints_client.py](add_two_ints_client.py) +## Services Client: [add_two_ints_client.py](src/add_two_ints_client.py) This code mimics the ROS 2 [Services "add_two_ints_client" demo](https://github.com/ros2/demos/blob/rolling/demo_nodes_cpp/src/services/add_two_ints_client.cpp). It's compatible with the ROS 2 [Services "add_two_ints_server" demo](https://github.com/ros2/demos/blob/rolling/demo_nodes_cpp/src/services/add_two_ints_server.cpp) running those commands: - `ros2 run demo_nodes_cpp add_two_ints_server` -- `zenho-bridge-ros2dds` +- `zenoh-bridge-ros2dds` - `python ./add_two_ints_client.py` -## Actions Client: [fibonnacci_action_client.py](fibonnacci_action_client.py) +## Actions Client: [fibonnacci_action_client.py](src/fibonnacci_action_client.py) This code mimics the ROS 2 [Actions "fibonnacci_action_client" demo](https://github.com/ros2/demos/blob/rolling/action_tutorials/action_tutorials_cpp/src/fibonacci_action_client.cpp). It's compatible with the ROS 2 [Actions "fibonnacci_action_server" demo](https://github.com/ros2/demos/blob/rolling/action_tutorials/action_tutorials_cpp/src/fibonacci_action_server.cpp) running those commands: - `ros2 run action_tutorials_cpp fibonacci_action_server` -- `zenho-bridge-ros2dds` +- `zenoh-bridge-ros2dds` - `python ./fibonnacci_action_client.py` From 27f1f02d9a59c31d44338b7970377a964b5a3a2e Mon Sep 17 00:00:00 2001 From: Steven Palma Date: Thu, 4 Apr 2024 10:20:14 +0200 Subject: [PATCH 7/9] [WIP] Push to zenoh 0.10.1 + rust readme + consistent prints --- examples/rust/Cargo.toml | 2 +- examples/rust/README.md | 41 ++++++++++++++++++++++++++++++- examples/rust/rust-toolchain.toml | 2 ++ examples/rust/src/bin/listener.rs | 4 +-- examples/rust/src/bin/talker.rs | 7 ++---- 5 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 examples/rust/rust-toolchain.toml diff --git a/examples/rust/Cargo.toml b/examples/rust/Cargo.toml index 672405d..41b6ae3 100644 --- a/examples/rust/Cargo.toml +++ b/examples/rust/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" [dependencies] async-std = { version = "1.12.0" } futures = { version = "0.3.28" } -zenoh = { version = "0.10.0-rc" } +zenoh = { version = "0.10.1-rc" } clap = { version = "3.2.23" } env_logger = { version = "0.10.0" } serde = {version = "1" } diff --git a/examples/rust/README.md b/examples/rust/README.md index 30404ce..0703d57 100644 --- a/examples/rust/README.md +++ b/examples/rust/README.md @@ -1 +1,40 @@ -TODO \ No newline at end of file +# Examples of Zenoh Rust applications communicating with ROS 2 Nodes + +## Building the examples +In order to build the examples you will need to: +* [Install Rust and Cargo](https://doc.rust-lang.org/cargo/getting-started/installation.html) +* [Install Zenoh Rust](https://github.com/eclipse-zenoh/zenoh?tab=readme-ov-file#how-to-install-it) + +Once this is done, compile by running the following: +``` +cd examples/rust +cargo build +``` + +## Messages Publication: [talker.rs](src/bin/talker.rs) + +This code mimics the ROS 2 [Topics "talker" demo](https://github.com/ros2/demos/blob/rolling/demo_nodes_cpp/src/topics/talker.cpp). It's compatible with the ROS 2 [Topics "listener" demo](https://github.com/ros2/demos/blob/rolling/demo_nodes_cpp/src/topics/listener.cpp) running those commands: +- `ros2 run demo_nodes_cpp listener` +- `zenoh-bridge-ros2dds` +- `cargo run --bin talker` + +## Messages Subscription: [listener.rs](src/bin/listener.rs) + +This code mimics the ROS 2 [Topics "listener" demo](https://github.com/ros2/demos/blob/rolling/demo_nodes_cpp/src/topics/listener.cpp). It's compatible with the ROS 2 [Topics "talker" demo](https://github.com/ros2/demos/blob/rolling/demo_nodes_cpp/src/topics/talker.cpp) running those commands: +- `ros2 run demo_nodes_cpp talker` +- `zenoh-bridge-ros2dds` +- `cargo run --bin listener` + +## Services Client: [add_two_ints_client.rs](src/bin/add_two_ints_client.rs) + +This code mimics the ROS 2 [Services "add_two_ints_client" demo](https://github.com/ros2/demos/blob/rolling/demo_nodes_cpp/src/services/add_two_ints_client.cpp). It's compatible with the ROS 2 [Services "add_two_ints_server" demo](https://github.com/ros2/demos/blob/rolling/demo_nodes_cpp/src/services/add_two_ints_server.cpp) running those commands: +- `ros2 run demo_nodes_cpp add_two_ints_server` +- `zenoh-bridge-ros2dds` +- `cargo run --bin add_two_ints_client` + +## Actions Client: [fibonnacci_action_client.rs](src/bin/fibonnacci_action_client.rs) + +This code mimics the ROS 2 [Actions "fibonnacci_action_client" demo](https://github.com/ros2/demos/blob/rolling/action_tutorials/action_tutorials_cpp/src/fibonacci_action_client.cpp). It's compatible with the ROS 2 [Actions "fibonnacci_action_server" demo](https://github.com/ros2/demos/blob/rolling/action_tutorials/action_tutorials_cpp/src/fibonacci_action_server.cpp) running those commands: +- `ros2 run action_tutorials_cpp fibonacci_action_server` +- `zenoh-bridge-ros2dds` +- `cargo run --bin fibonnacci_action_client` \ No newline at end of file diff --git a/examples/rust/rust-toolchain.toml b/examples/rust/rust-toolchain.toml new file mode 100644 index 0000000..83025f9 --- /dev/null +++ b/examples/rust/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "1.77.0" diff --git a/examples/rust/src/bin/listener.rs b/examples/rust/src/bin/listener.rs index 9c1d5f9..f400664 100644 --- a/examples/rust/src/bin/listener.rs +++ b/examples/rust/src/bin/listener.rs @@ -30,9 +30,7 @@ async fn main() { println!("Opening session..."); let session = zenoh::open(config).res().await.unwrap(); - let key_expr = "chatter"; - println!("Declaring Subscriber on '{}'...", &key_expr); - let subscriber = session.declare_subscriber(key_expr).res().await.unwrap(); + let subscriber = session.declare_subscriber("chatter").res().await.unwrap(); while let Ok(sample) = subscriber.recv_async().await { match cdr::deserialize_from::<_, Message, _>( diff --git a/examples/rust/src/bin/talker.rs b/examples/rust/src/bin/talker.rs index c0a9fc6..492bd8d 100644 --- a/examples/rust/src/bin/talker.rs +++ b/examples/rust/src/bin/talker.rs @@ -34,10 +34,7 @@ async fn main() { println!("Opening session..."); let session = zenoh::open(config).res().await.unwrap(); - let key_expr = "chatter"; - - println!("Declaring Publisher on '{key_expr}'..."); - let publisher = session.declare_publisher(key_expr).res().await.unwrap(); + let publisher = session.declare_publisher("chatter").res().await.unwrap(); for idx in 0..u32::MAX { sleep(Duration::from_secs(1)).await; @@ -45,7 +42,7 @@ async fn main() { data: format!("Hello World:{idx:4}"), }; let buf = cdr::serialize::<_, _, CdrLe>(&message, Infinite).unwrap(); - println!("Putting Data ('{}': '{}')...", &key_expr, message.data); + println!("Publishing: '{}')...", message.data); publisher.put(buf).res().await.unwrap(); } } From c03cb89a70e1266173129fa9560ea969f1ee0b1c Mon Sep 17 00:00:00 2001 From: Steven Palma Date: Tue, 9 Apr 2024 15:06:20 +0200 Subject: [PATCH 8/9] fix toolchain & clap version --- examples/rust/Cargo.toml | 2 +- examples/rust/rust-toolchain.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/rust/Cargo.toml b/examples/rust/Cargo.toml index 41b6ae3..beea59f 100644 --- a/examples/rust/Cargo.toml +++ b/examples/rust/Cargo.toml @@ -9,7 +9,7 @@ edition = "2021" async-std = { version = "1.12.0" } futures = { version = "0.3.28" } zenoh = { version = "0.10.1-rc" } -clap = { version = "3.2.23" } +clap = { version = "4.4.11", features = ["derive"] } env_logger = { version = "0.10.0" } serde = {version = "1" } serde_derive = {version = "1"} diff --git a/examples/rust/rust-toolchain.toml b/examples/rust/rust-toolchain.toml index 83025f9..b7eadd6 100644 --- a/examples/rust/rust-toolchain.toml +++ b/examples/rust/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "1.77.0" +channel = "1.72.0" \ No newline at end of file From 76700fe7e9304ba66d58fa143b8982ced1d293be Mon Sep 17 00:00:00 2001 From: Steven Palma Date: Wed, 17 Apr 2024 09:44:59 +0200 Subject: [PATCH 9/9] Remove install zenoh-rust step in readme --- examples/rust/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/rust/README.md b/examples/rust/README.md index 0703d57..3b89630 100644 --- a/examples/rust/README.md +++ b/examples/rust/README.md @@ -3,7 +3,7 @@ ## Building the examples In order to build the examples you will need to: * [Install Rust and Cargo](https://doc.rust-lang.org/cargo/getting-started/installation.html) -* [Install Zenoh Rust](https://github.com/eclipse-zenoh/zenoh?tab=readme-ov-file#how-to-install-it) +* [Clone the repository](https://github.com/eclipse-zenoh/zenoh-plugin-ros2dds) Once this is done, compile by running the following: ```