tags: DIT 12th 教學 – ROS 1
Loading embed note
rosbag可以儲存Topics當前的訊息,之後再回放出來,可以重複觀看數據進行debug
$ rosbag record [TOPIC_NAME]
$ rosbag record -a
$ rosbag record --duration 10 [TOPIC_NAME]
$ rosbag record --node=/[NODE_NAME]
$ rosbag record -O [FILE_NAME]
$ rosbag play [BAG_FILE_NAME.bag]
#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;
}
$ rosrun basiclearn talker
$ rostopic echo /counter
$ roscd basiclearn
$ mkdir bag
$ rosbag record --duration 10 /counter
$ rosbag play [BAG_FILE_NAME]
$ rostopic echo /counter
ROS內建的GUI界面
$ rqt
打開來應該會是一個空白的頁面,點一下plugin後才開始有東西
可視化node和topic間的關係
$ rqt_graph # or
$ rqt -s rqt_graph # or
$ rosrun rqt_graph rqt_graph
選擇想查看的類型
濾出想看的topic或是Node
example
例如底下的圖,/navMec_node 為 publisher 並傳送資料到 topic /push_vel 上,接著 /encoder_node 為 subscriber 接收這些資訊
將 topic 中的 message 錄製下來,並以圖形化界面加上時間條顯示,尤其是在比賽前實際到比賽場地測試時,將所有資訊錄下來,即便測試時間有限,回去仍舊可以 debug
$ rqt_bag # or
$ rqt -s rqt_bag # or
$ rosrun rqt_bag rqt_bag
按紅色按鈕
-
選擇topic並紀錄
再按一次紅色按鈕停止紀錄
$ rqt_bag [BAG_FILE]
rqt_plot 將 topic 中的資料圖形化,方便查看 message 的變化
$ rqt_plot # or
$ rqt -s rqt_plot # or
$ rosrun rqt_plot rqt_plot
輸入要監控的 topic
點擊加號將其加入到底下的圖表
點擊減號的小三角形取消監聽某一 topic
點放大鏡右邊的圖示可以設置圖表邊框距離
設置圖表的 x-y 軸範圍以及圖表顯示的各種數據
監控 topic 的資料以及 頻寬 和 頻率,可以想像成 rostopic 圖形界面
rqt -> Plugin -> Topics -> Topic Monitor
僅開啟 rqt_topic
$ rqt_topic # or
$ rqt -s rqt_topic # or
$ rosrun rqt_topic rqt_topic
勾選欲監控的 topic
點擊查看更詳細的資訊
Gazebo 是一個三維物理模擬平台,它可以模擬現實世界中的各種物理行為,因此當我們手上沒有實驗環境,我們便可以透過於此來搭建模擬環境。剛開啟gazebo什麼也沒有,不過我們可以透過左邊 insert的選項插入我們下載的不同的地圖物件。
$ gazebo
Rviz能將sensor的各種數據可視化,以圖像的方式表達
$ rviz
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一下
$ roslaunch wpr_simulation wpb_gmapping.launch(用於開啟rviz gazebo)
$ rosrun wpr_simulation keyboard_vel_ctrl(open controller)
以下是gazebo和rviz
在terminal通過鍵盤控制機器人行走
rviz左方可調整想可視化的topic