ROS Package中的Python使用规范

本文介绍了如何在ROS中规范地创建和管理Python包,包括ROS Package的结构、setup.py的编写,以及具体使用实例。强调了src目录下模块的组织方式,如何在setup.py中描述Python包结构,以及在节点中导入模块和服务的方法。并提供了包含多个子模块的实际项目结构示例。
摘要由CSDN通过智能技术生成

参考:
1. https://answers.ros.org/question/192723/cant-find-python-scripts-after-sourcing/
2. http://wiki.ros.org/PyStyleGuide

最近需要在ROS下实现几个使用TensorFlow的Publisher和Server node,出现了搜索不到module或者ros找不到我的node的情况,所以在网上搜了下怎么管理用Python写的ros package,把问题解决了。这篇博客的前半部分都来自参考[1],后半部分会讲一下参考[1]没说清楚的部分,还有我遇到的问题。

一、ROS Package结构

假设我建立了一个叫knex_pkg的包,其中包含如下四个node:

scripts/knex_arduino_connector.py
scripts/knex_scratch_connector.py
scripts/range_filter.py
scripts/range_to_laser.py

那么这个Package的结构应该如下所示:

knex_pkg/
    CMakesLists.txt
    package.xml
    launch/ # roslaunch files go here
    msg/ # msg files go here
    nodes/ # installable python nodes go here
        knex_arduino_connector.py
        knex_scratch_connector.py
        range_filter.py
        range_to_laser.py
    src/ # this is where your python modules exported as libraries or used in your nodes go.
    urdf/ # urdf and xacro files go here -- basically your robot model stuff, if any.
    scripts/ # generally non-exported python scripts -- stuff that might be called to setup your package and code gen stuff
    srv/ # service descriptions go here
    __init__.py # only necessary if you want to use anything from the scripts directory in your package src and node files
   
  • 4
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值