teleop.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # License: BSD
00004 #   https://raw.github.com/robotics-in-concert/rocon_qt_gui/license/LICENSE
00005 #
00006 ##############################################################################
00007 # Imports
00008 ##############################################################################
00009 
00010 from __future__ import division
00011 import os
00012 import math
00013 import threading
00014 
00015 from python_qt_binding import loadUi
00016 from python_qt_binding.QtGui import QWidget
00017 
00018 import rospkg
00019 import rospy
00020 from rocon_qt_library.widgets import QResourceChooser, QVideoTeleop
00021 from rocon_qt_library.interfaces import ResourceChooserInterface
00022 
00023 from qt_gui.plugin import Plugin
00024 
00025 ##############################################################################
00026 # Teleop App
00027 ##############################################################################
00028 
00029 
00030 class Teleop(Plugin):
00031     def __init__(self, context):
00032         self._lock = threading.Lock()
00033         self._context = context
00034         super(Teleop, self).__init__(context)
00035         # I'd like these to be also configurable via the gui
00036         self.initialised = False
00037         self.is_setting_dlg_live = False
00038 
00039         self._widget = QWidget()
00040         rospack = rospkg.RosPack()
00041         ui_file = os.path.join(rospack.get_path('concert_qt_teleop'), 'ui', 'concert_teleop.ui')
00042         loadUi(ui_file, self._widget, {'QResourceChooser' : QResourceChooser, 'QVideoTeleop' : QVideoTeleop})
00043         if context.serial_number() > 1:
00044             self._widget.setWindowTitle(self._widget.windowTitle() + (' (%d)' % context.serial_number()))
00045 
00046         ##### Setting Resource Chooser Interface ####
00047         self._set_resource_chooser_interface()
00048 
00049         context.add_widget(self._widget)
00050         self.setObjectName('Teleop')
00051 
00052         self._default_cmd_vel_topic = '/teleop/cmd_vel'
00053         self._default_compressed_image_topic = '/teleop/compressed_image'
00054 
00055     def shutdown(self):
00056         with self._lock: 
00057             if self._teleop_interface:
00058                 self._teleop_interface.shutdown()
00059                 self._teleop_interface = None
00060 
00061     def _set_resource_chooser_interface(self):
00062         capture_timeout = rospy.get_param('~capture_timeout', 15.0)
00063         service_name = rospy.get_param('~service_name')
00064         available_resource_topic = '/services/%s/available_teleops'%service_name
00065         capture_resource_pair_topic = '/services/%s/capture_teleop'%service_name
00066         capture_resource_callbacks = [self._widget.resource_chooser_widget.capture_resource_callback, self._init_teleop_interface]
00067         release_resource_callbacks = [self._widget.resource_chooser_widget.release_resource_callback, self._uninit_teleop_interface]
00068         error_resource_callbacks   = [self._widget.resource_chooser_widget.error_resource_callback]
00069         refresh_resource_list_callbacks = [self._widget.resource_chooser_widget.refresh_resource_list_callback]
00070 
00071         self._resource_chooser_interface = ResourceChooserInterface(capture_timeout, available_resource_topic, capture_resource_pair_topic, capture_resource_callbacks, release_resource_callbacks, error_resource_callbacks, refresh_resource_list_callbacks)
00072 
00073         capture_event_callbacks = [self._resource_chooser_interface.capture_resource]
00074         release_event_callbacks = [self._resource_chooser_interface.release_resource]
00075         self._widget.resource_chooser_widget.set_callbacks(capture_event_callbacks, release_event_callbacks)
00076 
00077 
00078     def _init_teleop_interface(self, uri, msg):
00079         if msg.result:
00080             cmd_vel_topic = self._get_remapped_topic(self._default_cmd_vel_topic, msg.remappings)
00081             compressed_image_topic = self._get_remapped_topic(self._default_compressed_image_topic, msg.remappings)
00082 
00083             with self._lock:
00084                 self._widget.video_teleop_widget.init_teleop_interface(cmd_vel_topic_name=cmd_vel_topic, compressed_image_topic_name=compressed_image_topic)
00085 
00086     def _get_remapped_topic(self, remap_from, remappings):
00087         for r in remappings:
00088             if r.remap_from == remap_from:
00089                 return r.remap_to
00090         return remap_from
00091 
00092     def  _uninit_teleop_interface(self, uri, msg):
00093         if msg.result:
00094             with self._lock:    
00095                 self._widget.video_teleop_widget.reset()
00096 
00097     def shutdown_plugin(self):
00098         self._widget.video_teleop_widget.shutdown_plugin()
00099         self._widget.resource_chooser_widget.shutdown()


concert_qt_teleop
Author(s): Donguk Lee
autogenerated on Fri Feb 12 2016 02:50:06