Added callback handler and connected threads using pyqt signals
This commit is contained in:
parent
e250dbc833
commit
09d9f6b653
@ -1,7 +1,7 @@
|
|||||||
<launch>
|
<launch>
|
||||||
<node pkg="rqt_gui"
|
<node pkg="rqt_gui"
|
||||||
type="rqt_gui"
|
type="rqt_gui"
|
||||||
name="rqt_gui"
|
name="master_rqt_gui"
|
||||||
args="--standalone safety_master_plugin"
|
args="--standalone safety_master_plugin"
|
||||||
/>
|
/>
|
||||||
</launch>
|
</launch>
|
21
safety_master_plugin/scripts/master_callback_handler.py
Normal file
21
safety_master_plugin/scripts/master_callback_handler.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
from python_qt_binding.QtCore import QObject
|
||||||
|
from python_qt_binding.QtCore import pyqtSignal
|
||||||
|
from robot_info import RobotInfo
|
||||||
|
|
||||||
|
class CallbackHandler(QObject):
|
||||||
|
robot_info_signal = pyqtSignal(object)
|
||||||
|
add_robot_signal = pyqtSignal(int)
|
||||||
|
remove_robot_signal = pyqtSignal(int)
|
||||||
|
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super(CallbackHandler, self).__init__()
|
||||||
|
|
||||||
|
def connect_robot_info_signal(self,slot):
|
||||||
|
self.robot_info_signal.connect(slot)
|
||||||
|
|
||||||
|
def connect_add_robot_signal(self,slot):
|
||||||
|
self.add_robot_signal.connect(slot)
|
||||||
|
|
||||||
|
def connect_remove_robot_signal(self,slot):
|
||||||
|
self.remove_robot_signal.connect(slot)
|
@ -9,6 +9,8 @@ from qt_gui.plugin import Plugin
|
|||||||
|
|
||||||
from enums.stop_state import StopState as SS
|
from enums.stop_state import StopState as SS
|
||||||
|
|
||||||
|
from master_callback_handler import CallbackHandler
|
||||||
|
|
||||||
class MasterPlugin(Plugin):
|
class MasterPlugin(Plugin):
|
||||||
|
|
||||||
def __init__(self,context):
|
def __init__(self,context):
|
||||||
@ -20,6 +22,11 @@ class MasterPlugin(Plugin):
|
|||||||
self._qt_wrapper = QtWrapper(self._widget)
|
self._qt_wrapper = QtWrapper(self._widget)
|
||||||
self._master_info = MasterInfo()
|
self._master_info = MasterInfo()
|
||||||
|
|
||||||
|
self.cbhandler = CallbackHandler()
|
||||||
|
self.cbhandler.connect_robot_info_signal(self._qt_wrapper.update_robot_info)
|
||||||
|
self.cbhandler.connect_add_robot_signal(self._qt_wrapper.add_robot)
|
||||||
|
self.cbhandler.connect_remove_robot_signal(self._qt_wrapper.remove_robot)
|
||||||
|
|
||||||
|
|
||||||
# self._qt_wrapper.connect_signals()
|
# self._qt_wrapper.connect_signals()
|
||||||
# self._qt_wrapper.set_sliders_to_initial_values()
|
# self._qt_wrapper.set_sliders_to_initial_values()
|
||||||
@ -66,24 +73,34 @@ class MasterPlugin(Plugin):
|
|||||||
self.restrictions_changed(restrictions)
|
self.restrictions_changed(restrictions)
|
||||||
|
|
||||||
def update_robots_list(self,robots_id_list):
|
def update_robots_list(self,robots_id_list):
|
||||||
|
|
||||||
|
for robot_id in robots_id_list:
|
||||||
|
if robot_id not in self._master_info.robots_id_list:
|
||||||
|
self.new_robot_registered(robot_id)
|
||||||
|
|
||||||
|
for robot_id in self._master_info.robots_id_list:
|
||||||
|
if robot_id not in robots_id_list:
|
||||||
|
self.robot_unregistered(robot_id)
|
||||||
|
|
||||||
self._master_info.robots_id_list = robots_id_list
|
self._master_info.robots_id_list = robots_id_list
|
||||||
self._qt_wrapper.update_robots_list_gui(robots_id_list)
|
|
||||||
# raise NotImplementedError
|
|
||||||
|
|
||||||
def new_robot_registered(self,robot_id):
|
def new_robot_registered(self,robot_id):
|
||||||
raise NotImplementedError
|
# raise NotImplementedError
|
||||||
# self._qt_wrapper.add_robot_subscriber(robot_id)
|
|
||||||
self._ros_wrapper.add_robot_subscriber(robot_id)
|
self._ros_wrapper.add_robot_subscriber(robot_id)
|
||||||
|
self.cbhandler.add_robot_signal.emit(robot_id)
|
||||||
|
# self._qt_wrapper.add_robot(robot_id)
|
||||||
|
|
||||||
def robot_unregistered(self,robot_id):
|
def robot_unregistered(self,robot_id):
|
||||||
raise NotImplementedError
|
# raise NotImplementedError
|
||||||
# self._qt_wrapper.remove_robot_subscriber(robot_id)
|
|
||||||
self._ros_wrapper.remove_robot_subscriber(robot_id)
|
self._ros_wrapper.remove_robot_subscriber(robot_id)
|
||||||
|
self.cbhandler.remove_robot_signal.emit(robot_id)
|
||||||
|
# self._qt_wrapper.remove_robot(robot_id)
|
||||||
|
|
||||||
def update_robot_info(self,robot_info):
|
def update_robot_info(self,robot_info):
|
||||||
# TODO emit signal to qt_wrapper where it will update info about one of robots
|
# TODO emit signal to qt_wrapper where it will update info about one of robots
|
||||||
self._qt_wrapper.update_robot_info(self,robot_info)
|
# self._qt_wrapper.update_robot_info(self,robot_info)
|
||||||
raise NotImplementedError
|
# raise NotImplementedError
|
||||||
|
self.cbhandler.robot_info_signal.emit(robot_info)
|
||||||
|
|
||||||
def master_started(self):
|
def master_started(self):
|
||||||
self._master_info.master_stop_state = SS.RUNNING
|
self._master_info.master_stop_state = SS.RUNNING
|
||||||
|
@ -125,6 +125,10 @@ class QtWrapper:
|
|||||||
self.add_robot_to_list(robot_id)
|
self.add_robot_to_list(robot_id)
|
||||||
|
|
||||||
|
|
||||||
|
def update_robot_info(self,robot_info):
|
||||||
|
self.log_info(str(robot_info.robot_id))
|
||||||
|
# raise NotImplementedError
|
||||||
|
|
||||||
# def remove_robot_from_list(self,robot_id):
|
# def remove_robot_from_list(self,robot_id):
|
||||||
# count = self.widget.robotsList.count()
|
# count = self.widget.robotsList.count()
|
||||||
|
|
||||||
@ -151,6 +155,15 @@ class QtWrapper:
|
|||||||
self.log_info('Przycisk masterSTOP odcisniety')
|
self.log_info('Przycisk masterSTOP odcisniety')
|
||||||
|
|
||||||
|
|
||||||
|
def add_robot(self,robot_id):
|
||||||
|
self.log_info('PIONIER{0} polaczony'.format(robot_id))
|
||||||
|
self.displayed_robots_id_list.append(robot_id)
|
||||||
|
|
||||||
|
def remove_robot(self,robot_id):
|
||||||
|
self.log_info('PIONIER{0} rozlaczony'.format(robot_id))
|
||||||
|
self.displayed_robots_id_list.remove(robot_id)
|
||||||
|
|
||||||
|
|
||||||
def log_info(self,info_text):
|
def log_info(self,info_text):
|
||||||
time = datetime.datetime.now().strftime('[%H:%M:%S]')
|
time = datetime.datetime.now().strftime('[%H:%M:%S]')
|
||||||
|
|
||||||
|
@ -35,8 +35,8 @@ class ROSWrapper:
|
|||||||
self.connection_timer = None
|
self.connection_timer = None
|
||||||
self.master_connection_timer = None
|
self.master_connection_timer = None
|
||||||
|
|
||||||
def setup_node(self):
|
# def setup_node(self):
|
||||||
rospy.init_node('safety_user_plugin', anonymous=True)
|
# rospy.init_node('safety_user_plugin', anonymous=True)
|
||||||
|
|
||||||
def setup_subscribers_and_publishers(self,robot_id):
|
def setup_subscribers_and_publishers(self,robot_id):
|
||||||
robot_name = 'PIONIER' + str(robot_id)
|
robot_name = 'PIONIER' + str(robot_id)
|
||||||
|
Loading…
Reference in New Issue
Block a user