ROS如何创建自己的包
作者:知乎@Ai酱
1. 首先创建catkin工作空间(如果你以及有了请忽略)
$ mkdir catkin_ws
$ cd catkin_ws
~/catkin_ws$ catkin_make
此时你的catkin_ws这个目录已经生成了三个文件夹,注意:你只需要关心"catkin_ws/src"这个文件夹。 也就是说,我们写代码,或者从github下载了别人的包都在这个文件夹下进行。
2. 使用catkin_create_pkg命令创建包
首先,创建名为“hello_ros_pkg”的包。
~/catkin_ws$ cd src
~/catkin_ws/src$ catkin_create_pkg hello_ros_pkg rospy roscpp std_msgs
输出:
Created file hello_ros_pkg/package.xml
Created file hello_ros_pkg/CMakeLists.txt
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 in package.xml.
此时在~/catkin_ws/src目录下有个hello_ros_pkg的文件夹它的结构如下所示:
.
├── CMakeLists.txt 这个是告诉系统怎么编译这个包
├── include
│ └── hello_ros_pkg
├── package.xml 这个写依赖哪些包(我们之前依赖的rospy roscpp std_msgs都在这里有)
└── src
小提示:
rospy 写python脚本控制机器人时要依赖它
roscpp 写c++代码控制机器人要依赖它
std_msgs 要与机器人进行消息通信要依赖它(基本会用到的)
然后,编译整个项目。
$ cd ~/catkin_ws
$ catkin_make
安装了一个ROS包后,怎么找包在哪,以及看看包里面有哪些文件和文件夹,以及如何定位到某个包的文件夹
$ rospack list
$ rospack list | grep ur
$ rosls ur5_moveit_config
前面三行输出格式均为: 包名 包的绝对路径
$ rospack find ur5_moveit_config
输出:绝对路径
$ roscd ur5_moveit_config
注意从github下载了别人的包到catkin_ws/src目录下后,记得一次性下载完别人的依赖项,记得回到工作空间catkin_ws/这个目录(它里面有src文件夹)。
命令为:
~/catkin_ws$ rosdep install --from-paths src --ignore-src -r -y
转载于:https://www.cnblogs.com/ailitao/p/11047312.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)