Skip to content

Instantly share code, notes, and snippets.

@Wonicon
Last active August 29, 2015 14:16
Show Gist options
  • Save Wonicon/15cc8ef909397b8151a7 to your computer and use it in GitHub Desktop.
Save Wonicon/15cc8ef909397b8151a7 to your computer and use it in GitHub Desktop.
ROS笔记

##创建msg

###msg是什么

msg是一个普通的文本文件,描述了一个消息的数据成员(数据结构),它将作为原型去生成各种编程语言能够使用的数据类型。

###Creating a msg

Firstly, we need a msg folder with a filename.msg file under the package folder.

Then, write the msg file with the format per line.

Then, open package.xml, and make sure these two lines are in it and uncommented:

  <build_depend>message_generation</build_depend>
  <run_depend>message_runtime</run_depend>

And in CMakeLists.txt, check the content below:

# Do not just add this to your CMakeLists.txt, 
# modify the existing text to add message_generation before the closing parenthesis
find_package(catkin REQUIRED COMPONENTS
   roscpp
   rospy
   std_msgs
   message_generation
)

catkin_package(
  ...
  CATKIN_DEPENDS message_runtime ...
  ...)

add_message_files(
  FILES
  yours.msg
)

##创建srv$ rosmsg sh $ rosmsg sh ###srv是什么

同msg一样,srv是用来描述service的纯文本和原型描述;特别地,它需要描述请求和响应两个部分。

###Creating a srv

Create .srv file in package_path/srv/your.srv

Check the content in package.xml:

  <build_depend>message_generation</build_depend>
  <run_depend>message_runtime</run_depend>

and check these content 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
)

add_service_files(
  FILES
  your.srv
)

Similar to msg, use `rossrv show <srvname>` to check it.

##topic

topic的主命令是rostopic,其子命令有:

  1. bw - 输出topic使用的带宽

  2. echo - 输出topic的msg内容

  3. hz - 输出topic发布msg的频率

  4. list - 输出所有活动的topic

  5. pub - 手动发送msg给topic

  6. type - 输出topic的msg类型名称

输出msg具体的数据结构使用:

$ rosmsg show `rostopic type [topic]`

rostopic pub的一些参数:

  1. -1 这个msg只发布一次
  2. -r 1 以频率(rate)1Hz发布msg
  3. -- 在double-dash之后的字符串都不被认为是option,用于输入msg

##service

options:

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

##parameter

主要设置和修改一些背景参数:

$ rosparam 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_graph来观察node之间的msg和topic:

$ rosrun rqt_graph rqt_graph

使用rqt_plot来观察msg数据的时间变化:

$ rosrun rqt_plot rqt_plot

##其他

###roslaunch

roslaunch可以一步启动多个包:

$ roslaunch [package] [filename.launch]

首先需要在workspace下准备launch文件夹,在launch文件夹内创建filename.launch文件,内容为xml,样例如下:

# start tag
<launch>
# ns = namespace
  <group ns="turtlesim1">
    <node pkg="turtlesim" name="sim" type="turtlesim_node"/>
  </group>
  # 两个相同的node放在不同的namespace下,不会冲突
  <group ns="turtlesim2">
    <node pkg="turtlesim" name="sim" type="turtlesim_node"/>
  </group>
  <node pkg="turtlesim" name="mimic" type="mimic">
  # 还需理解
    <remap from="input" to="turtlesim1/turtle1"/>
    <remap from="output" to="turtlesim2/turtle1"/>
  </node>
</launch>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment