Project

General

Profile

Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (670 Bytes)

1 c1426757 Tom Mullins
/*
2
 * rosserial PubSub Example
3
 * Prints "hello world!" and toggles led
4
 */
5
6
#include <ros.h>
7
#include <std_msgs/String.h>
8
#include <std_msgs/Empty.h>
9
10
ros::NodeHandle  nh;
11
12
13
void messageCb( const std_msgs::Empty& toggle_msg){
14
  digitalWrite(13, HIGH-digitalRead(13));   // blink the led
15
}
16
17
ros::Subscriber<std_msgs::Empty> sub("toggle_led", messageCb );
18
19
20
21
std_msgs::String str_msg;
22
ros::Publisher chatter("chatter", &str_msg);
23
24
char hello[13] = "hello world!";
25
26
void setup()
27
{
28
  pinMode(13, OUTPUT);
29
  nh.initNode();
30
  nh.advertise(chatter);
31
  nh.subscribe(sub);
32
}
33
34
void loop()
35
{
36
  str_msg.data = hello;
37
  chatter.publish( &str_msg );
38
  nh.spinOnce();
39
  delay(500);
40
}