![](/img/trans.png)
[英]ROS - rqt - python: Fatal IO error 2 (No such file or directory) on X server :0.0
[英]Threads in rqt ROS Python
我正在使用python為rqt內的機器人設計UI插件。 基本上,有一個按鈕稱為“轉到主頁”按鈕。 單擊此按鈕后,我想移動機器人。 請注意,每當我單擊此按鈕時,機器人都會移動,但是GUI會在一段時間內無響應,這在編寫代碼時很明顯。 請參見下面的代碼片段:
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)
中的線程調用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._robot.move_to_joint_angles, (self.home_pose,))
有什么更好的方法嗎?
actions
會更適合這個。
但是,在某些情況下,如果服務執行時間較長,則用戶可能希望能夠在執行過程中取消請求或獲得有關請求進展情況的定期反饋。 actionlib軟件包提供了一些工具來創建執行長期目標的服務器,這些目標可以被搶占。 它還提供了一個客戶端接口,以便將請求發送到服務器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.