![](/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
Diff: examples/ServiceServer.cpp
- Revision:
- 3:dff241b66f84
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/ServiceServer.cpp Sat Nov 12 23:53:04 2011 +0000 @@ -0,0 +1,42 @@ +//#define COMPILE_SERVICESERVER_CODE_ROSSERIAL +#ifdef COMPILE_SERVICESERVER_CODE_ROSSERIAL +/* + * rosserial Service Server + */ + +#include <ros.h> +#include <std_msgs/String.h> +#include <rosserial_arduino/Test.h> + +ros::NodeHandle nh; +using rosserial_arduino::Test; + +int i; +void callback(const Test::Request & req, Test::Response & res) { + if ((i++)%2) + res.output = "hello"; + else + res.output = "world"; +} + +ros::ServiceServer<Test::Request, Test::Response> server("test_srv",&callback); + +std_msgs::String str_msg; +ros::Publisher chatter("chatter", &str_msg); + +char hello[13] = "hello world!"; + +int main(void) { + nh.initNode(); + nh.advertiseService(server); + nh.advertise(chatter); + + + while (1) { + str_msg.data = hello; + chatter.publish( &str_msg ); + nh.spinOnce(); + wait_ms(10); + } +} +#endif \ No newline at end of file