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

  • 請見我的另外博客


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM