ROS与Arduino学习(六)Logging日志

本文介绍如何在ROS与Arduino的环境中使用不同级别的日志记录功能。通过示例程序展示了如何发布debug、info、warn、error及fatal五种类型的日志消息。

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 阅读(...) 评论(...) 编辑 收藏

shr@ubuntu:~/h_ws$ roslaunch urdf1_rviz d7_control.launch ... logging to /home/shr/.ros/log/8b996cec-677d-11f0-8c1d-e5f088e14116/roslaunch-ubuntu-19949.log Checking log directory for disk usage. This may take a while. Press Ctrl-C to interrupt Done checking log file disk usage. Usage is <1GB. started roslaunch server http://ubuntu:44935/ SUMMARY ======== PARAMETERS * /arbotix/controllers/base_controller/Kd: 12 * /arbotix/controllers/base_controller/Ki: 0 * /arbotix/controllers/base_controller/Ko: 50 * /arbotix/controllers/base_controller/Kp: 12 * /arbotix/controllers/base_controller/accel_limit: 1.0 * /arbotix/controllers/base_controller/base_frame_id: base_footprint * /arbotix/controllers/base_controller/base_width: 0.2 * /arbotix/controllers/base_controller/ticks_meter: 2000 * /arbotix/controllers/base_controller/type: diff_controller * /arbotix/sim: True * /robot_description: <?xml version="1.... * /rosdistro: noetic * /rosversion: 1.17.4 NODES / arbotix (arbotix_python/arbotix_driver) joint_state_publisher (joint_state_publisher/joint_state_publisher) robot_state_publisher (robot_state_publisher/robot_state_publisher) rviz (rviz/rviz) ROS_MASTER_URI=http://localhost:11311 process[rviz-1]: started with pid [19965] process[joint_state_publisher-2]: started with pid [19966] process[robot_state_publisher-3]: started with pid [19967] process[arbotix-4]: started with pid [19968] Error in XmlRpcClient::writeRequest: write error (Connection refused). Error in XmlRpcClient::writeRequest: write error (Connection refused). Traceback (most recent call last): File "/home/shr/h_ws/src/arbotix_ros/arbotix_python/bin/arbotix_driver", line 36, in <module> from arbotix_python.arbotix import ArbotiX, ArbotiXException File "/home/shr/h_ws/src/arbotix_ros/arbotix_python/src/arbotix_python/arbotix.py", line 33, in <module> import serial, time, sys, threading ModuleNotFoundError: No module named 'serial' [arbotix-4] process has died [pid 19968, exit code 1, cmd /home/shr/h_ws/src/arbotix_ros/arbotix_python/bin/arbotix_driver __name:=arbotix __log:=/home/shr/.ros/log/8b996cec-677d-11f0-8c1d-e5f088e14116/arbotix-4.log]. log file: /home/shr/.ros/log/8b996cec-677d-11f0-8c1d-e5f088e14116/arbotix-4*.log
最新发布
07-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值