Hello,
This is my first time trying to setup ros2-client in rust. I want to thank you for your patience in advance.
As mentioned, I am trying to get a simple publisher in place. I first started by creating a new rust project using cargo new <project_name . In this I have put a simple basic subscriber as below
`use ros2_client::{Context, NodeOptions, NodeName, Name, MessageTypeName, Subscription, DEFAULT_SUBSCRIPTION_QOS};
use futures::stream::StreamExt;
fn main() {
smol::block_on(async {
// Create a new ROS 2 context
let context = Context::new().unwrap();
// Create a new node with rosout logging enabled
let mut node = context
.new_node(
NodeName::new("/", "rustdds_listener").unwrap(),
NodeOptions::new().enable_rosout(true),
)
.unwrap();
let chatter_topic = node
.create_topic(
&Name::new("/", "topic").unwrap(),
MessageTypeName::new("std_msgs", "String"),
&ros2_client::DEFAULT_SUBSCRIPTION_QOS,
)
.unwrap();
// Subscribe to the 'topic'
let chatter_subscription = node
.create_subscription::<String>(&chatter_topic, None)
.unwrap();
// Process the messages received on this subscription
chatter_subscription
.async_stream()
.for_each(|result| async {
match result {
Ok((msg, _)) => println!("I heard: {msg}"),
Err(e) => eprintln!("Receive request error: {:?}", e),
}
})
.await;
});
}
`
Now, when I run the commands cargo build and cargo run , I do not see the listeners on the terminal when running ros2 node list . Even when running ros2 topic pub /topic std_msgs/msg/String "data: 'Hello, world'" on a separate terminal, I don't see the library listening and printing these messages.
Is there something wrong that I am doing, or am I supposed to create a package using ros2 pkg create ? Is there anything I need to check or do before creating the project? The node created using rust cannot be seen. I am currently using humble version of ROS2.
Any help is appreciated. Many thanks in advance
Hello,
This is my first time trying to setup ros2-client in rust. I want to thank you for your patience in advance.
As mentioned, I am trying to get a simple publisher in place. I first started by creating a new rust project using
cargo new <project_name. In this I have put a simple basic subscriber as below`use ros2_client::{Context, NodeOptions, NodeName, Name, MessageTypeName, Subscription, DEFAULT_SUBSCRIPTION_QOS};
use futures::stream::StreamExt;
fn main() {
smol::block_on(async {
// Create a new ROS 2 context
let context = Context::new().unwrap();
});
}
`
Now, when I run the commands
cargo buildandcargo run, I do not see the listeners on the terminal when runningros2 node list. Even when runningros2 topic pub /topic std_msgs/msg/String "data: 'Hello, world'"on a separate terminal, I don't see the library listening and printing these messages.Is there something wrong that I am doing, or am I supposed to create a package using
ros2 pkg create? Is there anything I need to check or do before creating the project? The node created using rust cannot be seen. I am currently using humble version of ROS2.Any help is appreciated. Many thanks in advance