ROS Tutorials(2)

瀏覽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)建一個*ROS package*
一個package如果被看作為**catkin package**,需要符合以下幾個條件:
1. 這個包必須含有一個**catkin compliant package.xml** 文件,
    - 這個**package.xml**文件提供關(guān)于package的信息。
2. 這個包必須含有一個 **CMakeLists.txt** 用來**catkin**,它是一個catkin metapackage。
3. 在一個文件中至多只有一個package:
    - 這說明,在同一個目錄下不能嵌套package或者有多個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
    打開終端后首先運行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來觀察正在運行的節(jié)點和話題之間的聯(lián)系:

$ rqt_graph```
######rostopic 用來獲取關(guān)于topic的信息:
rostopic echo shows the data published on a topic. 

$ rostopic echo [topic]```

理解ROS Messages

使話題的交流是因為兩個節(jié)點之間傳送messages,發(fā)布者和訂閱者需要使用同類型的messages。這說明一個topictype 是由它上面發(fā)布的messagetype決定。 在一個話題上發(fā)布的message類型可以由rostopic type決定。
$ rostopic pub -1 /turtle1/cmd_vel

使用rostopic pub

使用方法:

rostopic pub [topic] [msg_type] [args]```
實例:

$ 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.
--```
你可能看到小烏龜運動一下后就停止了,那是因為他需要1Hz頻率的連續(xù)的命令流來維持他的運動,所以我們用**rostopic pub -r** 來發(fā)布一個連續(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):

rqt_graph.png
筆記添加:

命令rostopic type [topic_name]返回在話題上發(fā)布的消息的類型,rosmsg show [message_type]返回消息的詳細(xì)信息,這兩條命令與rostopic type [topic_name] | rosmsg show 等價,即以下命令返回結(jié)果相同:

$ rostopic type  /turtle1/cmd_vel
rosmsg show geometry_msgs/Twist

$ rostopic type /turtle1/cmd_vel | rosmsg show```

.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容