Ros-RTOS helloworld example project

Dependencies:   mbed-rtos mbed ros_lib_indigo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "rtos.h"
00003 #include "cmsis_os.h"
00004 #include <ros.h>
00005 #include <std_msgs/String.h>
00006 
00007 
00008 
00009 ros::NodeHandle  nh;
00010 std_msgs::String str_msg;
00011 ros::Publisher chatter("chatter", &str_msg);
00012 
00013 
00014 DigitalOut led1(LED1);
00015 
00016 void print_thread(void const *argument)
00017 {
00018     char hello[13] = "hello world!"; 
00019     while (true) {
00020         Thread::wait(1000);
00021         str_msg.data = hello;
00022         chatter.publish( &str_msg );
00023         nh.spinOnce();
00024        
00025     }
00026 }
00027 
00028 int main()
00029 {
00030     nh.initNode();
00031     nh.advertise(chatter);
00032     
00033   
00034     Thread thread(print_thread, NULL, osPriorityNormal, DEFAULT_STACK_SIZE);
00035     
00036     while (true) {
00037         led1 = !led1;
00038         Thread::wait(500);
00039     }
00040     
00041 }