浏览ROS 文件系统
- 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...
文件系统(Filesystem)的工具
**rospack find **返回 package的路径:
$ rospack find [package_name]```
返回:
YOUR_INSTALL_PATH/share/roscpp```
roscd直接改变目录,跳转到package或者stacks。
$ roscd [locationname[/subdir]]```
返回:
YOUR_INSTALL_PATH/share/roscpp```
用 Unix command pwd打印出工作目录:
$ pwd```
<small>
上述两条命令返回结果相同,注意:
*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>
* * *
####创建一个*ROS package*
一个package如果被看作为**catkin package**,需要符合以下几个条件:
1. 这个包必须含有一个**catkin compliant package.xml** 文件,
- 这个**package.xml**文件提供关于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]```
现在我们用***Remapping Argument***来改变**node**的名字:
$ rosrun turtlesim turtlesim_node __name:=my_turtle ```
理解ROS Topics
用人rqt_graph来观察正在运行的节点和话题之间的联系:
$ rqt_graph```
######rostopic 用来获取关于topic的信息:
rostopic echo shows the data published on a topic.
$ rostopic echo [topic]```
理解ROS Messages
使话题的交流是因为两个节点之间传送messages,发布者和订阅者需要使用同类型的messages。这说明一个topic的type 是由它上面发布的message的type决定。 在一个话题上发布的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频率的连续的命令流来维持他的运动,所以我们用**rostopic pub -r** 来发布一个连续的命令:
$ rostopic pub /turtle1/cmd_vel geometry_msgs/Twist -r 1 -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, -1.8]'```
现在我们来看在rqt_graph中发生了什么,The rostopic pub node (here in red) is communicating with the rostopic echo node (here in green):
笔记添加:
命令rostopic type [topic_name]返回在话题上发布的消息的类型,rosmsg show [message_type]返回消息的详细信息,这两条命令与rostopic type [topic_name] | rosmsg show 等价,即以下命令返回结果相同:
$ rostopic type /turtle1/cmd_vel
rosmsg show geometry_msgs/Twist
$ rostopic type /turtle1/cmd_vel | rosmsg show```
.