瀏覽ROS 文件系統(tǒng)
- Packages: Packages are the software organization unit of ROS code. Each package can contain libraries, executables, scripts, or other artifacts.
- Manifests (package.xml): A manifest is a description of a package . It serves to define dependencies between packages and to capture meta information about the package like version, maintainer, license, etc...
文件系統(tǒng)(Filesystem)的工具
**rospack find **返回 package的路徑:
$ rospack find [package_name]```
返回:
YOUR_INSTALL_PATH/share/roscpp```
roscd直接改變目錄驶俊,跳轉(zhuǎn)到package或者stacks腊满。
$ roscd [locationname[/subdir]]```
返回:
YOUR_INSTALL_PATH/share/roscpp```
用 Unix command pwd打印出工作目錄:
$ pwd```
<small>
上述兩條命令返回結(jié)果相同旺遮,注意:
*Note that <b>roscd</b>, like other ROS tools, will <b>only find ROS packages</b> that are<b> within</b> the directories listed in your ROS_PACKAGE_PATH.* </small>
* * *
####創(chuàng)建一個(gè)*ROS package*
一個(gè)package如果被看作為**catkin package**顿痪,需要符合以下幾個(gè)條件:
1. 這個(gè)包必須含有一個(gè)**catkin compliant package.xml** 文件,
- 這個(gè)**package.xml**文件提供關(guān)于package的信息痛阻。
2. 這個(gè)包必須含有一個(gè) **CMakeLists.txt** 用來**catkin**菌瘪,它是一個(gè)catkin metapackage。
3. 在一個(gè)文件中至多只有一個(gè)package:
- 這說明阱当,在同一個(gè)目錄下不能嵌套package或者有多個(gè)package麻车。
$ cd ~/catkin_ws/src
$ catkin_create_pkg beginner_tutorials std_msgs rospy roscpp
catkin_create_pkg <package_name> [depend1] [depend2] [depend3]
####組建catkin空間和包缀皱,并添加路徑:
$ cd ~/catkin_ws
$ catkin_make
$ . ~/catkin_ws/devel/setup.bash```
理解 ROS Nodes
Node:
A node really isn't much more than an executable file within a ROS package. ROS nodes use a ROS client library to communicate with other nodes. Nodes can publish or subscribe to a Topic. Nodes can also provide or use a Service.
Client Libraries:
ROS client libraries allow nodes written in different programming languages to communicate:
- rospy = python client library
- roscpp = c++ client library
打開終端后首先運(yùn)行roscore斗这,使用node:
$ rosrun turtlesim turtlesim_node
$ rosrun [package_name] [node_name]```
現(xiàn)在我們用***Remapping Argument***來改變**node**的名字:
$ rosrun turtlesim turtlesim_node __name:=my_turtle ```
理解ROS Topics
用人rqt_graph來觀察正在運(yùn)行的節(jié)點(diǎn)和話題之間的聯(lián)系:
$ rqt_graph```
######rostopic 用來獲取關(guān)于topic的信息:
rostopic echo shows the data published on a topic.
$ rostopic echo [topic]```
理解ROS Messages
使話題的交流是因?yàn)閮蓚€(gè)節(jié)點(diǎn)之間傳送messages动猬,發(fā)布者和訂閱者需要使用同類型的messages。這說明一個(gè)topic的type 是由它上面發(fā)布的message的type決定表箭。 在一個(gè)話題上發(fā)布的message類型可以由rostopic type決定赁咙。
$ rostopic pub -1 /turtle1/cmd_vel
使用rostopic pub
使用方法:
rostopic pub [topic] [msg_type] [args]```
實(shí)例:
$ rostopic pub -1 /turtle1/cmd_vel geometry_msgs/Twist -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, 1.8]'```
分部解析上述命令的意義:
- This command will publish messages to a given topic:
rostopic pub```
- This option (dash-one) causes rostopic to only publish one message then exit:
-1```
- This is the name of the topic to publish to:
/turtle1/cmd_vel```
- This is the message type to use when publishing to the topic:
geometry_msgs/Twist```
- This option (double-dash) tells the option parser that none of the following arguments is an option. This is required in cases where your arguments have a leading dash-, like negative numbers.
--```
你可能看到小烏龜運(yùn)動一下后就停止了,那是因?yàn)樗枰?Hz頻率的連續(xù)的命令流來維持他的運(yùn)動免钻,所以我們用**rostopic pub -r** 來發(fā)布一個(gè)連續(xù)的命令:
$ rostopic pub /turtle1/cmd_vel geometry_msgs/Twist -r 1 -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, -1.8]'```
現(xiàn)在我們來看在rqt_graph中發(fā)生了什么彼水,The rostopic pub node (here in red) is communicating with the rostopic echo node (here in green):
筆記添加:
命令rostopic type [topic_name]返回在話題上發(fā)布的消息的類型,rosmsg show [message_type]返回消息的詳細(xì)信息极舔,這兩條命令與rostopic type [topic_name] | rosmsg show 等價(jià)凤覆,即以下命令返回結(jié)果相同:
$ rostopic type /turtle1/cmd_vel
rosmsg show geometry_msgs/Twist
$ rostopic type /turtle1/cmd_vel | rosmsg show```
.