本机系统:Ubuntu 16.04, ROS Luna
更新20191023:Ubutnu 18.04 LTS ROS Melodic
所有文件可在https://github.com/huyaoyu/rqt_my_plugin获取。
关于ROS rqt custom plugin的官方文档在
http://wiki.ros.org/rqt/Tutorials/Create%20your%20new%20rqt%20plugin
http://wiki.ros.org/rqt/Tutorials/Writing%20a%20Python%20Plugin
相关源码在
https://github.com/lucasw/rqt_mypkg
本文在综合上述信息的基础上,进行了尝试,这里把过程留下。
更新20191023:在实例中增加了topic的publisher和subscriber,增加了service 的server和client。
创建新ROS package
- 在catkin的workspace/src下,创建新的ROS package。
catkin_create_pkg rqt_my_plugin rospy rqt_gui rqt_gui_py
- 修改rqt_my_plugin/package.xml文件
变更package名称(尚未完善测试,这里是为了防止python import过程中出现命名冲突)
<package><name>元素从qrt_my_plugin修改为my_plugin
在<package>element下增加如下内容
<export>
<rqt_gui plugin="${prefix}/plugin.xml" />
</export>
为了使用service,在<package>元素内增加
<build_depend>message_generation</build_depend>
<exec_depend>message_runtime</exec_depend>
创建plugin.xml文件。plugin.xml文件同样位于rqt_my_plugin文件夹下。
<library path="src">
<class name="My plugin" type="plugin.my_module.MyPlugin" base_class_type="rqt_gui_py::Plugin">
<description>
A Python GUI plugin for test the functionalities.
</description>
<qtgui>
<group>
<label>Logging</label>
<icon type="theme">folder</icon>
<statustip>Plugins related to logging.</statustip>
</group>
<label>My plugin label</label>
<icon type="theme">applications-other</icon>
<statustip>A Python GUI plugin for test the functionalities.</statustip>
</qtgui>
</class>
</library>
其中,<class>的type属性是后面要创建的python脚本内定义的类名。<group>element表示将该插件置于rqt的plugin目录的哪一个子目录下。
setup.py文件
在同样位置创建setup.py文件,内容如下。
from distutils.core import setup
from catkin_pkg.python_setup import generate_distutils_setup
d = generate_distutils_setup(
packages=['plugin'],
package_dir={'': 'src'},
)
setup(**d)
创建UI resource
在package的文件夹内创建resource文件夹,在该文件夹内放置Qt designer输出的.ui文件。.ui文件实际上是xml文件,这里使用的实例如下,命名为MyPlugin.ui。
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">