status_indicator.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Copyright (c) 2020 Pilz GmbH & Co. KG
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Lesser General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 import os
18 
19 import rospy
21  PilzStatusIndicatorWidget
22 from prbt_hardware_support.msg import OperationModes
23 from qt_gui.plugin import Plugin
24 from std_msgs.msg import Bool, Float64
25 
26 TOPIC_OPERATION_MODE = "/prbt/operation_mode"
27 TOPIC_STATE_HW = "/prbt/status_info/state_hw"
28 TOPIC_STATE_ROS = "/prbt/status_info/state_ros"
29 TOPIC_SPEED_OVERRIDE = "/prbt/speed_override"
30 
31 
33  """Implementation of the status indicator as rqt plugin. It will
34  instantiate the Qt widget and handle the connection between ROS and its
35  visual state."""
36 
37  def __init__(self, context):
38  """Instantiate the plugin within its context with its initial state."""
39  super(PilzStatusIndicatorRqt, self).__init__(context)
40  self.setObjectName('PilzStatusIndicatorRqt')
41  self._widget = PilzStatusIndicatorWidget(context.serial_number())
42 
43  # Set initial widget state
44  self._widget.set_ROS_status(False)
45  self._widget.set_HW_status(False)
46 
47  self._widget.set_operation_mode(OperationModes.UNKNOWN)
48 
49  self._widget.set_speed(.5)
50 
51  # Subscribing to all informations we want to display
52  rospy.Subscriber(TOPIC_STATE_ROS, Bool, self.ros_status_callback)
53  rospy.Subscriber(TOPIC_STATE_HW, Bool,
54  self.hw_status_callback)
55  rospy.Subscriber(TOPIC_OPERATION_MODE, OperationModes,
57  rospy.Subscriber(TOPIC_SPEED_OVERRIDE, Float64, self.speed_callback)
58 
59  context.add_widget(self._widget)
60 
61  def hw_status_callback(self, msg):
62  """Callback for HW Status."""
63  self._widget.set_HW_status(msg.data)
64 
65  def ros_status_callback(self, msg):
66  """Callback for ROS Status."""
67  self._widget.set_ROS_status(msg.data)
68 
69  def operation_mode_callback(self, msg):
70  """Callback for Operation Mode."""
71  rospy.logdebug("set_operation_mode: " + str(msg))
72  self._widget.set_operation_mode(msg.value)
73 
74  def speed_callback(self, msg):
75  """Callback for Speed Override."""
76  val = msg.data
77  self._widget.set_speed(val)


pilz_status_indicator_rqt
Author(s):
autogenerated on Tue Feb 2 2021 03:50:27