# 常用命令

## 配置

rosdep update

source ./devel/setup.bash

source /opt/ros/indigo/setup.bash

rospack list

catkin_makecatkin_make install

catkin_make

rospack depends1 beginner_tutorials

roscd beginner_tutorials

pwd

catkin_create_pkg package-name

roslaunch -v package-name launch-file-name

roslaunch -screen package-name launch-file-name

加入前缀， launch-prefix=“xetrm-e”
xterm -e rosrun package node

rosrun turtlesim turtlesim_node turtle1/pos:=tim<remap from="org-name"to "new-name">

## 操作

roscore

rosrun turtlesim turtlesim_node

## 调试

rosrun rqt_graph rqt_graph

roswtf

rqt_console

rosparam list

rosparam get param_name

rosparam set param_name



## ROS node

rosnode cleanup

rosnode info node-name

$rosrun rqt_plot rqt_plot ## ROS topic 查看消息类型 $ rostopic type /turtle1/cmd_vel

你应该会看到:geometry_msgs/Twist

rostopic pub topic [args]

rostopic echo [topic]

rostopic echo /turtle1/cmd_vel

rosrun rqt_tf_tree rqt_tf_tree

rostopic list -v

rostopic echo /first -n 1 --noarr 找到frame id

rostopic info topic-name

rostopic echo topic-name -n 1 --noarr

rostopic pub -r rate-in-hz topic-name message-type message content

$rostopic find /message_type: ## ROS messages 查看消息的详细情况 $ rosmsg show geometry_msgs/Twist

    geometry_msgs/Vector3 linear

float64 x

float64 y

float64 z

geometry_msgs/Vector3 angular

float64 x

float64 y

float64 z123456789101112131415123456789101112131415

$rosmsg list: This lists all message $ rosmsg package [package_name]: This lists messages in a package

## ROS services


rosservice list         输出可用服务的信息

rosservice call         调用带参数的服务

rosservice type         输出服务类型

rosservice find         依据类型寻找服务find services by service type

rosservice uri          输出服务的ROSRPC uri1234567891012345678910

## ROS bags

$rosbag record topic_name -o bag_name We can also record all topics using the -a argument. 播放 $ rosbag play [bag_name]: This will playback the existing bag file.

rosbag info NAME

rosbag play NAME

# 结构

## Structure

The following are abstracts of each graph’s concepts:

• Nodes: Nodes are the process that perform computation. Each ROS node is written

using ROS client libraries such as roscpp and rospy. Using client library APIs, we
can implement different types of communication methods in ROS nodes. In a robot,
there will be many nodes to perform different kinds of tasks. Using the ROS
communication methods, it can communicate with each other and exchange data.
One of the aims of ROS nodes is to build simple processes rather than a large process
with all functionality. Being a simple structure, ROS nodes are easy to debug too.
Master: The ROS Master provides name registration and lookup to the rest of the
nodes. Nodes will not be able to find each other, exchange messages, or invoke
services without a ROS Master. In a distributed system, we should run the master on
one computer, and other remote nodes can find each other by communicating with
this master.

• Parameter Server: The parameter server allows you to keep the data to be stored in

a central location. All nodes can access and modify these values. Parameter server is
a part of ROS Master

• Messages: Nodes communicate with each other using messages. Messages are

simply a data structure containing the typed field, which can hold a set of data and
that can be sent to another node. There are standard primitive types (integer, floating
point, Boolean, and so on) and these are supported by ROS messages. We can also
build our own message types using these standard types.

• Topics: Each message in ROS is transported using named buses called topics. When

a node sends a message through a topic, then we can say the node is publishing a
topic. When a node receives a message through a topic, then we can say that the node
is subscribing to a topic. The publishing node and subscribing node are not aware of
each other’s existence. We can even subscribe a topic that might not have any
publisher. In short, the production of information and consumption of it are
decoupled. Each topic has a unique name, and any node can access this topic and
send data through it as long as they have the right message type.

• Services: In some robot applications, a publish/subscribe model will not be enough if

it needs a request/response interaction. The publish/subscribe model is a kind of oneway
transport system and when we work with a distributed system, we might need a
request/response kind of interaction. ROS Services are used in these case. We can
define a service definition that contains two parts; one is for requests and the other is
for responses. Using ROS Services, we can write a server node and client node. The
server node provides the service under a name, and when the client node sends a
request message to this server, it will respond and send the result to the client. The
client might need to wait until the server responds. The ROS service interaction is
like a remote procedure call.

• Bags: Bags are a format for saving and playing back ROS message data. Bags are an

important mechanism for storing data, such as sensor data, which can be difficult to
collect but is necessary for developing and testing robot algorithms. Bags are very
useful features when we work with complex robot mechanisms.

# 文件系统

### Ros source list

/ect/apt/sources.list/ros-latest.lis

### Source Space

The source space contains the source code of catkin packages. This is where you can extract/checkout/clone source code for the packages you want to build. Each folder within the source space contains one or more catkin packages. This space should remain unchanged by configuring, building, or installing. The root of the source space contains a symbolic link to catkin’s boiler-plate ‘toplevel’ CMakeLists.txt file. This file is invoked by CMake during the configuration of the catkin projects in the workspace. It can be created by calling catkin_init_workspace in the source space directory.

### Build Space

The build space is where CMake is invoked to build the catkin packages in the source space. CMake and catkin keep their cache information and other intermediate files here. The build space does not have to be contained within the workspace nor does it have to be outside of the source space, but this is recommended.

build 目录是build space的默认所在位置，同时cmake 和 make也是在这里被调用来配置并编译你的程序包。

### Development (Devel) Space

The development space (or devel space) is where built targets are placed prior to being installed. The way targets are organized in the devel space is the same as their layout when they are installed. This provides a useful testing and development environment which does not require invoking the installation step. The location of the devel space is controlled by a catkin specific CMake variable called CATKIN_DEVEL_PREFIX, and it defaults to/develspace. This is the default behavior because it might be confusing to CMake users if they invokedcmake .. in a build folder and that modified things outside of the current directory. It is recommended, however, to set thedevel space directory to be a peer of the build space directory.

devel 目录是devel space的默认所在位置, 同时也是在你安装程序包之前存放可执行文件和库文件的地方。

### Install Space

Once targets are built, they can be installed into the install space by invoking the install target, usually with make install. The install space does not have to be contained within the workspace. Since the install space is set by theCMAKE_INSTALL_PREFIX, it defaults to /usr/local, which you should not use (because uninstall is near-impossible, and using multiple ROS distributions does not work either).

### Result space

When ever referring to a folder which can either be a development space or an install space the generic term result spaceis used.

### ros包的位置

/opt/ros/kinetic/share/turtlesim

### 环境变量

ROS_ROOT /opt/ros/kinetic/share/ros
ROS_PACKAGE_PATH /opt/ros/kinetic/share
PYTHONPATH /opt/ros/kinetic/lib/python2.7/dist-packages

### The use of each folder in ROS package

• config: All configuration files that are used in this ROS package are kept in this
folder. This folder is created by the user and is a common practice to name the folder
config to keep the configuration files in it.

• include/package_name: This folder consists of headers and libraries that we need to
use inside the package.

• scripts: This folder keeps executable python scripts. In the block diagram, we can
see two example scripts.

• src: This folder stores the C++ source codes. We can see two examples of the source
code in the block diagram.

• launch: This folder keeps the launch files that are used to launch one or more ROS
nodes.

• msg: This folder contains custom message definitions.

• srv: This folder contains the service definitions.

• action: This folder contains the action definition. We will see more about actionlib
in the upcoming sections.

• package.xml: This is the package manifest file of this package.

• CMakeLists.txt: This is the CMake build file of this package.

# 如何自己写一个包

## package

• 快速创建程序包
$catkin_create_pkg beginner_tutorials std_msgs rospy roscpp # catkin_create_pkg <package_name> [depend1] [depend2] [depend3]1212 • 查看依赖 $ rospack depends1 beginner_tutorials 11
• 依赖

Build Tool Dependencies specify build system tools which this package needs to build itself. Typically the only build tool needed is catkin. In a cross-compilation scenario build tool dependencies are for the architecture on which the compilation is performed.
Build Dependencies specify which packages are needed to build this package. This is the case when any file from these packages is required at build time. This can be including headers from these packages at compilation time, linking against libraries from these packages or requiring any other resource at build time (especially when these packages are find_package()-ed in CMake). In a cross-compilation scenario build dependencies are for the targeted architecture.
Run Dependencies specify which packages are needed to run code in this package, or build libraries against this package. This is the case when you depend on shared libraries or transitively include their headers in public headers in this package (especially when these packages are declared as (CATKIN_)DEPENDS in catkin_package() in CMake).
Test Dependencies specify only additional dependencies for unit tests. They should never duplicate any dependencies already mentioned as build or run dependencies.

- <buildtool_depend>
- <build_depend>
- <run_depend>
- <test_depend>12341234

## CMakeLists

• Required CMake Version (cmake_minimum_required)
• Package Name (project())
• Find other CMake/Catkin packages needed for build (find_package())
• Enable Python module support (catkin_python_setup())
• Invoke message/service/action generation (generate_messages())
• Specify package build info export (catkin_package())
• Tests to build (catkin_add_gtest())
• Install rules (install())

• 本文已收录于以下专栏：

## ros机器人操作系统简介

Ros机器人操作系统类似“社会主义制度的国家”，众多的节点（node）充当“社会资源”（消息 message）的生产者与消费者（发布者与订阅者），社会资源（消息 message）通过市场（话题 top...

## ROS 机器人操作系统（1）

ROS中有许多概念，理解这些概念有助于对ROS整个程序架构理解。参考书籍《机器人操作系统浅析》 Package：在ROS中，所有软件都被组织为软件包的形式，称为ROS软件包或功能包，有时也简称为包。...

## ROS(机器人操作系统)学习（二）ROS文件系统

ROS WIKI：http://wiki.ros.org/ROS/Tutorials/NavigatingTheFilesystem 1.准备 您需要先安装tutorals

## ROS-机器人操作系统（ROS）浅析----第三章

举报原因： 您举报文章：深度学习：神经网络中的前向传播和反向传播算法推导 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)