Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed ros_lib_melodic
main.cpp@0:f48f597ef690, 2019-11-08 (annotated)
- Committer:
- Gary Servin
- Date:
- Fri Nov 08 14:46:24 2019 -0300
- Revision:
- 0:f48f597ef690
Initial commit for Melodic Morenia
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 | } |