-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
carter
committed
Dec 3, 2024
1 parent
4d5456c
commit 7262ad6
Showing
3 changed files
with
199 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//! Purpose of this example is to show how to host service visible to ROS1 from a Zenoh client. | ||
// IMPORTANT to bring this trait into scope so we can access the functions it provides | ||
// [ServiceProvider] is what allows us to actually access .service_client() | ||
use roslibrust::topic_provider::ServiceProvider; | ||
use roslibrust_zenoh::ZenohClient; | ||
|
||
// IMPORTANT this example will not work with the default zenoh-ros1-bridge settings! | ||
// It requires the flag `--client_bridging_mode auto` to be set when the bridge is started | ||
// Otherwise the service will not be advertised to ROS1 master. | ||
|
||
// Generate rust definitions for our messages | ||
roslibrust_codegen_macro::find_and_generate_ros_messages!("assets/ros1_common_interfaces"); | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
// Setup a logger for debugging purposes | ||
// Run this example with RUST_LOG=debug for more information if this doesn't work for you | ||
env_logger::init(); | ||
|
||
// Create our zenoh client, depending on how you are running zenoh / the bridge you may | ||
// need to pass specific configuration in here. | ||
let session = zenoh::open(zenoh::Config::default()).await.unwrap(); | ||
let client = ZenohClient::new(session); | ||
|
||
// Service will remain alive until handle is dropped | ||
let _handle = client | ||
.advertise_service::<std_srvs::SetBool, _>( | ||
"/my_set_bool", | ||
|request: std_srvs::SetBoolRequest| { | ||
log::info!("Got request to set bool: {request:?}"); | ||
Ok(std_srvs::SetBoolResponse { | ||
success: true, | ||
message: "You set my bool!".to_string(), | ||
}) | ||
}, | ||
) | ||
.await | ||
.unwrap(); | ||
|
||
// Wait for ctrl_c to kill this process | ||
tokio::signal::ctrl_c().await.unwrap(); | ||
|
||
// While this example is running: | ||
// `rosservice list` should show /my_set_bool | ||
// `rosservice call /my_set_bool "data: true"` should work | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//! Not actually an example for this crate, just peeping on how discovery for zenoh-ros1-bridge works | ||
#[tokio::main] | ||
async fn main() { | ||
let session = zenoh::open(zenoh::Config::default()).await.unwrap(); | ||
|
||
let sub = session | ||
.declare_subscriber("ros1_discovery_info/**") | ||
.await | ||
.unwrap(); | ||
|
||
loop { | ||
let sample = sub.recv_async().await.unwrap(); | ||
println!("Got sample: {sample:?}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters