Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT: Native service client #147

Merged
merged 13 commits into from
Jun 29, 2024
4 changes: 4 additions & 0 deletions assets/ros1_test_msgs/srv/RoundTripArray.srv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Purpose of this array is send and receive a large payload
uint8[] bytes
---
uint8[] bytes
31 changes: 31 additions & 0 deletions roslibrust/examples/ros1_service_client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
roslibrust_codegen_macro::find_and_generate_ros_messages!("assets/ros1_common_interfaces");

#[cfg(feature = "ros1")]
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
use roslibrust::ros1::NodeHandle;

simple_logger::SimpleLogger::new()
.with_level(log::LevelFilter::Debug)
.without_timestamps()
.init()
.unwrap();

let nh = NodeHandle::new("http://localhost:11311", "service_client_rs").await?;
log::info!("Connected!");

let response: rosapi::GetTimeResponse = nh
.service_client::<rosapi::GetTime>("rosapi/get_time")
.await?
.call(&rosapi::GetTimeRequest {})
.await?;

log::info!("Got time: {:?}", response);

Ok(())
}

#[cfg(not(feature = "ros1"))]
fn main() {
eprintln!("This example does nothing without compiling with the feature 'ros1'");
}
4 changes: 4 additions & 0 deletions roslibrust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,12 @@ pub enum RosLibRustError {
Timeout(#[from] tokio::time::error::Elapsed),
#[error("Failed to parse message from JSON: {0}")]
InvalidMessage(#[from] serde_json::Error),
#[error("TCPROS serialization error: {0}")]
SerializationError(String),
#[error("Rosbridge server reported an error: {0}")]
ServerError(String),
#[error("IO error: {0}")]
IoError(#[from] std::io::Error),
#[error("Name does not meet ROS requirements: {0}")]
InvalidName(String),
// Generic catch-all error type for not-yet-handled errors
Expand Down
4 changes: 4 additions & 0 deletions roslibrust/src/ros1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ pub use node::*;

mod publisher;
pub use publisher::Publisher;
mod service_client;
pub use service_client::ServiceClient;
mod subscriber;
pub use subscriber::Subscriber;
mod service_server;
pub use service_server::ServiceServer;
mod tcpros;
9 changes: 5 additions & 4 deletions roslibrust/src/ros1/names.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::fmt::Display;

lazy_static::lazy_static! {
// See: https://wiki.ros.org/Names
static ref GRAPH_NAME_REGEX: regex::Regex = regex::Regex::new(r"^([/~a-zA-Z]){1}([a-zA-Z0-9_/])*([A-z0-9_])$").unwrap();
}

Expand Down Expand Up @@ -52,16 +53,16 @@ impl Name {
}
}

fn is_valid(name: &str) -> bool {
GRAPH_NAME_REGEX.is_match(name)
}

impl Display for Name {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.inner.fmt(f)
}
}

fn is_valid(name: &str) -> bool {
GRAPH_NAME_REGEX.is_match(name)
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Loading
Loading