File tree Expand file tree Collapse file tree 3 files changed +54
-0
lines changed
Expand file tree Collapse file tree 3 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,14 @@ path = "src/minimal_subscriber.rs"
1313name = " minimal_publisher"
1414path = " src/minimal_publisher.rs"
1515
16+ [[bin ]]
17+ name = " zero_copy_subscriber"
18+ path = " src/zero_copy_subscriber.rs"
19+
20+ [[bin ]]
21+ name = " zero_copy_publisher"
22+ path = " src/zero_copy_publisher.rs"
23+
1624[dependencies ]
1725anyhow = {version = " 1" , features = [" backtrace" ]}
1826
Original file line number Diff line number Diff line change 1+ use anyhow:: { Error , Result } ;
2+ use std:: env;
3+
4+ fn main ( ) -> Result < ( ) , Error > {
5+ let context = rclrs:: Context :: new ( env:: args ( ) ) ?;
6+
7+ let node = rclrs:: create_node ( & context, "minimal_publisher" ) ?;
8+
9+ let publisher =
10+ node. create_publisher :: < std_msgs:: msg:: rmw:: UInt32 > ( "topic" , rclrs:: QOS_PROFILE_DEFAULT ) ?;
11+
12+ let mut publish_count: u32 = 1 ;
13+
14+ while context. ok ( ) {
15+ let mut message = publisher. borrow_loaned_message ( ) ?;
16+ message. data = publish_count;
17+ println ! ( "Publishing: {}" , message. data) ;
18+ message. publish ( ) ?;
19+ publish_count += 1 ;
20+ std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 500 ) ) ;
21+ }
22+ Ok ( ( ) )
23+ }
Original file line number Diff line number Diff line change 1+ use std:: env;
2+
3+ use anyhow:: { Error , Result } ;
4+
5+ fn main ( ) -> Result < ( ) , Error > {
6+ let context = rclrs:: Context :: new ( env:: args ( ) ) ?;
7+
8+ let mut node = rclrs:: create_node ( & context, "minimal_subscriber" ) ?;
9+
10+ let mut num_messages: usize = 0 ;
11+
12+ let _subscription = node. create_subscription :: < std_msgs:: msg:: UInt32 , _ > (
13+ "topic" ,
14+ rclrs:: QOS_PROFILE_DEFAULT ,
15+ move |msg : std_msgs:: msg:: UInt32 | {
16+ num_messages += 1 ;
17+ println ! ( "I heard: '{}'" , msg. data) ;
18+ println ! ( "(Got {} messages so far)" , num_messages) ;
19+ } ,
20+ ) ?;
21+
22+ rclrs:: spin ( & node) . map_err ( |err| err. into ( ) )
23+ }
You can’t perform that action at this time.
0 commit comments