ROS Service

rosservice

Services are another way that nodes can communicate with each other. Services allow nodes to send a request and receive a response.

rosservice list         print information about active services
rosservice call         call the service with the provided args
rosservice type         print service type
rosservice find         find services by service type
rosservice uri          print service ROSRPC uri

rosparam

rosparam set            set parameter
rosparam get            get parameter
rosparam load           load parameters from file
rosparam dump           dump parameters to file
rosparam delete         delete parameter
rosparam list           list parameter names

使用rqt_console和roslaunch

rqt_console

rosrun rqt_console rqt_console # 查看日志
rosrun rqt_logger_level rqt_logger_level # 设置日志等级,来源

roslaunch

自定义xml文件,使一只小海龟模仿另一只。

roslaunch [package] [filename.launch]

ROS ed

rosed

# rosed [package_name] [filename]
rosed roscpp Logger.msg

使用echo $EDITOR查看当前的编辑器(为空说明使用了默认的vim

可使用export EDITOR='nano -w'之类的方式修改编辑器(永久修改的话最好把这行加入.bashrc

创建ROS msg和srv文件

  • msg: msg files are simple text files that describe the fields of a ROS message. They are used to generate source code for messages in different languages.
  • srv: an srv file describes a service. It is composed of two parts: a request and a response.

msgs are just simple text files with a field type and field name per line. The field types you can use are:

  • int8, int16, int32, int64 (plus uint*)
  • float32, float64
  • string
  • time, duration
  • other msg files
  • variable-length array[] and fixed-length array[C]

srv files are just like msg files, except they contain two parts: a request and a response. The two parts are separated by a ‘—‘ line. Here is an example of a srv file:

int64 A
int64 B
---
int64 Sum

创建msg文件

  1. 在package目录下建立msg文件夹,向该文件夹写入一个.msg文件。

  2. 回到package目录下,修改package.xml文件

    <build_depend>message_generation</build_depend>
    <exec_depend>message_runtime</exec_depend>
  3. 修改CMakeLists.txt

    1. find_package中添加message_generation
    2. catkin_packageCATKIN_DEPENDS后添加message_runtime
    3. 取消add_message_files的注释,并向其中添加之前写的.msg文件
    4. 取消generate_messages的注释
  4. 查看msg文件,使用rosmsg show如果文件格式没问题,会显示出定义的数据

rosmsg

rosmsg show     Show message description
rosmsg list     List all messages
rosmsg md5      Display message md5sum
rosmsg package  List messages in a package
rosmsg packages List packages that contain messages

创建srv文件

  1. 在package下建立srv文件夹
  2. 使用roscp从其他地方复制个写好的.srv文件过来(肯定也能自己写拉)
  3. 创建msg文件 ,要确保package.xmlCMakeLists.txt中有相应的内容
  4. CMakeLists.txt中,取消add_service_files的注释,并向其中添加之前写的.srv文件

roscp

$ roscp [package_name] [file_to_copy_path] [copy_path]

rossrv

rossrv show <service type>

生成msg和srv文件

  1. 切换到package目录的上两层(就是workspace所在的目录,这里是~/catkin_ws
  2. catkin build或者catkin_make
  3. 文件生成好了,具体放在哪见下方参考

Any .msg file in the msg directory will generate code for use in all supported languages. 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/.

Similarly, any .srv files in the srv directory will have generated code in supported languages. For C++, this will generate header files in the same directory as the message header files. For Python and Lisp, there will be an ‘srv’ folder beside the ‘msg’ folders.

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