![](/media/cache/profiles/94aef38441efa3380a3bed3faf1f9d5d.50x50_q85.jpg)
This program is porting rosserial_arduino for mbed http://www.ros.org/wiki/rosserial_arduino This program supported the revision of 169 of rosserial. This program contains an example.
Dependencies: rosserial_mbed_lib mbed Servo
examples/ServiceServer.cpp@3:dff241b66f84, 2011-11-12 (annotated)
- Committer:
- nucho
- Date:
- Sat Nov 12 23:53:04 2011 +0000
- Revision:
- 3:dff241b66f84
This program supported the revision of 167 of rosserial.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nucho | 3:dff241b66f84 | 1 | //#define COMPILE_SERVICESERVER_CODE_ROSSERIAL |
nucho | 3:dff241b66f84 | 2 | #ifdef COMPILE_SERVICESERVER_CODE_ROSSERIAL |
nucho | 3:dff241b66f84 | 3 | /* |
nucho | 3:dff241b66f84 | 4 | * rosserial Service Server |
nucho | 3:dff241b66f84 | 5 | */ |
nucho | 3:dff241b66f84 | 6 | |
nucho | 3:dff241b66f84 | 7 | #include <ros.h> |
nucho | 3:dff241b66f84 | 8 | #include <std_msgs/String.h> |
nucho | 3:dff241b66f84 | 9 | #include <rosserial_arduino/Test.h> |
nucho | 3:dff241b66f84 | 10 | |
nucho | 3:dff241b66f84 | 11 | ros::NodeHandle nh; |
nucho | 3:dff241b66f84 | 12 | using rosserial_arduino::Test; |
nucho | 3:dff241b66f84 | 13 | |
nucho | 3:dff241b66f84 | 14 | int i; |
nucho | 3:dff241b66f84 | 15 | void callback(const Test::Request & req, Test::Response & res) { |
nucho | 3:dff241b66f84 | 16 | if ((i++)%2) |
nucho | 3:dff241b66f84 | 17 | res.output = "hello"; |
nucho | 3:dff241b66f84 | 18 | else |
nucho | 3:dff241b66f84 | 19 | res.output = "world"; |
nucho | 3:dff241b66f84 | 20 | } |
nucho | 3:dff241b66f84 | 21 | |
nucho | 3:dff241b66f84 | 22 | ros::ServiceServer<Test::Request, Test::Response> server("test_srv",&callback); |
nucho | 3:dff241b66f84 | 23 | |
nucho | 3:dff241b66f84 | 24 | std_msgs::String str_msg; |
nucho | 3:dff241b66f84 | 25 | ros::Publisher chatter("chatter", &str_msg); |
nucho | 3:dff241b66f84 | 26 | |
nucho | 3:dff241b66f84 | 27 | char hello[13] = "hello world!"; |
nucho | 3:dff241b66f84 | 28 | |
nucho | 3:dff241b66f84 | 29 | int main(void) { |
nucho | 3:dff241b66f84 | 30 | nh.initNode(); |
nucho | 3:dff241b66f84 | 31 | nh.advertiseService(server); |
nucho | 3:dff241b66f84 | 32 | nh.advertise(chatter); |
nucho | 3:dff241b66f84 | 33 | |
nucho | 3:dff241b66f84 | 34 | |
nucho | 3:dff241b66f84 | 35 | while (1) { |
nucho | 3:dff241b66f84 | 36 | str_msg.data = hello; |
nucho | 3:dff241b66f84 | 37 | chatter.publish( &str_msg ); |
nucho | 3:dff241b66f84 | 38 | nh.spinOnce(); |
nucho | 3:dff241b66f84 | 39 | wait_ms(10); |
nucho | 3:dff241b66f84 | 40 | } |
nucho | 3:dff241b66f84 | 41 | } |
nucho | 3:dff241b66f84 | 42 | #endif |