File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ [package ]
2+ name = " dynamic_pub_sub"
3+ version = " 0.1.0"
4+ edition = " 2021"
5+
6+ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+ [dependencies ]
9+ # TODO(luca) change this to the correct version once dynamic message support is released on crates.io
10+ rclrs = { version = " 0.4" , features = [" dyn_msg" ] }
11+ anyhow = {version = " 1" , features = [" backtrace" ]}
Original file line number Diff line number Diff line change 1+ use anyhow:: { Error , Result } ;
2+ use rclrs:: * ;
3+
4+ fn main ( ) -> Result < ( ) , Error > {
5+ let context = Context :: default_from_env ( ) ?;
6+ let mut executor = context. create_basic_executor ( ) ;
7+
8+ let node = executor. create_node ( "dynamic_subscriber" ) ?;
9+
10+ let worker = node. create_worker :: < usize > ( 0 ) ;
11+ let _subscription = worker. create_dynamic_subscription (
12+ "rclrs_example_msgs/msg/VariousTypes" . try_into ( ) ?,
13+ "topic" ,
14+ move |num_messages : & mut usize , msg, _msg_info| {
15+ * num_messages += 1 ;
16+ println ! ( "#{} | I heard: '{:#?}'" , * num_messages, msg. structure( ) ) ;
17+ } ,
18+ ) ?;
19+
20+ println ! ( "Waiting for messages..." ) ;
21+ executor. spin ( SpinOptions :: default ( ) ) . first_error ( ) ?;
22+ Ok ( ( ) )
23+ }
You can’t perform that action at this time.
0 commit comments