Skip to content

Commit bca4833

Browse files
authored
Merge pull request #1 from Robotics-BUT/rust_oop
Rust oop
2 parents ef5400a + f619c04 commit bca4833

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

ros/src/python_node/bin/main

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ from std_msgs.msg import Header
77
if __name__ == '__main__':
88

99
a = Header
10-
rospy.init_node('python_node', anonymous=True)
10+
rospy.init_node('python_node', anonymous=False)
1111

1212
controller = cnt.Controller()
1313

ros/src/rust_node/src/lib.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use rosrust;
2+
use std::sync::Arc;
3+
4+
pub struct Controller{
5+
subscriber: Arc<rosrust::Subscriber>,
6+
}
7+
8+
9+
impl Controller {
10+
11+
pub fn new() -> Controller {
12+
13+
let publisher = Arc::new(rosrust::publish("rust_to_cpp", 0).unwrap());
14+
let subscriber = Arc::new(rosrust::subscribe("python_to_rust", 1, move |v: rosrust_msg::std_msgs::Header| {
15+
publisher.send(v).unwrap();
16+
}).unwrap());
17+
18+
Controller {
19+
subscriber,
20+
}
21+
}
22+
}

ros/src/rust_node/src/main.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
use rosrust;
2+
extern crate rust_node;
23

34
fn main() {
45

56
rosrust::init("rust_node");
67

7-
let publisher = rosrust::publish("rust_to_cpp", 0).unwrap();
8-
let subscriber_info = rosrust::subscribe("python_to_rust", 1, move |v: rosrust_msg::std_msgs::Header| {
9-
rosrust::ros_info!("Received: {}", v.seq);
10-
publisher.send(v).unwrap();
11-
})
12-
.unwrap();
8+
let controller = rust_node::Controller::new();
139

1410
rosrust::spin();
1511
}

0 commit comments

Comments
 (0)