ros_serial for mbed updated to work with ROS Hydro. Library still needs to be debugged
Library and program still under development!
examples/ServiceServer.cpp@0:cb1dffdc7d05, 2015-02-15 (annotated)
- Committer:
- akashvibhute
- Date:
- Sun Feb 15 10:54:04 2015 +0000
- Revision:
- 0:cb1dffdc7d05
Error: ; "mbed::Stream::Stream(const mbed::Stream &)" (declared at <a href="#" onmousedown="mbed_doc_goto('/mbed_roshydro_test//extras/mbed_e188a91d3eaa/Stream.h', '59'); return false;">/extras/mbed_e188a91d3eaa/Stream.h:59</a>) is inaccessible in "ext
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
akashvibhute | 0:cb1dffdc7d05 | 1 | //#define COMPILE_SERVICESERVER_CODE_ROSSERIAL |
akashvibhute | 0:cb1dffdc7d05 | 2 | #ifdef COMPILE_SERVICESERVER_CODE_ROSSERIAL |
akashvibhute | 0:cb1dffdc7d05 | 3 | /* |
akashvibhute | 0:cb1dffdc7d05 | 4 | * rosserial Service Server |
akashvibhute | 0:cb1dffdc7d05 | 5 | */ |
akashvibhute | 0:cb1dffdc7d05 | 6 | |
akashvibhute | 0:cb1dffdc7d05 | 7 | #include <ros.h> |
akashvibhute | 0:cb1dffdc7d05 | 8 | #include <std_msgs/String.h> |
akashvibhute | 0:cb1dffdc7d05 | 9 | #include <rosserial_arduino/Test.h> |
akashvibhute | 0:cb1dffdc7d05 | 10 | |
akashvibhute | 0:cb1dffdc7d05 | 11 | ros::NodeHandle nh; |
akashvibhute | 0:cb1dffdc7d05 | 12 | using rosserial_arduino::Test; |
akashvibhute | 0:cb1dffdc7d05 | 13 | |
akashvibhute | 0:cb1dffdc7d05 | 14 | int i; |
akashvibhute | 0:cb1dffdc7d05 | 15 | void callback(const Test::Request & req, Test::Response & res) { |
akashvibhute | 0:cb1dffdc7d05 | 16 | if ((i++)%2) |
akashvibhute | 0:cb1dffdc7d05 | 17 | res.output = "hello"; |
akashvibhute | 0:cb1dffdc7d05 | 18 | else |
akashvibhute | 0:cb1dffdc7d05 | 19 | res.output = "world"; |
akashvibhute | 0:cb1dffdc7d05 | 20 | } |
akashvibhute | 0:cb1dffdc7d05 | 21 | |
akashvibhute | 0:cb1dffdc7d05 | 22 | ros::ServiceServer<Test::Request, Test::Response> server("test_srv",&callback); |
akashvibhute | 0:cb1dffdc7d05 | 23 | |
akashvibhute | 0:cb1dffdc7d05 | 24 | std_msgs::String str_msg; |
akashvibhute | 0:cb1dffdc7d05 | 25 | ros::Publisher chatter("chatter", &str_msg); |
akashvibhute | 0:cb1dffdc7d05 | 26 | |
akashvibhute | 0:cb1dffdc7d05 | 27 | char hello[13] = "hello world!"; |
akashvibhute | 0:cb1dffdc7d05 | 28 | |
akashvibhute | 0:cb1dffdc7d05 | 29 | int main(void) { |
akashvibhute | 0:cb1dffdc7d05 | 30 | nh.initNode(); |
akashvibhute | 0:cb1dffdc7d05 | 31 | nh.advertiseService(server); |
akashvibhute | 0:cb1dffdc7d05 | 32 | nh.advertise(chatter); |
akashvibhute | 0:cb1dffdc7d05 | 33 | |
akashvibhute | 0:cb1dffdc7d05 | 34 | |
akashvibhute | 0:cb1dffdc7d05 | 35 | while (1) { |
akashvibhute | 0:cb1dffdc7d05 | 36 | str_msg.data = hello; |
akashvibhute | 0:cb1dffdc7d05 | 37 | chatter.publish( &str_msg ); |
akashvibhute | 0:cb1dffdc7d05 | 38 | nh.spinOnce(); |
akashvibhute | 0:cb1dffdc7d05 | 39 | wait_ms(10); |
akashvibhute | 0:cb1dffdc7d05 | 40 | } |
akashvibhute | 0:cb1dffdc7d05 | 41 | } |
akashvibhute | 0:cb1dffdc7d05 | 42 | #endif |