01. ROS tools

tags: DIT 12th 教學 ROS 1


Loading embed note

ROSbag

introduction

rosbag可以儲存Topics當前的訊息,之後再回放出來,可以重複觀看數據進行debug

record

$ rosbag record [TOPIC_NAME]
  • 紀錄所有的訊息
$ rosbag record -a
  • 設定紀錄時長
$ rosbag record --duration 10 [TOPIC_NAME]
  • 紀錄某個node中接受的訊息
$ rosbag record --node=/[NODE_NAME]
  • 指定bag file名稱
$ rosbag record -O [FILE_NAME]

play

  • 回放儲存的bag file
$ rosbag play [BAG_FILE_NAME.bag]

example

  1. 寫一個簡單的publisher(basiclearn中的talker.cpp)
#include "ros/ros.h"
#include "std_msgs/Int64.h"

int main(int argc, char **argv)
{
    ros::init(argc, argv, "talker");
    ros::NodeHandle nh;
    ros::Publisher pub = nh.advertise<std_msgs::Int64>("counter", 10);
    ros::Rate loop_rate(2);
    
    int number = 0;
    std_msgs::Int64 msg;
    
    while(ros::ok())
    {
        msg.data = number;
        // ROS_INFO("%ld", msg.data);
        pub.publish(msg);
        
        number++;
        loop_rate.sleep();
    }
    return 0;
}
  1. 執行這個publisher,並利用rostopic echo來查看"counter"的即時訊息
$ rosrun basiclearn talker
$ rostopic echo /counter
  1. 在 package 底下創建 bag folder ( 統一環境而已,也可以用自己的方式儲存要用的 bag file )
$ roscd basiclearn $ mkdir bag
  1. rosrun 剛剛的 publisher 並使用開另一個terminal紀錄訊息 rosbag record,記得要先進去bag這一層資料夾
$ rosbag record --duration 10 /counter
  1. 使用 rosbag play 回放剛剛存好的 bag file ,用另一個terminal 進行rostopic echo
$ rosbag play [BAG_FILE_NAME] $ rostopic echo /counter

rqt

ROS內建的GUI界面

  • 先打開rqt
$ rqt

打開來應該會是一個空白的頁面,點一下plugin後才開始有東西

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

some plugins

rqt_graph

可視化node和topic間的關係

  • rqt->Plugin->intorspection->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 was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

  2. 濾出想看的topic或是Node

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

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

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

rqt_bag

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

  1. 開啟
  • rqt -> Plugin -> Logging -> Bag
  • 僅開啟 rqt_bag
$ rqt_bag # or $ rqt -s rqt_bag # or $ rosrun rqt_bag rqt_bag
  1. 選擇要紀錄的 topic
  • 按紅色按鈕
    -

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

  • 選擇topic並紀錄

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

  • 再按一次紅色按鈕停止紀錄

  1. 播放
$ rqt_bag [BAG_FILE]

rqt_plot

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

  1. 開啟
  • rqt -> Plugin -> Visualization -> Plot
  • 僅開啟 rqt_plot
$ rqt_plot # or
$ rqt -s rqt_plot # or
$ rosrun rqt_plot rqt_plot

wczUAbP

  1. 輸入要監控的 topic

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

  3. 點擊減號的小三角形取消監聽某一 topic

  4. 點放大鏡右邊的圖示可以設置圖表邊框距離G9LRQwm

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

rqt_topic

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

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

  • 僅開啟 rqt_topic

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

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

Gazebo

Gazebo 是一個三維物理模擬平台,它可以模擬現實世界中的各種物理行為,因此當我們手上沒有實驗環境,我們便可以透過於此來搭建模擬環境。剛開啟gazebo什麼也沒有,不過我們可以透過左邊 insert的選項插入我們下載的不同的地圖物件。

  1. 單獨開啟
$ gazebo

Rviz

Rviz能將sensor的各種數據可視化,以圖像的方式表達

  1. 單獨開啟
$ rviz

examples

  • 在workspace/src裡執行下列操作
git clone https://github.com/6-robot/wpr_simulation.git git clone https://github.com/6-robot/wpb_home.git
$ cd .. $ sudo apt update $ cd wpr_simulation/scripts/ $ ./install_for_noetic.sh 回到workspace $ cd wpb_home/wpb_home_bringup/scripts/ $ ./install_for_noetic.sh 回到workspace $ catkin_make 接下來source一下
  • launch以下檔案來開啟gazebo rviz and 控制器
$ roslaunch wpr_simulation wpb_gmapping.launch(用於開啟rviz gazebo) $ rosrun wpr_simulation keyboard_vel_ctrl(open controller)
  • 以下是gazebo和rviz
    gazebo
    rviz

  • 在terminal通過鍵盤控制機器人行走

  • rviz左方可調整想可視化的topic