src
examples
Blink
Blink.cpp
Go to the documentation of this file.
1
/*
2
* rosserial Subscriber Example
3
* Blinks an LED on callback
4
*/
5
#include "mbed.h"
6
#include <ros.h>
7
#include <std_msgs/Empty.h>
8
9
ros::NodeHandle
nh
;
10
DigitalOut
myled
(LED1);
11
12
void
messageCb
(
const
std_msgs::Empty& toggle_msg){
13
myled
= !
myled
;
// blink the led
14
}
15
16
ros::Subscriber<std_msgs::Empty>
sub
(
"toggle_led"
, &
messageCb
);
17
18
int
main
() {
19
nh
.initNode();
20
nh
.
subscribe
(
sub
);
21
22
while
(1) {
23
nh
.spinOnce();
24
wait_ms(1);
25
}
26
}
27
messageCb
void messageCb(const std_msgs::Empty &toggle_msg)
Definition:
Blink.cpp:12
nh
ros::NodeHandle nh
Definition:
Blink.cpp:9
ros::NodeHandle::subscribe
Subscriber subscribe(const std::string &topic, uint32_t queue_size, const boost::function< void(C)> &callback, const VoidConstPtr &tracked_object=VoidConstPtr(), const TransportHints &transport_hints=TransportHints())
sub
ros::Subscriber< std_msgs::Empty > sub("toggle_led", &messageCb)
main
int main()
Definition:
Blink.cpp:18
ros::Subscriber
ros::NodeHandle
myled
DigitalOut myled(LED1)
rosserial_mbed
Author(s): Gary Servin
autogenerated on Wed Mar 2 2022 00:58:08