rosserial_mbed Hello World example for Melodic Morenia distribution
Dependencies: mbed ros_lib_melodic
main.cpp@2:7968a5c6a53b, 2019-11-08 (annotated)
- Committer:
- garyservin
- Date:
- Fri Nov 08 18:00:37 2019 +0000
- Revision:
- 2:7968a5c6a53b
- Parent:
- 0:f48f597ef690
Update mbed lib
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Gary Servin |
0:f48f597ef690 | 1 | /* |
Gary Servin |
0:f48f597ef690 | 2 | * rosserial Subscriber Example |
Gary Servin |
0:f48f597ef690 | 3 | * Blinks an LED on callback |
Gary Servin |
0:f48f597ef690 | 4 | */ |
Gary Servin |
0:f48f597ef690 | 5 | #include "mbed.h" |
Gary Servin |
0:f48f597ef690 | 6 | #include <ros.h> |
Gary Servin |
0:f48f597ef690 | 7 | #include <std_msgs/Empty.h> |
Gary Servin |
0:f48f597ef690 | 8 | |
Gary Servin |
0:f48f597ef690 | 9 | ros::NodeHandle nh; |
Gary Servin |
0:f48f597ef690 | 10 | DigitalOut myled(LED1); |
Gary Servin |
0:f48f597ef690 | 11 | |
Gary Servin |
0:f48f597ef690 | 12 | void messageCb(const std_msgs::Empty& toggle_msg){ |
Gary Servin |
0:f48f597ef690 | 13 | myled = !myled; // blink the led |
Gary Servin |
0:f48f597ef690 | 14 | } |
Gary Servin |
0:f48f597ef690 | 15 | |
Gary Servin |
0:f48f597ef690 | 16 | ros::Subscriber<std_msgs::Empty> sub("toggle_led", &messageCb); |
Gary Servin |
0:f48f597ef690 | 17 | |
Gary Servin |
0:f48f597ef690 | 18 | int main() { |
Gary Servin |
0:f48f597ef690 | 19 | nh.initNode(); |
Gary Servin |
0:f48f597ef690 | 20 | nh.subscribe(sub); |
Gary Servin |
0:f48f597ef690 | 21 | |
Gary Servin |
0:f48f597ef690 | 22 | while (1) { |
Gary Servin |
0:f48f597ef690 | 23 | nh.spinOnce(); |
Gary Servin |
0:f48f597ef690 | 24 | wait_ms(1); |
Gary Servin |
0:f48f597ef690 | 25 | } |
Gary Servin |
0:f48f597ef690 | 26 | } |