ROS tools

01. rosbag

Introduction

rosbag 能夠將當前 topic 的訊息記錄下來,並在之後使用 play 將紀錄下的訊息回放

Record

$ rosbag record [TOPIC_NAME]
  • 紀錄所有 topic 的訊息
$ rosbag record -a
  • 設定紀錄時長
$ rosbag record --duration 10 [TOPIC_NAME] $ rosbag record --duration 10 /callback_vel
  • 接收指定 node 所接收到的訊息
$ rosbag record --node=/navMec_node

Play

將 bag file 中的訊息再次回放到該 topic 中

  • 開始回放 bag file
$ rosbag play 0125.bag
  • rostopic 查看是否有訊息
$ rostopic echo /navMec_node

Example

  1. 先簡單寫一個 publisher
#include "ros/ros.h" #include "std_msgs/Int64.h" int main(int argc, char **argv){ ros::init(argc, argv, "pub_tutorial"); ros::NodeHandle nh; ros::Publisher pub = nh.advertise<std_msgs::Int64>("data_tutorial", 10); std_msgs::Int64 data; data.data = 5; ros::Rate rate(2); while(ros::ok()){ data.data += 2; pub.publish(data); rate.sleep(); } }
  1. 執行看看該 publisher ,並開另一個終端機以 rostopic echo 查看
$ rosrun [PACKAGE NAME] [NODE NAME]
$ rostopic echo [TOPIC NAME]
  1. 在 package 底下創建 bag folder ( 統一環境而已,也可以用自己的方式儲存要用的 bag file )
$ roscd [PACKAGE NAME] $ mkdir bag $ cd bag
  1. rosrun 剛剛的 publisher 並使用開另一個終端機紀錄訊息 rosbag record
$ rosbag record --duration 10 [TOPIC NAME]
  1. 使用 rosbag play 回放剛剛存好的 bag file ,並使用 rostopic echo 查看該 topic 得到的訊息
$ rosbag play [BAG FILE NAME]
$ rostopic echo [TOPIC NAME]

02. rqt

ROS 內建的 GUI 界面,單獨使用的話沒什麼用,需搭配各種 plugins

基本概念

  • 啟動 rqt
$ rqt

啟動時會發現什麼東西都沒有,只有最上面那一列,因為目前沒有跑任何 node 而且也沒有使用任何 plugin

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

以 GUI 圖形界面直接啟用 plugin 的方式

  1. 點擊 Plugins

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  2. 選擇要用的 plugin ,例如我想看各個 node 之間的關聯,所以選擇 Node Graph

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

Basic command

  • 查看所有指令
$ rqt -h
  • 查看當前所有 plugin
$ rqt --list-plugins
  • 僅開啟當前 plugin
$ rqt -s [PLUGIN_NAME] $ rqt -s rqt_graph

Plugin 01 - rqt_graph

rqt_graph 將 node 以及 topic 的關係可視化,在大型專案中能更清楚各個 node 或是 topic 間的關係

  • 開啟
    rqt -> Plugin -> introspection -> Node Graph

  • 僅開啟 rqt_graph

$ rqt_graph # or $ rqt -s rqt_graph # or $ rosrun rqt_graph rqt_graph
  1. 選擇想查看的類型

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  2. 濾出想查看的 topic 或是 node

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  3. 查看關係 - EXAMPLE
    例如底下的圖,/navMec_node 為 publisher 並傳送資料到 topic /push_vel 上,接著 /encoder_node 為 subscriber 接收這些資訊

Plugin 02 - rqt_bag

將 topic 中的 message 錄製下來,並以圖形化界面加上時間條顯示,尤其是在比賽前實際到比賽場地測試時,將所有資訊錄下來,即便測試時間有限,回去仍舊可以 debug

  • 開啟
    rqt -> Plugin -> Logging -> Bag

  • 僅開啟 rqt_bag

$ rqt_bag # or $ rqt -s rqt_bag # or $ rosrun rqt_bag rqt_bag
  1. 選擇要紀錄的 topic

    1. 點擊紅色按鈕
    2. 選擇要紀錄的 topic 並開始紀錄
  2. 停止紀錄
    再次按下紅色按鈕

  3. 播放

$ rqt_bag [BAG_FILE] $ rqt_bag hello_world.bag

Plugin 03 - rqt_plot

rqt_plot 將 topic 中的資料圖形化,方便查看 message 的變化

  • 開啟
    rqt -> Plugin -> Visualization -> Plot

  • 僅開啟 rqt_plot

$ rqt_plot # or $ rqt -s rqt_plot # or $ rosrun rqt_plot rqt_plot
  1. 選擇要監控的 topic

  2. 將其加入到底下的圖表

  3. 取消監聽某一 topic

  4. 設置圖表邊框距離

  5. 設置圖表的 x-y 軸範圍以及圖表顯示的各種數據

Plugin 04 - rqt_topic

監控 topic 的資料以及 頻寬頻率,可以想像成 rostopic 圖形界面

  • 開啟
    rqt -> Plugin -> Topics -> Topic Monitor

  • 僅開啟 rqt_topic

$ rqt_topic # or $ rqt -s rqt_topic # or $ rosrun rqt_topic rqt_topic
  1. 勾選欲監控的 topic

  2. 點擊查看更詳細的資訊

Plugin 05 - rqt_console

取得當前 Node 或 Topic 印出於 console 的東西
相較於使用終端機看,rqt_console 能濾出一些不必要的訊息,加速 debug

  • 開啟
    rqt -> Plugin -> Logging -> Console

  • 僅開啟 rqt_console

$ rqt_console # or $ rqt -s rqt_console # or $ rosrun rqt_console rqt_console
  1. 選擇欲加入的方式

  2. 查看 messages

  3. ...containing 濾掉不要的訊息

  • EX : 濾掉所有含有 4 的訊息

Plugin 06 - rqt_launch

圖形化的 launch 界面

  • 開啟
    rqt -> Plugin -> Configuration -> Launch

  • 僅開啟 rqt_launch

$ rqt -s rqt_launch
  1. 選擇 launch file

  2. 加入該 launch 檔需要的參數

  3. 增加其他 node 需要的 args

  4. 執行全部 / 停止全部