rqt ROS中的线程Python
问题描述:
我正在为使用python的rqt内部的机器人设计UI插件。基本上,有一个按钮称为“转到主页”按钮。点击此按钮后,我想移动机器人。请注意,无论何时单击此按钮,机器人都会移动,但GUI在一段时间内变得无响应,这很明显是通过编写代码的方式。请看下面的代码片段:rqt ROS中的线程Python
import rospy
from robot_controller import RobotController
from qt_gui.plugin import Plugin
from python_qt_binding.QtGui import QWidget, QVBoxLayout, QPushButton
class MyPlugin(Plugin):
def __init__(self, context):
super(MyPlugin, self).__init__(context)
# Give QObjects reasonable names
self.setObjectName('MyPlugin')
# Create QWidget
self._widget = QWidget()
self._widget.setObjectName('MyPluginUi')
# Create push button and connect a function
self._goto_home_button = QPushButton('Goto Home')
self._goto_home_button.clicked.connect(self.goto_home)
self._vertical_layout = QVBoxLayout()
self._vertical_layout.addWidget(self._goto_home_button.)
self._widget.setLayout(self._vertical_layout)
context.add_widget(self._widget)
# Create robot object to move robot from GUI
self._robot = RobotController()
def goto_home(self):
self._robot.move_to_joint_angles(self._joint_angles)
我想在这里实现一个线程。更加珍贵的是,如何使用rqt中的线程调用self._robot.move_to_joint_angles(self._joint_angles)
。请注意,我在Ubuntu 14.04 LTS PC上使用ROS Indigo中的Python 2.7。
答
我找到了解决方法。请参阅下面的代码片段:
import thread
thread.start_new_thread(self.baxter.move_to_joint_angles, (self.home_pose,))
有没有更好的方法来做到这一点?