arci_ros/
ros_speak_client.rs

1use arci::WaitFuture;
2use schemars::JsonSchema;
3use serde::{Deserialize, Serialize};
4
5mod msg {
6    rosrust::rosmsg_include!(std_msgs / String);
7}
8
9pub struct RosEspeakClient {
10    publisher: rosrust::Publisher<msg::std_msgs::String>,
11}
12
13#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
14#[serde(deny_unknown_fields)]
15pub struct RosEspeakClientConfig {
16    pub topic: String,
17}
18
19impl RosEspeakClient {
20    pub fn new(topic: &str) -> Self {
21        Self {
22            publisher: rosrust::publish(topic, 2).unwrap(),
23        }
24    }
25}
26
27impl arci::Speaker for RosEspeakClient {
28    fn speak(&self, message: &str) -> Result<WaitFuture, arci::Error> {
29        let ros_msg = msg::std_msgs::String {
30            data: message.to_string(),
31        };
32        self.publisher
33            .send(ros_msg)
34            .map_err(|e| anyhow::format_err!("{e}"))?;
35        Ok(WaitFuture::ready())
36    }
37}