Statistics
| Branch: | Revision:

root / quad2 / arduino / src / ros_lib / examples / ServiceServer / ServiceServer.pde @ c1426757

History | View | Annotate | Download (698 Bytes)

1
/*
2
 * rosserial Service Server
3
 */
4

    
5
#include <ros.h>
6
#include <std_msgs/String.h>
7
#include <rosserial_arduino/Test.h>
8

    
9
ros::NodeHandle  nh;
10
using rosserial_arduino::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

    
20
ros::ServiceServer<Test::Request, Test::Response> server("test_srv",&callback);
21

    
22
std_msgs::String str_msg;
23
ros::Publisher chatter("chatter", &str_msg);
24

    
25
char hello[13] = "hello world!";
26

    
27
void setup()
28
{
29
  nh.initNode();
30
  nh.advertiseService(server);
31
  nh.advertise(chatter);
32
}
33

    
34
void loop()
35
{
36
  str_msg.data = hello;
37
  chatter.publish( &str_msg );
38
  nh.spinOnce();
39
  delay(10);
40
}