示例#1
0
 def __init__(self, context):
     """
     :type context: qt_gui.PluginContext
     """
     super(RobotMonitorPlugin, self).__init__(context)
     self._robot_monitor = RobotMonitorWidget(context, 'diagnostics_agg')
     if context.serial_number() > 1:
         self._robot_monitor.setWindowTitle(
             self._robot_monitor.windowTitle() +
             (' (%d)' % context.serial_number()))
     context.add_widget(self._robot_monitor)
     self.setObjectName('rqt Robot Monitor')
class RobotMonitorBagView(TopicMessageView):
    name = 'Diagnostics Viewer'

    def __init__(self, timeline, parent, topic):
        super(RobotMonitorBagView, self).__init__(timeline, parent, topic)
        
        self._widget = RobotMonitorWidget(parent)
        parent.layout().addWidget(self._widget)

    def message_viewed(self, bag, msg_details):
        msg = msg_details[1]
        # generic conversion of DiagnosticStatus from bag type to current type
        #  this should be fairly robust to minor changes in the message format
        status = [DiagnosticStatus(**dict((slot, getattr(m, slot)) for slot in m.__slots__)) for m in msg.status]
        msg = DiagnosticArray(msg.header, status)
        self._widget.message_updated.emit(msg)

    def close(self):
        self._widget.shutdown()  # Closes unclosed popup windows.
示例#3
0
 def _show_monitor(self):
     with QMutexLocker(self._show_mutex):
         try:
             if self._monitor_shown:
                 self.context.remove_widget(self._monitor)
                 self._monitor_close()
                 self._monitor_shown = False
             else:
                 self._monitor = RobotMonitorWidget(self.context,
                                                    '/diagnostics_agg')
                 if self._plugin_settings:
                     self._monitor.restore_settings(self._plugin_settings,
                                                    self._instance_settings)
                 self.context.add_widget(self._monitor)
                 self._monitor_shown = True
         except Exception:
             if self._monitor_shown == False:
                 raise
             #TODO: when closeEvents is available fix this hack
             # (It ensures the button will toggle correctly)
             self._monitor_shown = False
             self._show_monitor()
示例#4
0
class RobotMonitorPlugin(Plugin):
    def __init__(self, context):
        """
        :type context: qt_gui.PluginContext
        """
        super(RobotMonitorPlugin, self).__init__(context)
        self._robot_monitor = RobotMonitorWidget(context, 'diagnostics_agg')
        if context.serial_number() > 1:
            self._robot_monitor.setWindowTitle(
                self._robot_monitor.windowTitle() +
                (' (%d)' % context.serial_number()))
        context.add_widget(self._robot_monitor)
        self.setObjectName('rqt Robot Monitor')

    def shutdown_plugin(self):
        """
        Call RobotMonitorWidget's corresponding function.

        Overriding Plugin's method.
        """
        self._robot_monitor.shutdown()  # Closes unclosed popup windows.

    def save_settings(self, plugin_settings, instance_settings):
        """
        Call RobotMonitorWidget's corresponding function.

        Overriding Plugin's method.
        """
        self._robot_monitor.save_settings(plugin_settings, instance_settings)

    def restore_settings(self, plugin_settings, instance_settings):
        """
        Call RobotMonitorWidget's corresponding function.

        Overriding Plugin's method.
        """
        self._robot_monitor.restore_settings(plugin_settings,
                                             instance_settings)
 def _show_monitor(self):
     with QMutexLocker(self._show_mutex):
         try:
             if self._monitor_shown:
                 self.context.remove_widget(self._monitor)
                 self._monitor_close()
                 self._monitor_shown = False
             else:
                 self._monitor = RobotMonitorWidget(self.context,
                                                    '/diagnostics_agg')
                 if self._plugin_settings:
                     self._monitor.restore_settings(self._plugin_settings,
                                                    self._instance_settings)
                 self.context.add_widget(self._monitor)
                 self._monitor_shown = True
         except Exception:
             if self._monitor_shown == False:
                 raise
             #TODO: when closeEvents is available fix this hack
             # (It ensures the button will toggle correctly)
             self._monitor_shown = False
             self._show_monitor()
class MonitorDashWidget(IconToolButton):
    """
    A widget which brings up the rqt_robot_monitor.

    Times out after certain period of time (set as 5 sec as of Apr 2013)
    without receiving diagnostics msg ('/diagnostics_toplevel_state' of
    DiagnosticStatus type), status becomes as 'stale'.

    :param context: The plugin context to create the monitor in.
    :type context: qt_gui.plugin_context.PluginContext
    """
    def __init__(self, context, icon_paths=[]):
        self._graveyard = []
        ok_icon = ['bg-green.svg', 'ic-diagnostics.svg']
        warn_icon = ['bg-yellow.svg', 'ic-diagnostics.svg',
                     'ol-warn-badge.svg']
        err_icon = ['bg-red.svg', 'ic-diagnostics.svg', 'ol-err-badge.svg']
        stale_icon = ['bg-grey.svg', 'ic-diagnostics.svg',
                      'ol-stale-badge.svg']

        icons = [ok_icon, warn_icon, err_icon, stale_icon]

        super(MonitorDashWidget, self).__init__('MonitorWidget', icons,
                                                icon_paths=icon_paths)

        self.setFixedSize(self._icons[0].actualSize(QSize(50, 30)))

        self._monitor = None
        self._close_mutex = QMutex()
        self._show_mutex = QMutex()

        self._last_update = rospy.Time.now()

        self.context = context
        self.clicked.connect(self._show_monitor)

        self._monitor_shown = False
        self.setToolTip('Diagnostics')

        self._diagnostics_toplevel_state_sub = rospy.Subscriber(
                                'diagnostics_toplevel_state',
                                DiagnosticStatus, self.toplevel_state_callback)
        self._top_level_state = -1
        self._stall_timer = QTimer()
        self._stall_timer.timeout.connect(self._stalled)
        self._stalled()
        self._plugin_settings = None
        self._instance_settings = None

    def toplevel_state_callback(self, msg):
        self._is_stale = False
        self._stall_timer.start(5000)

        if self._top_level_state != msg.level:
            if (msg.level >= 2):
                self.update_state(2)
                self.setToolTip("Diagnostics: Error")
            elif (msg.level == 1):
                self.update_state(1)
                self.setToolTip("Diagnostics: Warning")
            else:
                self.update_state(0)
                self.setToolTip("Diagnostics: OK")
            self._top_level_state = msg.level

    def _stalled(self):
        self._stall_timer.stop()
        self._is_stale = True
        self.update_state(3)
        self._top_level_state = 3
        self.setToolTip("Diagnostics: Stale\nNo message received on " +
                        "dashboard_agg in the last 5 seconds")

    def _show_monitor(self):
        with QMutexLocker(self._show_mutex):
            try:
                if self._monitor_shown:
                    self.context.remove_widget(self._monitor)
                    self._monitor_close()
                    self._monitor_shown = False
                else:
                    self._monitor = RobotMonitorWidget(self.context,
                                                       '/diagnostics_agg')
                    if self._plugin_settings:
                        self._monitor.restore_settings(self._plugin_settings,
                                                       self._instance_settings)
                    self.context.add_widget(self._monitor)
                    self._monitor_shown = True
            except Exception:
                if self._monitor_shown == False:
                    raise
                #TODO: when closeEvents is available fix this hack
                # (It ensures the button will toggle correctly)
                self._monitor_shown = False
                self._show_monitor()

    def _monitor_close(self):
        if self._monitor_shown:
            with QMutexLocker(self._close_mutex):
                if self._plugin_settings:
                    self._monitor.save_settings(self._plugin_settings,
                                                self._instance_settings)
                self._monitor.shutdown()
                self._monitor.close()
                self._graveyard.append(self._monitor)
                self._monitor = None

    def shutdown_widget(self):
        self._stall_timer.stop()
        if self._monitor:
            self._monitor.shutdown()
        self._diagnostics_toplevel_state_sub.unregister()

    def save_settings(self, plugin_settings, instance_settings):
        if self._monitor_shown:
            self._monitor.save_settings(self._plugin_settings,
                                        self._instance_settings)

    def restore_settings(self, plugin_settings, instance_settings):
        self._plugin_settings = plugin_settings
        self._instance_settings = instance_settings
    def __init__(self, timeline, parent, topic):
        super(RobotMonitorBagView, self).__init__(timeline, parent, topic)

        self._widget = RobotMonitorWidget(parent)
        parent.layout().addWidget(self._widget)
示例#8
0
class MonitorDashWidget(IconToolButton):
    """
    A widget which brings up the rqt_robot_monitor.

    Times out after certain period of time (set as 5 sec as of Apr 2013)
    without receiving diagnostics msg ('/diagnostics_toplevel_state' of
    DiagnosticStatus type), status becomes as 'stale'.

    :param context: The plugin context to create the monitor in.
    :type context: qt_gui.plugin_context.PluginContext
    """
    def __init__(self, context, icon_paths=[]):
        self._graveyard = []
        ok_icon = ['bg-green.svg', 'ic-diagnostics.svg']
        warn_icon = [
            'bg-yellow.svg', 'ic-diagnostics.svg', 'ol-warn-badge.svg'
        ]
        err_icon = ['bg-red.svg', 'ic-diagnostics.svg', 'ol-err-badge.svg']
        stale_icon = [
            'bg-grey.svg', 'ic-diagnostics.svg', 'ol-stale-badge.svg'
        ]

        icons = [ok_icon, warn_icon, err_icon, stale_icon]

        super(MonitorDashWidget, self).__init__('MonitorWidget',
                                                icons,
                                                icon_paths=icon_paths)

        self.setFixedSize(self._icons[0].actualSize(QSize(50, 30)))

        self._monitor = None
        self._close_mutex = QMutex()
        self._show_mutex = QMutex()

        self._last_update = rospy.Time.now()

        self.context = context
        self.clicked.connect(self._show_monitor)

        self._monitor_shown = False
        self.setToolTip('Diagnostics')

        self._diagnostics_toplevel_state_sub = rospy.Subscriber(
            'diagnostics_toplevel_state', DiagnosticStatus,
            self.toplevel_state_callback)
        self._top_level_state = -1
        self._stall_timer = QTimer()
        self._stall_timer.timeout.connect(self._stalled)
        self._stalled()
        self._plugin_settings = None
        self._instance_settings = None

    def toplevel_state_callback(self, msg):
        self._is_stale = False
        self._stall_timer.start(5000)

        if self._top_level_state != msg.level:
            if (msg.level >= 2):
                self.update_state(2)
                self.setToolTip("Diagnostics: Error")
            elif (msg.level == 1):
                self.update_state(1)
                self.setToolTip("Diagnostics: Warning")
            else:
                self.update_state(0)
                self.setToolTip("Diagnostics: OK")
            self._top_level_state = msg.level

    def _stalled(self):
        self._stall_timer.stop()
        self._is_stale = True
        self.update_state(3)
        self._top_level_state = 3
        self.setToolTip("Diagnostics: Stale\nNo message received on " +
                        "dashboard_agg in the last 5 seconds")

    def _show_monitor(self):
        with QMutexLocker(self._show_mutex):
            try:
                if self._monitor_shown:
                    self.context.remove_widget(self._monitor)
                    self._monitor_close()
                    self._monitor_shown = False
                else:
                    self._monitor = RobotMonitorWidget(self.context,
                                                       '/diagnostics_agg')
                    if self._plugin_settings:
                        self._monitor.restore_settings(self._plugin_settings,
                                                       self._instance_settings)
                    self.context.add_widget(self._monitor)
                    self._monitor_shown = True
            except Exception:
                if self._monitor_shown == False:
                    raise
                #TODO: when closeEvents is available fix this hack
                # (It ensures the button will toggle correctly)
                self._monitor_shown = False
                self._show_monitor()

    def _monitor_close(self):
        if self._monitor_shown:
            with QMutexLocker(self._close_mutex):
                if self._plugin_settings:
                    self._monitor.save_settings(self._plugin_settings,
                                                self._instance_settings)
                self._monitor.shutdown()
                self._monitor.close()
                self._graveyard.append(self._monitor)
                self._monitor = None

    def shutdown_widget(self):
        self._stall_timer.stop()
        if self._monitor:
            self._monitor.shutdown()
        self._diagnostics_toplevel_state_sub.unregister()

    def save_settings(self, plugin_settings, instance_settings):
        if self._monitor_shown:
            self._monitor.save_settings(self._plugin_settings,
                                        self._instance_settings)

    def restore_settings(self, plugin_settings, instance_settings):
        self._plugin_settings = plugin_settings
        self._instance_settings = instance_settings