繁体   English   中英

rqt ROS Python中的线程

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM