Last active
July 10, 2018 20:00
-
-
Save durka/70175783a971cbd4cc26005e4ed6173d to your computer and use it in GitHub Desktop.
rosrust vs rospy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[macro_use] extern crate rosrust_codegen; | |
rosmsg_main!("sensor_msgs/Image"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "node" | |
version = "0.1.0" | |
authors = ["alex"] | |
[dependencies] | |
error-chain = "0.12" | |
rosrust = "0.6.5" | |
rosrust_codegen = "0.6.5" | |
serde = "1.0.25" | |
serde_derive = "1.0.25" | |
[build-dependencies] | |
rosrust_codegen = "0.6.5" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import rospy | |
from sensor_msgs.msg import Image | |
class sub_cb: | |
def __init__(self, pub): | |
self.pub = pub | |
self.i = 1 | |
def __call__(self, data): | |
print self.i | |
self.i += 1 | |
self.pub.publish(data) | |
def main(): | |
print 'starting' | |
rospy.init_node('node') | |
pub = rospy.Publisher('/out', Image, queue_size=10) | |
sub = rospy.Subscriber('/in', Image, sub_cb(pub)) | |
print 'finished setup' | |
rospy.spin() | |
print 'shutting down' | |
if __name__ == '__main__': | |
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[macro_use] extern crate error_chain; | |
#[macro_use] extern crate rosrust; | |
#[macro_use] extern crate rosrust_codegen; | |
rosmsg_include!(); | |
use std::cell::RefCell; | |
use std::sync::atomic::{AtomicUsize, Ordering}; | |
error_chain! { | |
foreign_links { | |
Ros(rosrust::error::Error); | |
} | |
} | |
quick_main!(|| -> Result<()> { | |
// Initialize node | |
rosrust::init("node"); | |
ros_info!("Starting up"); | |
let img_pub = RefCell::new(rosrust::publish("/out")?); | |
img_pub.borrow_mut().set_queue_size(Some(10)); | |
let idx = AtomicUsize::new(0); | |
let _img_sub = rosrust::subscribe("/in", | |
move |v: msg::sensor_msgs::Image| { | |
let i = idx.load(Ordering::SeqCst) + 1; | |
ros_info!("Received frame #{}: {}x{} {}!", i, v.height, v.width, v.encoding); | |
idx.store(i, Ordering::SeqCst); | |
img_pub.borrow_mut().send(v).unwrap(); | |
})?; | |
// Block the thread until a shutdown signal is received | |
rosrust::spin(); | |
ros_info!("Shutting down"); | |
Ok(()) | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment