ros_serial for mbed updated to work with ROS Hydro. Library still needs to be debugged

Dependencies:   rosserial_hydro

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ServiceClient.cpp Source File

ServiceClient.cpp

00001 //#define COMPILE_SERVICECLIENT_CODE_ROSSERIAL
00002 #ifdef  COMPILE_SERVICECLIENT_CODE_ROSSERIAL
00003 
00004 /*
00005  * rosserial Service Client
00006  */
00007 
00008 #include <ros.h>
00009 #include <std_msgs/String.h>
00010 
00011 #include <rosserial_arduino/Test.h>
00012 
00013 ros::NodeHandle  nh;
00014 using rosserial_arduino::Test;
00015 
00016 ros::ServiceClient<Test::Request, Test::Response> client("test_srv");
00017 
00018 std_msgs::String str_msg;
00019 ros::Publisher chatter("chatter", &str_msg);
00020 
00021 char hello[13] = "hello world!";
00022 
00023 int main() {
00024     nh.initNode();
00025     nh.serviceClient(client);
00026     nh.advertise(chatter);
00027     while (!nh.connected()) nh.spinOnce();
00028     nh.loginfo("Startup complete");
00029     while (1) {
00030         Test::Request req;
00031         Test::Response res;
00032         req.input = hello;
00033         client.call(req, res);
00034         str_msg.data = res.output;
00035         chatter.publish( &str_msg );
00036         nh.spinOnce();
00037         wait_ms(100);
00038     }
00039 }
00040 #endif