-
Notifications
You must be signed in to change notification settings - Fork 0
/
amiga_vel_subscriber.rs
41 lines (34 loc) · 1.07 KB
/
amiga_vel_subscriber.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use tracing::{debug, info, Level};
use tracing_subscriber::FmtSubscriber;
fn main() {
tracing::subscriber::set_global_default(
FmtSubscriber::builder()
.with_max_level(Level::INFO)
.finish(),
)
.expect("setting default subscriber failed");
// Initialize node
rosrust::init("amiga_vel_subscriber");
// Create object that maintains 20Hz between sleep requests
let rate = rosrust::rate(20.0);
let arc_count = std::sync::Arc::new(std::sync::Mutex::<u32>::new(0));
let arc_count_clone = arc_count.clone();
let _subscriber_raii = rosrust::subscribe(
"/amiga/vel",
100,
move |v: rosrust_msg::geometry_msgs::TwistStamped| {
debug!("Received: {:?}", v);
let mut data = arc_count_clone.lock().unwrap();
*data += 1;
},
)
.unwrap();
info!("amiga_vel_subscriber launched");
while rosrust::is_ok() {
// Sleep to maintain 20Hz rate
rate.sleep();
if *arc_count.lock().unwrap() > 10 {
break;
}
}
}