适合初学者的ROS机器⼈教程(1):Ubuntu下ROS创建⾃⼰的包和使⽤github
下载的包
ROS如何创建⾃⼰的包
作者:知乎
1. ⾸先创建catkin⼯作空间(如果你以及有了请忽略)
$ mkdir catkin_ws # 创建⼀个⽂件夹⾥⾯计划放我们的项⽬,ws是workspace的缩写
$ cd catkin_ws # 将当前⼯作⽂件夹切换到catkin_ws这个⽂件夹
~/catkin_ws$ catkin_make # 执⾏catkin_make创建⼀ROS项⽬
此时你的catkin_ws这个⽬录已经⽣成了三个⽂件夹,注意:你只需要关⼼"catkin_ws/src"这个⽂件夹。 也就是说,我们写代码,或者从github下载了别⼈的包都在这个⽂件夹下进⾏。
2. 使⽤catkin_create_pkg命令创建包
⾸先,创建名为“hello_ros_pkg”的包。
~/catkin_ws$ cd src # 记得前⾯说了啥不?我们只关⼼src这个⽬录,创建包也必须到这个⽬录下创建
# catkin_create_pkg 包名依赖包1 依赖包2 依赖包3
# 创建⼀包名为“hello_ros_pkg”的包,它的依赖包有rospy roscpp std_msgs
~/catkin_ws/src$ catkin_create_pkg hello_ros_pkg rospy roscpp std_msgs
输出:
Created file hello_ros_l
Created file hello_ros_
Created folder hello_ros_pkg/include/hello_ros_pkg
Created folder hello_ros_pkg/src
Successfully created files in /home/litao/catkin_ws/src/hello_ros_pkg.
Please adjust the values l.
此时在~/catkin_ws/src⽬录下有个hello_ros_pkg的⽂件夹它的结构如下所⽰:
.
├──   这个是告诉系统怎么编译这个包
├── include
│└── hello_ros_pkg
├── l  这个写依赖哪些包(我们之前依赖的rospy roscpp std_msgs都在这⾥有)
└── src
⼩提⽰:
rospy 写python脚本控制机器⼈时要依赖它
roscpp 写c++代码控制机器⼈要依赖它
std_msgs 要与机器⼈进⾏消息通信要依赖它(基本会⽤到的)
然后,编译整个项⽬。
$ cd ~/catkin_ws # 回到catkin_ws⼯作空间这⽬录
$ catkin_make # 编译整个项⽬
安装了⼀个ROS包后,怎么包在哪,以及看看包⾥⾯有哪些⽂件和⽂件夹,以及如何定位到某个包的⽂件夹
$ rospack list # 列出所有包
$ rospack list |grep ur # 查询所有包名中带"ur"这两个字符的包,⽐如你安装了ur5机器⼈但是忘了包名就可这样包名
$ rosls ur5_moveit_config # 列出包名为"ur5_moveit_config"的包⾥⾯的⽂件
前⾯三⾏输出格式均为:包名包的绝对路径
$ rospack find ur5_moveit_config # 包名为"ur5_moveit_config"的包所在的绝对路径
ubuntu使用入门教程输出:绝对路径
$ roscd ur5_moveit_config # 将当前⼯作⽬录切换为"ur5_moveit_config"的包所在的⽂件夹
注意从github下载了别⼈的包到catkin_ws/src⽬录下后,记得⼀次性下载完别⼈的依赖项,记得回到⼯作空间catkin_ws/这个⽬录(它⾥⾯有src⽂件夹)。
命令为:
~/catkin_ws$ rosdep install --from-paths src --ignore-src -r -y