ROS 命令以及相关内容学习(一)

1.安装:按照官网APT 安装、

2.配置环境变量.

3.创建工作空间

1 mkdir -p ~/catkin_ws/src
2 cd ~/catkin_ws
3 catkin_init_workspace
4 catkin_make

4.创建RoS中的一个package

1 cd ~/catkin_ws/src
2 catkin_create_pkg test std_msgs rospy roscpp  #后面三个 是所依赖的东西 catkin_create_pkg <package_name> [depend1] [depend2] [depend3]
3 catkin_make --pkg test 4 source ~/.bashrc 
5 vi~/.bashrc
6 source /XXX .bash # add 环境变量
7 rospack depends1 <> #查看一个包有什么依赖
8 rospack depend <> #查看所有的 依赖
9 cat XXX #看这个文件里面的内容 不做任何修改

package 介绍:

package 中必须包含两个文件中:. xlm  提供包的mata元信息,这个东西是很重要的,他包含了这个包中的依赖,如果这些依赖  电脑找不到,或者没有,那么这个包是不能运行的,也就是你跑不了程序哦。 里面提供了 这个包的作者以及邮箱。这个包的许可,这个包的所依项。build_dependbuildtool_dependrun_dependtest_depend.   其中依赖项中有这四种,具体什么功效可以去这个网址看  http://wiki.ros.org/catkin/package.xml#Build.2C_Run.2C_and_Test_Dependencies  

   1 <?xml version="1.0"?>
   2 <package>
   3   <name>beginner_tutorials</name>
   4   <version>0.1.0</version>
   5   <description>The beginner_tutorials package</description>
   6 
   7   <maintainer email="you@yourdomain.tld">Your Name</maintainer>
   8   <license>BSD</license>
   9   <url type="website">http://wiki.ros.org/beginner_tutorials</url>
  10   <author email="you@yourdomain.tld">Jane Doe</author>
  11 
  12   <buildtool_depend>catkin</buildtool_depend>
  13 
  14   <build_depend>roscpp</build_depend>
  15   <build_depend>rospy</build_depend>
  16   <build_depend>std_msgs</build_depend>
  17 
  18   <run_depend>roscpp</run_depend>
  19   <run_depend>rospy</run_depend>
  20   <run_depend>std_msgs</run_depend>
  21 
  22 </package>

上面介绍完毕下.xmL 文件,下面介绍以下cmake 文件。可以理解成电脑中各个部分的穿针引线的作用,在一个目录下首先告诉你这个包怎么安装,怎么编译,用到什么依赖项。并且他还把其他的cmake 文件联系起来。一个cmake 文件必须包含其他几项。  详情请看http://wiki.ros.org/catkin/CMakeLists.txt

  1. Required CMake Version (cmake_minimum_required

  2. Package Name (project()

  3. Find other CMake/Catkin packages needed for build (find_package())      #如果现在创建的包依赖于其他的包,为何能找到其他的包呢?思考以下把?

  4. Message/Service/Action Generators (add_message_files(), add_service_files(), add_action_files()

  5. Invoke message/service/action generation (generate_messages()

  6. Specify package build info export (catkin_package()) #

  7. Libraries/Executables to build (add_library()/add_executable()/target_link_libraries()

  8. Tests to build (catkin_add_gtest()

  9. Install rules (install())  

 

 

4.1可以自己修改 .xml文件。

可以查看 http://wiki.ros.org/ROS/Tutorials/CreatingPackage

 

5.如果一个项目包含多个ROS包,创建方法如下:

1 cd ~/catkin_ws/src
2 mkdir projectxx
3 cd projectxx
4 catkin_create_pkg subproj1 std_msgs rospy roscpp
5 catkin_create_pkg subproj2 std_msgs rospy roscpp
6 catkin_create_pkg subproj3 std_msgs rospy roscpp
7 ..

 6.ros中包的查找 以及查看包。

1 rospack list   # 显示所有的ros 里面的包
2 rospack find <>  +# <>内为你要找的包的名字
3 roscd <>  
4 pwd 
5 rosls
6 ROS_PACKAGE_PATH # 查看与ros 相关的所有的包

7.node 

,节点包含可执行文件,但又不仅仅是可执行文件。节点之间可以相互发布或者订阅topic 其中topic 的数据类型是由messgae决定的,

  • roscore = ros+core : master (provides name service for ROS) + rosout (stdout/stderr) + parameter server (parameter server will be introduced later) 
  • rosnode = ros+node : ROS tool to get information about a node. 
  • rosrun = ros+run : runs a node from a given package. 

roscore 是一个巨大的boss ,俗称master他管理一切node  所以你每次运行node  都要在roscore 下运运行。我发现一个情况,当roscore 运行的时候,有一个节点在运行rosout,,rosout 是roscore的一部分,

1 roscore  #打开 master
2 rosnode #这个可以查看 rosnode 有什么命令,然后rosnode list 可以查看运行的节点。
3 rosnode info /name #这是查看具体node 的信息,你会发现

Publications: 
* /rosout_agg [rosgraph_msgs/Log]

Subscriptions: 
* /rosout [unknown type]

Services: 
* /rosout/set_logger_level
* /rosout/get_loggers


contacting node http://localhost:43111/ ...
Pid: 10782

这些东西是非常有意义的

  4  rosrun [package_name] [node_name]  #运行包下的文件 的节点。

运行

  
rosrun rqt_graph rqt_graph   红色的是topic  其他颜色的自己推测。

可以查看运行节点之间的关系是什么样子的。消息是则呢吗传递的。

下面以一个例子具体来看这些东西有什么作用
rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key

 

8 .topic

这是关于 topic 的一些命令。 顺便熟悉一下 -h的 help 命令

rostopic -h

rostopic bw     display bandwidth used by topic
rostopic echo   print messages to screen
rostopic hz     display publishing rate of topic    
rostopic list   print information about active topics
rostopic pub    publish data to topic
rostopic type   print topic type

rostopic list -h

Usage: rostopic list [/topic]

Options:
  -h, --help            show this help message and exit
  -b BAGFILE, --bag=BAGFILE
                        list topics in .bag file
  -v, --verbose         list full details about each topic
  -p                    list only publishers
  -s                    list only subscribers

9.message

嘛。message 就是信息么。node之间的topic 交流,topic 的底层是message

topic Communication on topics happens by sending ROS messages between nodes. For the publisher (turtle_teleop_key) and subscriber (turtlesim_node) to communicate, the publisher and subscriber must send and receive the same type of message. This means that a topic type is defined by the message type published on it. The type of the message sent on a topic can be determined using rostopic type

你可以用以下命令来 观看message 的相关信息

 1 rostopic type [topic]  #查看topic 的类型
 2 rostopic type /turtle1/cmd_vel   
 3 geometry_msgs/Twist
 4 
 5 
 6 rosmsg show geometry_msgs/Twist  查看msg 的具体内容。
 7 geometry_msgs/Vector3 linear
 8   float64 x
 9   float64 y
10   float64 z
11 geometry_msgs/Vector3 angular
12   float64 x
13   float64 y
14   float64 z

   9.1用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]'
你会看见小乌龟 转了一个四分之一园,-1的意思就是(dash-one)仅仅发一条信息然后结束
然后你还可以用下面这条命另,让小乌龟不停的转圈。

rostopic pub /turtle1/cmd_vel geometry_msgs/Twist -r 1 -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, -1.8]'
你还可以用下面这条命令查看这个消息发送的rate。

rostopic hz /turtle1/pose



posted @ 2016-11-20 14:15  小萝、卜  阅读(939)  评论(0编辑  收藏  举报