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 Servo roscar_ver_20190501_anglechange_copy ros_lib_kinetic roscar_ver_20190501_copy
main.cpp@0:2595562b0c61, 2018-08-10 (annotated)
- Committer:
- FernandoLG
- Date:
- Fri Aug 10 21:02:43 2018 +0000
- Revision:
- 0:2595562b0c61
- Child:
- 1:fb8f963047b0
Initial test commit to publish
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| FernandoLG | 0:2595562b0c61 | 1 | /* | 
| FernandoLG | 0:2595562b0c61 | 2 | * rosserial Subscriber Example | 
| FernandoLG | 0:2595562b0c61 | 3 | * Blinks an LED on callback | 
| FernandoLG | 0:2595562b0c61 | 4 | */ | 
| FernandoLG | 0:2595562b0c61 | 5 | #include "mbed.h" | 
| FernandoLG | 0:2595562b0c61 | 6 | #include <ros.h> | 
| FernandoLG | 0:2595562b0c61 | 7 | #include <std_msgs/String.h> | 
| FernandoLG | 0:2595562b0c61 | 8 | |
| FernandoLG | 0:2595562b0c61 | 9 | ros::NodeHandle nh; | 
| FernandoLG | 0:2595562b0c61 | 10 | DigitalOut myled(LED1); | 
| FernandoLG | 0:2595562b0c61 | 11 | |
| FernandoLG | 0:2595562b0c61 | 12 | std_msgs::String commandRead; | 
| FernandoLG | 0:2595562b0c61 | 13 | ros::Publisher chatter("chatter", &commandRead); | 
| FernandoLG | 0:2595562b0c61 | 14 | |
| FernandoLG | 0:2595562b0c61 | 15 | // /* | 
| FernandoLG | 0:2595562b0c61 | 16 | void messageCb(const std_msgs::String& command){ | 
| FernandoLG | 0:2595562b0c61 | 17 | myled = 1; // turn on the led | 
| FernandoLG | 0:2595562b0c61 | 18 | commandRead.data = command.data; | 
| FernandoLG | 0:2595562b0c61 | 19 | } | 
| FernandoLG | 0:2595562b0c61 | 20 | // */ | 
| FernandoLG | 0:2595562b0c61 | 21 | |
| FernandoLG | 0:2595562b0c61 | 22 | ros::Subscriber<std_msgs::String> sub("toggle_led", &messageCb); | 
| FernandoLG | 0:2595562b0c61 | 23 | |
| FernandoLG | 0:2595562b0c61 | 24 | //char message[13] = "012345678910"; | 
| FernandoLG | 0:2595562b0c61 | 25 | |
| FernandoLG | 0:2595562b0c61 | 26 | int main() { | 
| FernandoLG | 0:2595562b0c61 | 27 | nh.initNode(); | 
| FernandoLG | 0:2595562b0c61 | 28 | nh.subscribe(sub); | 
| FernandoLG | 0:2595562b0c61 | 29 | nh.advertise(chatter); | 
| FernandoLG | 0:2595562b0c61 | 30 | |
| FernandoLG | 0:2595562b0c61 | 31 | while (1) { | 
| FernandoLG | 0:2595562b0c61 | 32 | myled = 0; // turn off the led | 
| FernandoLG | 0:2595562b0c61 | 33 | // commandRead.data = message ; | 
| FernandoLG | 0:2595562b0c61 | 34 | chatter.publish( &commandRead); | 
| FernandoLG | 0:2595562b0c61 | 35 | nh.spinOnce(); | 
| FernandoLG | 0:2595562b0c61 | 36 | wait_ms(1); | 
| FernandoLG | 0:2595562b0c61 | 37 | } | 
| FernandoLG | 0:2595562b0c61 | 38 | } |