logging.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * rosserial PubSub Example
  3. * Prints "hello world!" and toggles led
  4. */
  5. #include <rtthread.h>
  6. #include <board.h>
  7. #include <ros.h>
  8. #include <std_msgs/String.h>
  9. #include <std_msgs/Empty.h>
  10. static ros::NodeHandle nh;
  11. static std_msgs::String str_msg;
  12. static ros::Publisher chatter("chatter", &str_msg);
  13. static char hello[13] = "hello world!";
  14. static char debug[]= "debug statements";
  15. static char info[] = "infos";
  16. static char warn[] = "warnings";
  17. static char error[] = "errors";
  18. static char fatal[] = "fatalities";
  19. static void rosserial_logging_thread_entry(void *parameter)
  20. {
  21. nh.initNode();
  22. nh.advertise(chatter);
  23. while (1)
  24. {
  25. str_msg.data = hello;
  26. chatter.publish( &str_msg );
  27. nh.logdebug(debug);
  28. nh.loginfo(info);
  29. nh.logwarn(warn);
  30. nh.logerror(error);
  31. nh.logfatal(fatal);
  32. nh.spinOnce();
  33. rt_thread_mdelay(500);
  34. }
  35. }
  36. static void rosserial_logging_example(int argc,char *argv[])
  37. {
  38. rt_thread_t thread = rt_thread_create("r_log", rosserial_logging_thread_entry, RT_NULL, 1024, 25, 10);
  39. if(thread != RT_NULL)
  40. {
  41. rt_thread_startup(thread);
  42. rt_kprintf("[rosserial] New thread r_log\n");
  43. }
  44. else
  45. {
  46. rt_kprintf("[rosserial] Failed to create thread r_log\n");
  47. }
  48. }
  49. MSH_CMD_EXPORT(rosserial_logging_example, roserial publish and subscribe with UART);
  50. // If you are using Keil, you can ignore everything below
  51. // This is required
  52. // If you'd like to compile with scons which uses arm-none-eabi-gcc
  53. // extern "C" void __cxa_pure_virtual()
  54. // {
  55. // while (1);
  56. //}
  57. // Moreover, you need to add:
  58. // CXXFLAGS = CFLAGS + ' -fno-rtti'
  59. // in rtconfig.py for arm-none-eabi-gcc