ROS与Arduino学习(六)Logging日志

ROS与Arduino学习(六)Logging日志

 

Tutorial Level:客户端与服务器

Next Tutorial:小案例节点通信

     本节较为简单告诉大家如何向系统发布日志信息。

Tips 1 日志信息发布

节点提供了五种日志消息,分别是debug、information、warn、error、fatal。可以分别用以下函数调用。其中参数为一个字符串

  nh.logdebug(debug);
  nh.loginfo(info);
  nh.logwarn(warn);
  nh.logerror(error);
  nh.logfatal(fatal);

 

Tips 2 案例程序

/*
 * rosserial PubSub Example
 * Prints "hello world!" and toggles led
 */

#include <ros.h>
#include <std_msgs/String.h>
#include <std_msgs/Empty.h>

ros::NodeHandle  nh;


std_msgs::String str_msg;
ros::Publisher chatter("chatter", &str_msg);

char hello[13] = "hello world!";


char debug[]= "debug statements";
char info[] = "infos";
char warn[] = "warnings";
char error[] = "errors";
char fatal[] = "fatalities";

void setup()
{
  pinMode(13, OUTPUT);
  nh.initNode();
  nh.advertise(chatter);
}

void loop()
{
  str_msg.data = hello;
  chatter.publish( &str_msg );
  
  nh.logdebug(debug);
  nh.loginfo(info);
  nh.logwarn(warn);
  nh.logerror(error);
  nh.logfatal(fatal);
  
  nh.spinOnce();
  delay(500);
}

 

Tips 3 测试程序

 

#新终端打开
$ roscore
#新终端打开
$  rosrun rosserial_python serial_node.py _port:=/dev/ttyUSB0

 

posted @ 2018-04-26 12:04  #Cloud  阅读(842)  评论(0编辑  收藏  举报