1 配置ROS工作空間
通過一下指令建立工作區:
$ mkdir -p ~/catkin_ws/src
$ cd ~/catkin_ws/
$ catkin_make
在重新開機終端後,運作如下指令加載工作區:
$ source devel/setup.bash
2 ROS檔案系統
查找包:
$ rospack find [package_name]
進入包目錄:
檢視包目錄内容:
3 建立包
建立包的指令,在src檔案夾中執行:
編譯包的指令,在工程檔案夾(catkin_ws)中執行
$ catkin_make
檢視包的依賴關系,可分為一級依賴關系和所有依賴關系。檢視一級依賴關系如下:
$ rospack depends1 <package_name>
通過一下指令可以檢視所有依賴關系:
$ rospack depends <package_name>
4 ROS節點
在使用其他ROS節點前,首先執行
$ roscore
列出活躍的ROS節點:
$ rosnode list
檢視特定ROS節點的資訊:
$ rosnode info /<ROS_node_name>
執行特定包中的特定ROS節點:
5 ROS topic
使用rqt_graph檢視節點和topic的圖形資訊:
$ rosrun rqt_graph rqt_graph
使用ROS topic指令
rostopic bw display bandwidth used by topic
rostopic echo print messages to screen
rostopic hz display publishing rate of topic
rostopic list print information about active topics
rostopic pub publish data to topic
rostopic type print topic type
比較常用的為如下幾個:
rostopic echo
該指令用于顯示被釋出到特定topic上的資訊:
$ rostopic echo [topic]
rostopic list
列出目前被訂閱或者釋出的topic
$ rostopic list
該指令後可帶參數:
-h, --help show this help message and exit
-b BAGFILE, --bag=BAGFILE
list topics in .bag file
-v, --verbose list full details about each topic
-p list only publishers
-s list only subscriber
一般會使用:
rostopic type
傳回目前topic對應的消息類型:
rostopic pub
釋出目前topic對應的資料
例如:
其中[msg_type]可以通過
rostopic type [topic]
指令檢視到,例如:
上述指令将傳回
geometry_msgs/Twist
然後具體的msg的内容,即[args]可以通過rosmsg show檢視到:
上述指令将傳回
geometry_msgs/Vector3 linear
float64 x
float64 y
float64 z
geometry_msgs/Vector3 angular
float64 x
float64 y
float64 z
rostopic hz
該指令将傳回rostopic釋出資料的頻率:
$ rostopic hz [topic]
6 ROS服務
ROS服務(Services)是ROS節點的一種消息傳遞方式,通過發送request和接收response完成。
rosservice指令
rosservice提供一下指令:
rosservice list print information about active services
rosservice call call the service with the provided args
rosservice type print service type
rosservice find find services by service type
rosservice uri print service ROSRPC uri
其中
$ rosservice list
列出目前提供的服務。
可以檢視特定服務的類型(參數類型),例如:
$ rosservice type /clear
$ std_srvs/Empty
上述代碼通過
rosservice type
指令檢視服務/clear(清空)的類型,傳回的是一個空類型(在發送request的時候不包含資料,接收response的時候也沒有資料)。
可以通過rosservice call指令來調用服務:
例如我們調用上述/clear服務,由于是空類型,我們不需要加參數:
$ rosservice call /clear
7 ROS參數
可以通過rosparam來存儲和處理ROS參數伺服器(Parameter Server)上的資料。
rosparam set set parameter
rosparam get get parameter
rosparam load load parameters from file
rosparam dump dump parameters to file
rosparam delete delete parameter
rosparam list list parameter names
例如:
$ rosparam list
該指令傳回:
/background_b
/background_g
/background_r
/rosdistro
/roslaunch/uris/host_57aea0986fef__34309
/rosversion
/run_id
即目前使用到的參數,可以通過
rosparam set [param_name]
rosparam get [param_name]
對參數進行修改和檢視。修改參數的例子如下:
$ rosparam set /background_r
$ rosservice call /clear
可看到turtlesim的背景變了。檢視參數的例子如下:
$ rosparam get /background_g
$
另外:
$ rosparam get /
可以擷取參數清單中所有參數的值:
background_b:
background_g:
background_r:
roslaunch:
uris: {'aqy:51932': 'http://aqy:51932/'}
run_id: e07ea71e-df-de--b21201aa8
可以通過
rosparam dump [file_name] [namespace]
rosparam load [file_name] [namespace]
将上述參數寫入檔案或者從檔案導出,例如我們通過下面的方式将所有的參數寫入params.yaml 檔案:
$ rosparam dump params.yaml
可以将參數從這些檔案中導出:
$ rosparam load params.yaml copy
$ rosparam get /copy/background_b
$
8 roslaunch
roslaunch用于啟動多個ros節點,啟動的細節通過launch檔案在定義。
典型的launch檔案如下:
<launch>
<group ns="turtlesim1">
<node pkg="turtlesim" name="sim" type="turtlesim_node"/>
</group>
<group ns="turtlesim2">
<node pkg="turtlesim" name="sim" type="turtlesim_node"/>
</group>
<node pkg="turtlesim" name="mimic" type="mimic">
<remap from="input" to="turtlesim1/turtle1"/>
<remap from="output" to="turtlesim2/turtle1"/>
</node>
</launch>
其中,ns表示group的命名空間,可以使我們啟動兩個相同的節點,但是不會發生沖突。