ROS 从入门到放弃 - 入门

ROS 从入门到放弃 - 入门

  • 1. Installing and Configuring Your ROS Environment
  • 2. Navigating the ROS Filesystem
    • Packages & Manifests:
    • 文件管理操作:
  • 3. Creating a ROS Package
    • 3.1 Package的组成:
    • 3.2 一个Worksapce的组成
    • 3.3 创建一个Package
      • package.xml中各tag的介绍:
  • 4. Building a ROS Package
  • 5. Understanding ROS Nodes
    • 5.1 Quick Overview of Graph Concepts:
    • 5.2 详细介绍Node:
    • 5.3 roscore
    • 5.4 rosnode
    • 5.5 rosrun
  • 6. Understanding ROS Topics
    • 6.0 准备工作:
    • 6.1 ROS Topic:
      • 6.1.1 Using rqt_graph:
      • 6.1.2 rostopic: 用于咨询Topic
      • 6.1.3 Using rqt_plot:
      • 6.1.4 rosmsg: ROS Messages
  • 7. Understanding ROS Services and Parameters
    • 7.1 rosservice
    • 7.2 rosparam
  • 8. Using rqt_console and roslaunch
    • 8.0 准备工作
    • 8.1 rqt_console & rqt_logger_level
    • 8.2 roslaunch:
      • 创建launch文件的步骤:
  • 9. Using rosed to edit files in ROS
  • 10. Creating a ROS msg and srv
    • 10.1 Introduction to msg and srv
      • msg
      • srv
    • 10.2 Using msg
      • 定义一条msg
      • rosmsg:
    • 10.3 Using srv
      • roscp
      • 定义一个srv
      • rossrv
    • 10.4 创建msg和srv的共同步骤
  • 11. Writing a Simple Publisher and Subscriber (Python)
    • 11.0 Node的定义
    • 11.1 创建一个Publisher Node
    • 11.2 创建一个Subscriber Node
  • 12. Examining the Simple Publisher and Subscriber
  • 15. Writing a Simple Service and Client (Python)
    • 15.1 创建一个Service Node
    • 15.2 创建一个Client Node
  • 16. Examining the Simple Service and Client
  • 17. Recording and playing back data
    • 17.1 创建一个.bag文件 [记录数据]
    • 17.2 检查与播放bag文件
    • 17.3 Recording a subset of the data
    • 17.4 The limitations of rosbag record/play
  • 18. Reading messages from a bag file
    • 18.1 播放消息并在多个终端中查看输出
    • 18.2 ros_readbagfile script
    • 18.3 为什么rostopic echo -b 不好?
  • 19. Getting started with roswtf
    • 19.1 检查安装
    • 19.2 Trying it online
    • 19.3 Errors
  • 20. Navigating the ROS wiki
  • 21. Where Next?
    • 21.1 Launching a Simulator
    • 21.2 RViz
    • 21.3 Understanding TF
    • 21.4 Going Deeper
  • 最后:
      • 再见
  • 附录:Terminal的命令合集:


本教程参考

  • ROS官方教程
  • ROS安装

本教程针对Python。


1. Installing and Configuring Your ROS Environment

  1. 创建工作空间(Work Space):
$ mkdir -p ~/catkin_ws/src
$ cd ~/catkin_ws/
$ catkin_make

如果需要在ROS Melodic及之前的版本中运用Python3,则需要
catkin_make -DPYTHON_EXECUTABLE=/usr/bin/python3

  1. 在工作空间的位置(如/home/frank/catkin_ws)下添加环境变量:
source devel/setup.bash
此操作等价于
. ~/catkin_ws/devel/setup.bash

之后可以通过echo $ROS_PACKAGE_PATH查看当前环境变量:

之前:
/home/frank/tutorial_ws/src:/opt/ros/kinetic/share
之后:
/home/frank/catkin_ws/src:/home/frank/tutorial_ws/src:/opt/ros/kinetic/share
  • each path separated by a colon ‘:’
    source环境变量的作用:Sourcing any of these files will overlay this workspace on top of your environment.

2. Navigating the ROS Filesystem

本节需要预先导入材料:
sudo apt-get install ros--ros-tutorials

Packages & Manifests:

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…

文件管理操作:

  1. rospack find [package_name]: 查找某个包的位置
    注意:will only find ROS packages that are within the directories listed in your ROS_PACKAGE_PATH.
  2. rospack depends1 rospy[pkgname]: 查看某个包的依赖项,注意要在环境中添加当前的ws
    • rospack depends [pkgname]找pkg的所有依赖,如我们定义时可能只写了依赖rospy,但此时会把rospy需要的包都显示出来
    • rospack depends1 pkg名字:First-order dependencies,直接需要的包
  3. roscd [locationname[/subdir]]: 移动到一个包的位置
    roscd roscpp/cmake:可以移动到roscpp下的camke文件夹。
    roscd log: 只有运行ROS程序才可以去到程序存储log文件的地方,否则会报错。

可以通过echo $ROS_PACKAGE_PATH来查看环境变量ROS_PACKAGE_PATH,如果我们的Worksapce不在里面,需要用1.2中的方法添加环境变量。
4. rosls [pkgname]

3. Creating a ROS Package

3.1 Package的组成:

  • 一定要包含的文件:
    • package.xml: provides meta information about the package.
    • CMakeLists.txt: which uses catkin.
  • 其他:
    • If it is a catkin metapackage it must have the relevant boilerplate CMakeLists.txt file.
    • Each package must have its own folder: This means no nested packages nor multiple packages sharing the same directory.

3.2 一个Worksapce的组成

例如一个Workspace(WS)的目录:

workspace_folder/        -- WORKSPACE
  src/                   -- SOURCE SPACE
    CMakeLists.txt       -- 'Toplevel' CMake file, provided by catkin
    package_1/
      CMakeLists.txt     -- CMakeLists.txt file for package_1
      package.xml        -- Package manifest for package_1
    ...
    package_n/
      CMakeLists.txt     -- CMakeLists.txt file for package_n
      package.xml        -- Package manifest for package_n

3.3 创建一个Package

  1. 在src中文件目录下使用:
    catkin_create_pkg [depend1] [depend2] [depend3]
    后面的depend是它依赖的包,如下面的命令创建了一个依赖std_msgs, roscpp和rospy名为beginner_tutorials的包:

    catkin_create_pkg beginner_tutorials std_msgs rospy roscpp

    Rq:

    • 运行完后会在src文件夹里出现一个’beginner_tutorials’的文件夹
    • 因为之前source过,也可以用rosls beginner_tutorials来显示内部内容
    • 一般pkg的名字只用小写。
  2. 创建完pkg之后,要回到ws的进行catkin_make:

    $ cd ~/catkin_ws
    $ catkin_make
    
  3. 再source一下:
    . ~/catkin_ws/devel/setup.bash

    Rq:
    rospack depends: 找各种包的Dependencies
    rospack depends1 pkg名字:First-order dependencies,直接需要的包

    可以用对应的pkg中的package.xml来验证:

    <package format="2">
    ...
      <buildtool_depend>catkinbuildtool_depend>
      <build_depend>roscppbuild_depend>
      <build_depend>rospybuild_depend>
      <build_depend>std_msgsbuild_depend>
    ...
    package>
    
  4. 查看各个由catkin_create_pkg生成的文件:

package.xml中各tag的介绍:

  1. The beginner_tutorials package:描述pkg按照惯例,第一句话应该简短,但要涵盖整个包装范围。
  2. user:维护者的tag
  3. TODO:版权协议。常见的为BSD。
  4. roscpp:pkg的依赖
    • The dependencies are split into build_depend, buildtool_depend, exec_depend, test_depend

4. Building a ROS Package

确认已经source:$ source /opt/ros/kinetic/setup.bash

  1. catkin_make: 用于build放在src中的文件。
  2. Build之后ws的情况:出现3个文件夹。
    • src
    • devel: The devel folder is the default location of the devel space, which is where your executables and libraries go before you install your packages.
    • build: The build folder is the default location of the build space and is where cmake and make are called to configure and build your packages.

5. Understanding ROS Nodes

5.1 Quick Overview of Graph Concepts:

  • Nodes: A node is an executable that uses ROS to communicate with other nodes.
  • Messages: ROS data type used when subscribing or publishing to a topic.
  • Topics: Nodes can publish messages to a topic as well as subscribe to a topic to receive messages.
  • Master: Name service for ROS (i.e. helps nodes find each other)
  • rosout: ROS equivalent of stdout/stderr
  • roscore: Master + rosout + parameter server (parameter server will be introduced later)

5.2 详细介绍Node:

  • 功能:
    Nodes can publish or subscribe to a Topic. Nodes can also provide or use a Service.
  • Client Libraries:
    ROS client libraries允许Node可以用其他变成语言编写。
    • rospy = python client library
    • roscpp = c++ client library

5.3 roscore

  • The first thing you should run when using ROS.

5.4 rosnode

  • rosnode list:查看当前运行的node。
  • rosnode info /rosout:查看/rosout这个node的info格式。

5.5 rosrun

  • rosrun [package_name] [node_name]:运行某一个pkg的node
    • EX:$ rosrun turtlesim turtlesim_node,此时的rosnode list为:
    /rosout
    /turtlesim
    
  • rosrun turtlesim turtlesim_node __name:=my_turtle: 更改node的名字,此时的rosnode list为:
    /my_turtle
    /rosout
    
    • rosnode ping my_turtle:测试node是否正常工作。

6. Understanding ROS Topics

6.0 准备工作:

  • Ter1:rosrun turtlesim turtlesim_node
  • Ter2:rosrun turtlesim turtle_teleop_key 遥控乌龟
  • 基本原理:
    • 两个node通过一个topic进行互相沟通。
    • turtle_teleop_key/turtle1/command_velocity–>turtlesim_node
    • 实际上各个node的名字(因为我们可以改名字)为:
      /teleop_turtle/turtle1/command_velocity–>/turtlesim
      前者发消息给topic/turtle1/command_velocity/turtlesim来接受信息。

6.1 ROS Topic:

6.1.1 Using rqt_graph:

  • 安装:distro==kinetic
  $ sudo apt-get install ros--rqt
  $ sudo apt-get install ros--rqt-common-plugins
  • 使用:rosrun rqt_graph rqt_graph

6.1.2 rostopic: 用于咨询Topic

  • rostopic bw: display bandwidth used by topic

  • rostopic echo [topic]:显示published到一个topic上的信息
    rostopic echo /turtle1/cmd_vel

  • rostopic list [/topic]

    • 显示当前运行的所有的topic的名字:rostopic list
    • 列出每个Topic的Sub和Pub数量:rostopic list -v
    • 列出有Sub的Topic的名字:rostopic list -s
    • 列出有Pub的Topic的名字:rostopic list -p
  • rostopic type [topic]: 显示某个topic接受的消息(topic的消息类型由publiser发布的消息类型决定)
    rostopic type /turtle1/cmd_vel

  • rostopic pub [topic] [msg_type] [args]: 向某个Topic发布消息

    • 单次执行发送:
      rostopic pub -1 /turtle1/cmd_vel geometry_msgs/Twist -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, 1.8]'
      其中-1表示单次执行,发送一次消息之后就退出了,后面的是YAML格式的消息。
    • 以一定频率发送信息:
      rostopic pub /turtle1/cmd_vel geometry_msgs/Twist -r 1 -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, -1.8]'
      以1HZ的频率发布信息
  • rostopic hz [topic]:显示消息的发送频率
    例如我们可以检验上面的是否真的是以1hz的频率发布消息到/turtle1/cmd_vel,结果中的average rate的单位是hz。

    $ rostopic hz /turtle1/cmd_vel
    average rate: 1.000 min: 1.000s max: 1.000s std dev: 0.00000s window: 2
    

6.1.3 Using rqt_plot:

rosrun rqt_plot rqt_plot

6.1.4 rosmsg: ROS Messages

Topic通讯实现方式是通过不同node间相互发送ROS消息来实现的。Sub和Pub的消息类型必须相同。topic的消息类型由publiser发布的消息类型决定。

  • rostopic type [topic]:查询消息类型。
  • rosmsg show geometry_msgs/Twist:查看某个消息类型的定义:
    • $ rostopic type /turtle1/cmd_vel | rosmsg show
    • 顺势将一个topic的消息类型的定义查出,他只是把查询到的type(geometry_msgs/Twist)放在了show后面用于查询最底层定义。

7. Understanding ROS Services and Parameters

除了通过Topic之外,另一种Node之间相互通信的办法,

你可能感兴趣的:(ROS,python)