ROS Tutorials
手册链接:ROS/Tutorials - ROS Wiki cn/ROS/Tutorials - ROS Wiki
安装:kinetic/Installation/Ubuntu - ROS Wiki
环境管理
通过
printenv | grep ROS
判断 ROS 是否正常安装,主要判断 ROS_ROOT 和 ROS_PACKAGE_PATH 是否存在。
如果不存在,可以通过执行
source /opt/ros/<distro>/setup.bash
echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc
source ~/.bashrc
创建 ROS Worksapce
$ mkdir -p ~/catkin_ws/src
$ cd ~/catkin_ws/
$ catkin_make
上述代码将在 src 路径下生成 CMakeLists.txt 文件,build/,devel/。
其中 devel 中的 setup.*sh 文件是用来切换当前 ROS Workspace 的。
$ source devel/setup.bash
判断是否已经正确完成的 Workspace 的切换
$ echo $ROS_PACKAGE_PATH
/home/youruser/catkin_ws/src:/opt/ros/kinetic/share
浏览 ROS 文件系统 —— ROS 常用命令
rospack
rospack allows you to get information about packages. In this tutorial, we are only going to cover the find option, which returns the path to package.
$ rospack find [package_name]
$ rospack find roscpp
YOUR_INSTALL_PATH/share/roscpp
If you installed ROS Kinetic from apt on Ubuntu Linux you would see exactly:
/opt/ros/kinetic/share/roscpp
roscd
roscd is part of the rosbash suite. It allows you to change directory (cd) directly to a package or a stack.
$ roscd [locationname[/subdir]]
$ roscd roscpp
$ pwd
YOUR_INSTALL_PATH/share/roscpp
Note that roscd, like other ROS tools, will only find ROS packages that are within the directories listed in your ROS_PACKAGE_PATH.
roscd log will take you to the folder where ROS stores log files. Note that if you have not run any ROS programs yet, this will yield an error saying that it does not yet exist.
rosls
rosls is part of the rosbash suite. It allows you to ls directly in a package by name rather than by absolute path.
$ rosls [locationname[/subdir]]
$ rosls roscpp_tutorials
cmake launch package.xml srv
roscore
roscore is the first thing you should run when using ROS.
$ roscore
If roscore does not initialize and sends a message about lack of permissions, probably the ~/.ros folder is owned by root, change recursively the ownership of that folder with:
$ sudo chown -R <your_username> ~/.ros
rosnode
rosnode displays information about the ROS nodes that are currently running. The rosnode list command lists these active nodes:
$ rosnode list
/rosout
$ rosnode info /rosout
------------------------------------------------------------------------
Node [/rosout]
Publications:
* /rosout_agg [rosgraph_msgs/Log]
Subscriptions:
* /rosout [unknown type]
Services:
* /rosout/get_loggers
* /rosout/set_logger_level
contacting node http://machine_name:54614/ ...
Pid: 5092
rosrun
rosrun allows you to use the package name to directly run a node within a package (without having to know the package path).
$ rosrun [package_name] [node_name]
$ rosrun turtlesim turtlesim_node
use a Remapping Argument to change the node's name:
$ rosrun turtlesim turtlesim_node __name:=my_turtle
cleaning the rosnode list with:
$ rosnode cleanup
Let's use another rosnode command, ping, to test that it's up:
$ rosnode ping my_turtle
rosnode: node is [/my_turtle]
pinging /my_turtle with a timeout of 3.0s
xmlrpc reply from http://aqy:42235/ time=1.152992ms
xmlrpc reply from http://aqy:42235/ time=1.120090ms
xmlrpc reply from http://aqy:42235/ time=1.700878ms
xmlrpc reply from http://aqy:42235/ time=1.127958ms
创建 ROSPackage
# You should have created this in the Creating a Workspace Tutorial
$ cd ~/catkin_ws/src
$ catkin_create_pkg beginner_tutorials std_msgs rospy roscpp
This will create a beginner_tutorials folder which contains a package.xml and a CMakeLists.txt, which have been partially filled out with the information you gave catkin_create_pkg.
其中 package.xml provides meta information about the package.
Build Packages
CMAKE
# In a CMake project
$ mkdir build
$ cd build
$ cmake ..
$ make
$ make install # (optionally)
Catkin
# In a catkin workspace
$ catkin_make
$ catkin_make install # (optionally)
上述命令将编译 src 中的所有 Package。