6.28-ROS debug tools

TOC

参考

《ROS机器人程序设计》

前言

  • 必须学习,对大型项目开发有好处,加快效率
  • 本文章记录除gdb以外的ROS单独提供的辅助开发工具,包括日志输出,系统监测,和数据可视化。

学习记录

gdb调试

直接调试

  • 启动roscore之后
gdb bin/example1

roslaunch文件启动gdb或者valgrind

<node pkg="chapter3_tutorials" type="example1"
name="example1" output="screen"
launch-prefix="xterm -e gdb --args"/>
<node pkg="chapter3_tutorials" type="example1"
name="example1" output="screen"
launch-prefix="valgrind"/>

ros节点core文件转存

  • core文件是程序运行崩溃时刻的内存情况
# 取消core文件大小限制
ulimit -c unlimited
echo 1 > /proc/sys/kernel/core_uses_pid

调试信息

日志输出

# 不同等级的消息
# ROS_INFO("zs: ");
# ROS_WARN("zs: ");
# 条件(过滤)消息
# ROS_DEBUG_COND(x < 0, "Uh oh, x = %d, this is bad", x);
# 流消息
# ROS_DEBUG_STREAM_COND(x < 0, "Uh oh, x = " << x << ", this is bad");
# 命名消息
# ROS_DEBUG_COND_NAMED(x < 0, "test_only", "Uh oh, x = %d, this is bad", x);
# ROS_DEBUG_STREAM_COND_NAMED(x < 0, "test_only", "Uh oh, x = " << x << ", this is bad");
# 通用格式
ROS_INFO_STREAM_NAMED(
"named_msg",
"My named INFO stram message; val = " << val
);

设置调试信息级别

编译时设置
find_library(LOG4CXX_LIBRARY log4cxx)
rosbuild_add_executable(example1 src/example1.cpp)
target_link_libraries(example1 ${LOG4CXX_LIBRARY})
  • 在main函数中
// Set the logging level manually to DEBUG
ROSCONSOLE_AUTOINIT;
log4cxx::LoggerPtr my_logger =
log4cxx::Logger::getLogger( ROSCONSOLE_DEFAULT_NAME );
my_logger->setLevel(
ros::console::g_level_lookup[ros::console::levels::Debug]
);
启动时设置
  • config文件:创建一个config文件夹和chapter3_tutorials.config的文件
log4j.logger.ros.chapter3_tutorials=DEBUG
  • Launch文件:设置ROSCONSOLE_CONFIG_FILE环境变量指向我们的文件
<launch>
<!-- Logger config -->
<env name="ROSCONSOLE_CONFIG_FILE"
value="$(find chapter3_tutorials)/config/chapter3_tutorials.
config"/>
<!-- Example 1 -->
<node pkg="chapter3_tutorials" type="example1" name="example1"
output="screen"/>
</launch>

系统监测

  • 节点,主题,服务列表rostopic list
  • 节点状态图rqt_graph
  • 数据绘制rqt_plot

数据可视化

显示普通摄像头图像

# 这样输出的是文本信息,没有意义
rostopic echo /camera
# 应该这样
rosrun image_view image_view image:=/camera

fire1394摄像头图像

rosrun camera1394 camera1394_node
rqt
# 使用dynamic reconfigure_gui

相机标定

rosrun camera_calibration cameracalibrator.py --size 8x6 --square 0.108
image:=/camera/image_raw camera:=/camera

rviz和ros_bag

  • 请见我的另外博客
原文地址:https://www.cnblogs.com/lizhensheng/p/11117483.html