Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
ServiceServer.cpp
00001 //#define COMPILE_SERVICESERVER_CODE_ROSSERIAL 00002 #ifdef COMPILE_SERVICESERVER_CODE_ROSSERIAL 00003 /* 00004 * rosserial Service Server 00005 */ 00006 00007 #include <ros.h> 00008 #include <std_msgs/String.h> 00009 #include <rosserial_arduino/Test.h> 00010 00011 ros::NodeHandle nh; 00012 using rosserial_arduino::Test; 00013 00014 int i; 00015 void callback(const Test::Request & req, Test::Response & res) { 00016 if ((i++)%2) 00017 res.output = "hello"; 00018 else 00019 res.output = "world"; 00020 } 00021 00022 ros::ServiceServer<Test::Request, Test::Response> server("test_srv",&callback); 00023 00024 std_msgs::String str_msg; 00025 ros::Publisher chatter("chatter", &str_msg); 00026 00027 char hello[13] = "hello world!"; 00028 00029 int main(void) { 00030 nh.initNode(); 00031 nh.advertiseService(server); 00032 nh.advertise(chatter); 00033 00034 00035 while (1) { 00036 str_msg.data = hello; 00037 chatter.publish( &str_msg ); 00038 nh.spinOnce(); 00039 wait_ms(10); 00040 } 00041 } 00042 #endif
Generated on Sun Jul 17 2022 00:31:54 by
1.7.2