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: Servo mbed rosserial_mbed_lib
Fork of rosserial_mbed by
Diff: examples/pubsub.cpp
- Revision:
- 0:06fc856e99ca
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/pubsub.cpp Fri Aug 19 09:06:16 2011 +0000 @@ -0,0 +1,41 @@ +//#define COMPILE_PUBSUB_CODE_ROSSERIAL +#ifdef COMPILE_PUBSUB_CODE_ROSSERIAL + +/* + * rosserial PubSub Example + * Prints "hello world!" and toggles led + */ +#include "mbed.h" +#include <ros.h> +#include <std_msgs/String.h> +#include <std_msgs/Empty.h> + +ros::NodeHandle nh; +DigitalOut myled(LED1); + +void messageCb( const std_msgs::Empty& toggle_msg) { + myled = !myled; // blink the led +} + +ros::Subscriber<std_msgs::Empty> sub("toggle_led", messageCb ); + + + +std_msgs::String str_msg; +ros::Publisher chatter("chatter", &str_msg); + +char hello[13] = "hello world!"; + +int main() { + nh.initNode(); + nh.advertise(chatter); + nh.subscribe(sub); + + while (1) { + str_msg.data = hello; + chatter.publish( &str_msg ); + nh.spinOnce(); + wait_ms(500); + } +} +#endif \ No newline at end of file