ros_serial for mbed updated to work with ROS Hydro. Library still needs to be debugged
Embed:
(wiki syntax)
Show/hide line numbers
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