ServiceServer.cpp
Go to the documentation of this file.
1 /*
2  * rosserial Service Server
3  */
4 
5 #include <ros.h>
6 #include <std_msgs/String.h>
7 #include <rosserial_mbed/Test.h>
8 
10 using rosserial_mbed::Test;
11 
12 int i;
13 void callback(const Test::Request & req, Test::Response & res) {
14  if ((i++)%2)
15  res.output = "hello";
16  else
17  res.output = "world";
18 }
19 
21 
22 std_msgs::String str_msg;
23 ros::Publisher chatter("chatter", &str_msg);
24 
25 char hello[13] = "hello world!";
26 
27 int main(void) {
28  nh.initNode();
31 
32 
33  while (1) {
34  str_msg.data = hello;
36  nh.spinOnce();
37  wait_ms(10);
38  }
39 }
40 
ros::Publisher
i
int i
Definition: ServiceServer.cpp:12
main
int main(void)
Definition: ServiceServer.cpp:27
ros::NodeHandle::advertiseService
ServiceServer advertiseService(AdvertiseServiceOptions &ops)
ros::Publisher::publish
void publish(const boost::shared_ptr< M > &message) const
ros::NodeHandle::advertise
Publisher advertise(AdvertiseOptions &ops)
server
ros::ServiceServer< Test::Request, Test::Response > server("test_srv",&callback)
nh
ros::NodeHandle nh
Definition: ServiceServer.cpp:9
str_msg
std_msgs::String str_msg
Definition: ServiceServer.cpp:22
callback
void callback(const Test::Request &req, Test::Response &res)
Definition: ServiceServer.cpp:13
chatter
ros::Publisher chatter("chatter", &str_msg)
ros::ServiceServer
hello
char hello[13]
Definition: ServiceServer.cpp:25
ros::NodeHandle


rosserial_mbed
Author(s): Gary Servin
autogenerated on Wed Mar 2 2022 00:58:08