2017-11-11 5 views
0

私は、rqtの中でロボットのUIプラグインをPythonを使って設計しています。基本的に、「Goto Home」ボタンと呼ばれるボタンがあります。このボタンをクリックするとロボットを動かしたい。このボタンをクリックするとロボットは動きますが、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) 

ここにスレッドを実装します。もっと貴重なことに、self._robot.move_to_joint_angles(self._joint_angles)をrqtのスレッドを使って呼び出す方法。私はUbuntu 14.04 LTS PCのROS IndigoでPython 2.7を使用しています。

答えて

0

回避策が見つかりました。下記のコードスニペットをご覧ください:

import thread 
thread.start_new_thread(self.baxter.move_to_joint_angles, (self.home_pose,)) 

もっと良い方法がありますか?

関連する問題