ROS学习手记 - 7 创建ROS msg & srv

原创 2015年07月10日 14:02:47


至此,我们初步学习了ROS的基本工具,接下来一步步理解ROS的各个工作部件的创建和工作原理。

本文的详细文档:http://wenku.baidu.com/view/623f41b3376baf1ffd4fad7a

  1. Creating a ROS msg and srv

    This tutorial covers how to create and build msg and srv files as well as therosmsg, rossrv and roscp commandline tools.

1. msg & srv 文件介绍
    msg 文件 就是用来让不同语言能产生message的一个指导性文本文件。
    srv file describes a service. It is composed of two parts: a request and a response.

2. msg & srv 文件存储位置:
    <workspace>/packagename/msg/
    &
    <workspace>/packagename/srv/
   
==== msg file 说明 ====
3. msgfile 的格式和生成
    生成:
         $ cd ~/catkin_ws/src/beginner_tutorials
         $ mkdir msg
         $ echo "int64 num" > msg/Num.msg

    格式:
         string first_name
         string last_name
         uint8 age
         uint32 score

4. msgfile 添加到package.xml的dependency中
      <build_depend>message_generation</build_depend>
      <run_depend>message_runtime</run_depend>

5. 对CMakeLists.txt文件的修改:

  5.1 添加message_generation dependency到CMakeLists.txt中:
      message_generation before the closing parenthesis
        find_package(catkin REQUIRED COMPONENTS
        roscpp
        rospy
        std_msgs
        message_generation  // add ’message_generation’
        )

  5.2 export the message runtime dependency.
      catkin_package(
      ...
      CATKIN_DEPENDS message_runtime ...
      ...)

  5.3 添加msg文件
      add_message_files(
      FILES
      Num.msg
      )
    添加了.msg文件在CMake里,我们保证在你添加其他.msg文件时,CMake知道何时它需要reconfigure重新配置项目。

  5.4 确保generate_messages 函数被调用
      generate_messages(
      DEPENDENCIES
      std_msgs
      )

6. rosmsg 工具的使用
    make sure that ROS can see it using the rosmsg show command.
    Usage:
      $ rosmsg show [message type]
    Example:
      $ rosmsg show beginner_tutorials/Num
      $ rosmsg show Num
===================
      === srv file 说明 ===
 1. srv的路径和生成
      $ roscd beginner_tutorials
      $ mkdir srv
    Instead of creating a new srv definition by hand, we will copy an existing one from another package.
For that, roscp is a useful commandline tool for copying files from one package to another.
    使用roscp工具从一个package拷贝文件到另一个。
    Usage:
      $ roscp [package_name] [file_to_copy_path] [copy_path]
    Now we can copy a service from the rospy_tutorials package:
      $ roscp rospy_tutorials AddTwoInts.srv srv/AddTwoInts.srv

 2. 保证package.xml里有dependency配置(可能独立修改了srv,确保一下)
      <build_depend>message_generation</build_depend>
      <run_depend>message_runtime</run_depend>

 3.1 add the message_generation dependency to generate messages in CMakeLists.txt:
# Do not just add this line to your CMakeLists.txt, modify the existing line
       find_package(catkin REQUIRED COMPONENTS
         roscpp
         rospy
         std_msgs
         message_generation
       )

  3.2 添加 srvice 文件
    add_service_files(
      FILES
      AddTwoInts.srv
    )

  3.3 确保generate_messages 函数被调用
      generate_messages(
      DEPENDENCIES
      std_msgs
      )

4. 使用rossrv工具
    添加以后,确保ROS can see it using the rossrv show command.
    Usage:
    $ rossrv show <service type>
    Example:
    $ rossrv show beginner_tutorials/AddTwoInts
    You will see:
    int64 a
    int64 b
    ---
    int64 sum
    Similar to rosmsg, you can find service files like this without specifying package name:
    $ rossrv show AddTwoInts
    [beginner_tutorials/AddTwoInts]:
    int64 a
    int64 b
    ---
    int64 sum

    [rospy_tutorials/AddTwoInts]:
    int64 a
    int64 b
    ---
    int64 sum

无论是修改了msg还是srv,都需要做的步骤:

  CMakeLists.txt文件的修改
  1.
        find_package(catkin REQUIRED COMPONENTS
        roscpp
        rospy
        std_msgs
        message_generation  // add ’message_generation’
        )

  2. add any packages you depend on which contain .msg files that your messages use (in this case std_msgs), such that it looks like this:
        generate_messages(
          DEPENDENCIES
          std_msgs
        )

终于到了catkin_make出手的时候:

Now that we have made some new messages we need to make our package again:

# In your catkin workspace (by default:~/catkin_ws$)

$ cd ../..
$ catkin_make
$ cd -

至此,我们就编译完成了一套ROS 的 msg & srv
Any .msg file in the msg directory will generate code for use in all supportedlanguages.
The C++ message header file will be generated in ~/catkin_ws/devel/include/beginner_tutorials/.
The Python script will be created in ~/catkin_ws/devel/lib/python2.7/dist-packages/beginner_tutorials/msg.
The lisp file appears in ~/catkin_ws/devel/share/common-lisp/ros/beginner_tutorials/msg/.

The full specification for the message format is available at theMessage Description Language page.

Getting Help

We've seen quite a few ROS tools already. It can be difficult to keeptrack of what arguments each command requires. Luckily, most ROS tools providetheir own help.

Try:

$ rosmsg -h

You should see a list of different rosmsg subcommands.

Commands:

  •   rosmsgshow Show message description
  •   rosmsgusers  Find files that use message
  •   rosmsgmd5  Display message md5sum
  •   rosmsgpackage  List messages in a package
  •   rosmsgpackages List packages that contain messages

You can also get help for subcommands

$ rosmsg show -h

  • This shows the arguments that are needed for rosmsg show:

·       Usage: rosmsg show[options] <message type>

·        

·       Options:

·         -h, --help show this help message and exit
  -r, --raw   show raw message text, including comments

Review

Lets just list some of the commands we've used so far:

  • rospack = ros+pack(age) : provides information related to ROS packages
  • roscd = ros+cd : changes directory to a ROS package or stack
  • rosls = ros+ls : lists files in a ROS package
  • roscp = ros+cp : copies files from/to a ROS package
  • rosmsg = ros+msg : provides information related to ROS message definitions
  • rossrv = ros+srv : provides information related to ROS service definitions
  • catkin_make : makes (compiles) a ROS package
    • rosmake = ros+make : makes (compiles) a ROS package (if you're not using a catkin workspace)

Next Tutorial

Now that you've made a new ROS msg and srv, let's look at writing a simplepublisher and subscriber(python)(c++).




版权声明:sonictl原创文章,转载注明,否则读者享用不了后续服务,感谢!

相关文章推荐

ROS学习笔记八:创建ROS msg和srv

本节主要讲述了如何创建和建立ROS msg和srv,同时使用命令行工具rosmsg、rossrv和roscp。msg和srv简介 msg:描述ROS messages内容的简单text文件,它们用来生...

ros自定义动态消息发布(vector)

ros自定义动态消息发布(vector) msg 原本我要节点发布一张图片,并在在rviz上显示, 图片是一副背景图再加一些点. 如果在运算的主程序内,每次...

ros中创建msg和srv文件时,配置CMakeLists.txt文件问题

作为一个ROS菜鸟,在按照ros wiki上的教程一步一步的走的过程中,在自己配置msg文件时,遇到了编译的问题,分析问题,发现是package下的CMakeLists.txt文件配置出现问题,

ROS入门之主题和服务、msg和srv(C++)

本文主要是总结一下ROS节点、主题、服务的相关概念、简单的主题发布者和订阅者和简单的服务器端和客户端以及创建srv、msg文件。主要参考了以下文章:1、Wiki:> http://wiki.ros.o...

创建ROS的msg和srv

Creating a ROS msg and srv Introduction to msg and srv msg: msg files are simple text ...

机器人操作系统ROS Indigo 入门学习(11)——创建一个ROS msg和srv

这篇教程将涉及怎样创建和编译msg和srv文件,以及怎样使用命令行工具rosmsg,rossrv 和roscp.   1.1介绍msg和srv msg:msg文件是描叙ROS message字段...

7、创建ROS msg和srv

一、msg和srv介绍msg: msg文件使用简单的文本格式声明一个ROS message的各个域。仅需要创建一个msg文件,就可以使用它来生成不同语言的message定义代码。srv: srv文件则...

ROS的学习(十一)ROS的msg和srv

msg是一个描述ROS中消息的域的简单的文本文件,它用来为消息产生不同语言的源代码。      一个srv文件描述一个服务,它由两部分组成,请求和服务。      msg文件被存储在一个包的msg...

ROS Kinetic: msg & srv - A brief introduction

msg: msg files are simple text files that describe the fields of a ROS message. They are used to gen...

ROS自定义msg类型及使用

一、创建msg消息参考: CreatingMsgAndSrv 首先创建一个空的package单独存放msg类型(当然也可以在任意的package中自定义msg类型) 这里为便于说明,建立一个名为...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)