This program is porting rosserial_arduino for mbed http://www.ros.org/wiki/rosserial_arduino This program supported the revision of 169 of rosserial. This program contains an example.

Dependencies:   rosserial_mbed_lib mbed Servo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers HelloWorld.cpp Source File

HelloWorld.cpp

00001 #define COMPILE_HELLOWORLD_CODE_ROSSERIAL
00002 #ifdef  COMPILE_HELLOWORLD_CODE_ROSSERIAL
00003 
00004 /*
00005  * rosserial Publisher Example
00006  * Prints "hello world!"
00007  */
00008 
00009 #include"mbed.h"
00010 #include <ros.h>
00011 #include <std_msgs/String.h>
00012 
00013 ros::NodeHandle  nh;
00014 
00015 std_msgs::String str_msg;
00016 ros::Publisher chatter("chatter", &str_msg);
00017 
00018 char hello[13] = "hello world!";
00019 
00020 int main() {
00021     nh.initNode();
00022     nh.advertise(chatter);
00023 
00024     while (1) {
00025         str_msg.data = hello;
00026         chatter.publish( &str_msg );
00027         nh.spinOnce();
00028         wait_ms(1000);
00029     }
00030 }
00031 
00032 #endif