pubsub.cpp
Go to the documentation of this file.
1 /*
2  * rosserial PubSub Example
3  * Prints "hello world!" and toggles led
4  */
5 #include "mbed.h"
6 #include <ros.h>
7 #include <std_msgs/String.h>
8 #include <std_msgs/Empty.h>
9 
11 DigitalOut myled(LED1);
12 
13 void messageCb( const std_msgs::Empty& toggle_msg) {
14  myled = !myled; // blink the led
15 }
16 
18 
19 std_msgs::String str_msg;
20 ros::Publisher chatter("chatter", &str_msg);
21 
22 char hello[13] = "hello world!";
23 
24 int main() {
25  nh.initNode();
26  nh.advertise(chatter);
27  nh.subscribe(sub);
28 
29  while (1) {
30  str_msg.data = hello;
32  nh.spinOnce();
33  wait_ms(500);
34  }
35 }
36 
void publish(const boost::shared_ptr< M > &message) const
std_msgs::String str_msg
Definition: pubsub.cpp:19
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ros::NodeHandle nh
Definition: pubsub.cpp:10
char hello[13]
Definition: pubsub.cpp:22
ros::Subscriber< std_msgs::Empty > sub("toggle_led", messageCb)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ros::Publisher chatter("chatter",&str_msg)
DigitalOut myled(LED1)
int main()
Definition: pubsub.cpp:24
void messageCb(const std_msgs::Empty &toggle_msg)
Definition: pubsub.cpp:13


rosserial_mbed
Author(s): Gary Servin
autogenerated on Mon Jun 10 2019 14:53:26