2017-11-11 19 views
0

rqt 안에 파이썬을 사용하여 로봇 용 UI 플러그인을 설계했습니다. 기본적으로 'Go 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,)) 

더 좋은 방법이 있습니까?