ros 部署python 节点 ,cmakelist.txt和setup.py的写法
项目紧急,没有接触过python的节点布置,以下为可行的cmakelists.txt的部署方式(能够实现功能,写法也比较草率,在网上寻找了许多,这是一种自测可用的方案,cmakelist写的不好,原理还不太明白,后续记录补充,)
一、python节点主要结构
my_package/
CMakeLists.txt
package.xml
setup.py #(部署install包的时候需要这个文件,文件中内容在后续)
launch/
ros_node.launch
src/
my_package/
demo.py
—init—.py
include/ #(这个包的名字自取,demo.py所调用的库文件可以放这里,)
demo1.py
demo2.py
—init—.py #(每个包中放一个—init—.py)
二、cmakelist.txt
1.取消cmakelist里catkin_python_setup的注释(与setup.py有关,内容在下节)
2.在cmakelist添加
install(PROGRAMS
src/my_package/demo.py
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
三、setup.py
在setup.py加入以下语句
from distutils.core import setup
from catkin_pkg.python_setup import generate_distutils_setup
setup_args = generate_distutils_setup(
packages=[‘my_package’ (#通过catkin_make install 后会在python2.7里面生成my_package下.py文件)
‘include’], (#上一步include及目录下文件未生成,需要再添加include,如果include目录下还有文件夹目录,仍需要继续添加package)
package_dir={’’: ‘src’})
setup(**setup_args)
参考:https://github.com/jlyw1017/ros_packages/tree/master/python_package
https://blog.youkuaiyun.com/afei__/article/details/81201039
https://blog.youkuaiyun.com/cyril__li/article/details/78979253
https://zhuanlan.zhihu.com/p/58382081