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

Committer:
nucho
Date:
Wed Feb 29 23:02:12 2012 +0000
Revision:
4:2cbca0ac2569
Parent:
3:dff241b66f84

        

Who changed what in which revision?

UserRevisionLine numberNew 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