学习链接
https://www.imooc.com/article/252345
https://github.com/DroidAITech/ROS-Academy-for-Beginners
当下载某个功能包到自己的空间,在编译时,出现依赖项有问题,解决如下:
$roscd package_name
$rosdep package_name
rosdep即可安装缺少的依赖项
直接用这个方法就行了
一个一个装太麻烦,我们直接安装ros一个功能包所需要的依赖一个较常使用的命令是 :
rosdep install --from-paths src --ignore-src --rosdistro=kinetic -y
这个命令是用于安装工作空间中 src 路径下所有package的依赖项(由pacakge.xml文件指定)。
————————————————————————————————————
工作空间
vision_pac文件夹表示一个包(package),package是ROS源代码存放的地方,任何ROS的代码无论是C++还是Python都要放到package中,这样才能正常的编译和运行。
src中存放的是C++和Python源代码,这里每一个.cpp文件都是一个节点(node)。从功能角度来说,通常一个node负责者机器人的某一个单独的功能。由于机器人的功能模块非常复杂,我们往往不会把所有功能都集中到一个node上,而会采用分布式的方式,把鸡蛋放到不同的篮子里。自然,节点之间会通过各种方法来进行通信,ROS中有两种,一种是topic通信,另一种是service通信。本文中使用的是topic通信。
ROS平台始终的是cmake工具进行编译,并且ROS对cmake进行扩展,于是便有了Catkin编译系统。CMakeLists.txt原本是Cmake编译系统的规则文件,而Catkin编译系统基本沿用了CMake的编译风格,只是针对ROS工程添加了一些宏定义。所以在写法上,catkin的 CMakeLists.txt 与CMake的基本一致。这个文件直接规定了这个package要依赖哪些package,要编译生成哪些目标,如何编译等等流程。Roboware帮我们完成了大部分工作,不需要关心这个文件的具体编写。
pacakge.xml 包含了package的名称、版本号、内容描述、维护人员、软件许可、编译构建工具、编译依赖、运行依赖等信息。 rospack find、rosdep 等命令能快速定位和分析出package的依赖项信息,原因就是直接读取了每一个pacakge中的 package.xml文件。
ROS_安装一个第三方仿真软件包——机器人模拟世界
最终效果图
下载源码包
在Ubuntu系统上,确保git已经安装
sudo apt-get install git
然后再创建一个名为tutorial_ws的工作空间,在它的src路径下克隆ROS-Academy-for-Beginners软件包cdmkdir -p tutorial_ws/src 创建catkin工作空间cd tutorial_ws/src 进入src路径,克隆教学软件包
git clone https://github.com/DroidAITech/ROS-Academy-for-Beginners.git
安装依赖
安装依赖:
cd ~/tutorial_ws
rosdep install --from-paths src --ignore-src --rosdistro=kinetic -y
过程图:
注意:以上命令非常重要,缺少依赖将导致软件包无法正常编译和运行。
在开始编译之前,需要确保Gazebo在7.0版本以上
gazebo -V
编译
接着回到catkin_ws下编译:
cd ~/tutorial_ws
catkin_make
过程图:
下面是刷新环境的两种方法:
source ~/tutorial_ws/devel/setup.bash
rospack profile
过程图:
运行仿真程序
首先需要解决一个问题,不然待会儿运行时会闪退:
虚拟机上无法运行Gazebo的问题?
然后进入工作空间,输入下方代码即可:
roslaunch robot_sim_demo robot_spawn.launch
下面是运行过程图(是的,一开始可能会遇到一个报错[robot_spawn.launch] is neither a launch file in package [robot_sim_demo] nor is [robot_sim_demo] a launch file name The traceback for the exception was written to the log file,然而下面的过程图已经是从报错到解决报错成功运行的过程了):
liweipeng@liweipeng-virtual-machine:~$ rospack profile
Full tree crawl took 0.189714 seconds.
Directories marked with (*) contain no manifest. You may
want to delete these directories.
To get just of list of directories without manifests,
re-run the profile with --zombie-only
-------------------------------------------------------------0.141810 /opt/ros/kinetic/share0.000770 * /opt/ros/kinetic/share/OpenCV-3.3.1-dev0.000257 * /opt/ros/kinetic/share/doc0.000043 * /opt/ros/kinetic/share/OpenCV-3.3.1-dev/haarcascades0.000019 * /opt/ros/kinetic/share/OpenCV-3.3.1-dev/lbpcascades0.000008 * /opt/ros/kinetic/share/doc/liborocos-kdl
liweipeng@liweipeng-virtual-machine:~$ roslaunch robot_sim_demo robot_spawn.launch
[robot_spawn.launch] is neither a launch file in package [robot_sim_demo] nor is [robot_sim_demo] a launch file name
The traceback for the exception was written to the log file
liweipeng@liweipeng-virtual-machine:~$ roslaunch robot_sim_demo robot_spawn.launch
[robot_spawn.launch] is neither a launch file in package [robot_sim_demo] nor is [robot_sim_demo] a launch file name
The traceback for the exception was written to the log file
liweipeng@liweipeng-virtual-machine:~$ cd ~/tutorial_ws
liweipeng@liweipeng-virtual-machine:~/tutorial_ws$ roslaunch robot_sim_demo robot_spawn.launch
[robot_spawn.launch] is neither a launch file in package [robot_sim_demo] nor is [robot_sim_demo] a launch file name
The traceback for the exception was written to the log file
liweipeng@liweipeng-virtual-machine:~/tutorial_ws$ source ~/tutorial_ws/devel/setup.bash
liweipeng@liweipeng-virtual-machine:~/tutorial_ws$ rospack profile
Full tree crawl took 0.025369 seconds.
Directories marked with (*) contain no manifest. You may
want to delete these directories.
To get just of list of directories without manifests,
re-run the profile with --zombie-only
-------------------------------------------------------------0.016329 /opt/ros/kinetic/share0.008478 /home/liweipeng/tutorial_ws/src0.008405 /home/liweipeng/tutorial_ws/src/ROS-Academy-for-Beginners0.000169 * /opt/ros/kinetic/share/OpenCV-3.3.1-dev0.000036 * /opt/ros/kinetic/share/doc0.000035 * /opt/ros/kinetic/share/OpenCV-3.3.1-dev/haarcascades0.000015 * /opt/ros/kinetic/share/OpenCV-3.3.1-dev/lbpcascades0.000006 * /opt/ros/kinetic/share/doc/liborocos-kdl
liweipeng@liweipeng-virtual-machine:~/tutorial_ws$ roslaunch robot_sim_demo robot_spawn.launch
... logging to /home/liweipeng/.ros/log/3bcd5ac4-be9d-11e8-a270-000c29f43d2c/roslaunch-liweipeng-virtual-machine-2603.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.
xacro: Traditional processing is deprecated. Switch to --inorder processing!
To check for compatibility of your document, use option --check-order.
For more infos, see http://wiki.ros.org/xacro#Processing_Orderxacro.py is deprecated; please use xacro instead
started roslaunch server http://liweipeng-virtual-machine:41819/
SUMMARY
========
PARAMETERS
再打开一个终端,输入以下命令,用键盘控制机器人移动,聚焦控制程序窗口,按下i、j、l等按键,控制机器人移动:
rosrun robot_sim_demo robot_keyboard_teleop.py
过程图如下,记得运行前要刷新环境,或者用上面的方法把刷新命令添加到脚本:
本仓库为ROS入门教程的代码示例,包括以下ROS软件包:
软件包 内容
robot_sim_demo 机器人仿真程序,大部分示例会用到这个软件包
topic_demo topic通信,自定义msg,包括C++和python两个版本实现
service_demo service通信,自定义srv,分别以C++和python两种语言实现
action_demo action通信,自定义action,C++和python两种语言实现
param_demo param操作,分别以C++和python两种语言实现
msgs_demo 演示msg、srv、action文件的格式规范
tf_demo tf相关API操作演示,tf示例包括C++和python两个版本
tf_follower 制作mybot机器人 实现mybot跟随xbot的功能
urdf_demo 创建机器人urdf模型,在RViz中显示
navigation_sim_demo 导航演示工具包,包括AMCL, Odometry Navigation等演示
slam_sim_demo 同步定位与建图演示,包括Gmapping, Karto, Hector等SLAM演示
robot_orbslam2_demo ORB_SLAM2的演示
ros_academy_for_beginners Metapacakge示例,依赖了本仓库所有的pacakge
下载和编译
克隆或下载ROS-Academy-for-Beginners教学包到工作空间的/src目录下,例如 ~/catkin_ws/src
$ cd ~/catkin_ws/src
$ git clone https://github.com/DroidAITech/ROS-Academy-for-Beginners.git
安装教学包所需的依赖
$ cd ~/catkin_ws
$ rosdep install --from-paths src --ignore-src --rosdistro=kinetic -y
编译并刷新环境
$ catkin_make
$ source ~/catkin_ws/devel/setup.bash
运行示例
运行须知
建议在本地Ubuntu 16.04下运行仿真程序。目前Gazebo模拟器的兼容性是一大问题,在虚拟机或配置较低的电脑上可能无法运行。如果你的显卡是N卡,建议安装Ubuntu下的显卡驱动。
运行Gazebo仿真程序robot_sim_demo前,请将Gazebo升级到7.x版本以上(推荐7.9版本)。
查看Gazebo版本方法
$ gazebo -v #确认7.0以上,推荐7.9
升级方法
$ sudo sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list'
$ wget http://packages.osrfoundation.org/gazebo.key -O - | sudo apt-key add -
$ sudo apt-get update
$ sudo apt-get install gazebo7
确保所有依赖都已安装,如gazebo_ros, gmapping, slam_karto, amcl。