Skip to content

Commit a60529d

Browse files
committed
Added main example code with info logger
1 parent ab4cb3c commit a60529d

File tree

1 file changed

+23
-0
lines changed
  • examples/minimal_logging/src

1 file changed

+23
-0
lines changed

examples/minimal_logging/src/main.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use rclrs::{create_node, log, Context, RclrsError, ToLogParams, QOS_PROFILE_DEFAULT};
2+
use std::{env, time::Duration};
3+
use std_msgs::msg::String as StringMsg;
4+
fn main() -> Result<(), RclrsError> {
5+
let context = Context::new(env::args())?;
6+
7+
let node = create_node(&context, "minimal_logger")?;
8+
9+
let publisher = node.create_publisher("topic", QOS_PROFILE_DEFAULT)?;
10+
11+
let mut message = StringMsg::default();
12+
13+
let mut publish_count: u32 = 1;
14+
15+
while context.ok() {
16+
message.data = format!("Hello, world! {}", publish_count);
17+
log!(node.info(), "Publishing: [{}]", message.data);
18+
publisher.publish(&message)?;
19+
publish_count += 1;
20+
std::thread::sleep(std::time::Duration::from_millis(500));
21+
}
22+
Ok(())
23+
}

0 commit comments

Comments
 (0)