Go to the documentation of this file.00001
00002
00003 import rospy
00004
00005
00006
00007 class NodeController(object):
00008 '''
00009 Containing both proxy and gui instances, this class gives a control of
00010 a node on both ROS & GUI sides.
00011 '''
00012
00013
00014
00015 __slots__ = ['_proxy', '_gui']
00016
00017 def __init__(self, proxy, gui):
00018 '''
00019 @type proxy: rqt_launch.NodeProxy
00020 @type gui: QWidget
00021 '''
00022 self._proxy = proxy
00023
00024 self._gui = gui
00025 self._gui.set_node_controller(self)
00026
00027 def start_stop_slot(self, signal):
00028 '''
00029 Works as a slot particularly intended to work for
00030 QAbstractButton::toggled(checked). Internally calls
00031 NodeController.start / stop depending on `signal`.
00032
00033 @type signal: bool
00034 '''
00035 if self._proxy.is_running():
00036 self.stop()
00037 rospy.logdebug('---start_stop_slot stOP')
00038 else:
00039 self.start()
00040 rospy.logdebug('==start_stop_slot StART')
00041
00042 def start(self, restart=True):
00043 '''
00044 Start a ROS node as a new _process.
00045 '''
00046 rospy.logdebug('Controller.start restart={}'.format(restart))
00047
00048
00049
00050
00051 if self._proxy.is_running():
00052 if not restart:
00053
00054
00055 return
00056
00057
00058 self.stop()
00059
00060
00061 if (self._proxy.config.launch_prefix !=
00062 self._gui._lineEdit_launch_args.text()):
00063
00064 self._proxy.config.launch_prefix = \
00065 self._gui._lineEdit_launch_args.text()
00066 self._proxy.recreate_process()
00067
00068 self._gui.set_node_started(False)
00069 self._gui.label_status.set_starting()
00070 self._proxy.start_process()
00071 self._gui.label_status.set_running()
00072 self._gui.label_spawncount.setText("({})".format(
00073 self._proxy.get_spawn_count()))
00074
00075 def stop(self):
00076 '''
00077 Stop a ROS node's _process.
00078 '''
00079
00080
00081
00082
00083 self._gui.set_node_started(True)
00084 self._gui.label_status.set_stopping()
00085 self._proxy.stop_process()
00086 self._gui.label_status.set_stopped()
00087
00088 def check_process_status(self):
00089 if self._proxy.has_died():
00090 rospy.logerr("Process died: {}".format(
00091 self._proxy.get_proc_name()))
00092 self._proxy.stop_process()
00093 self._gui.set_node_started(True)
00094 if self._proxy._process.exit_code == 0:
00095 self._gui.label_status.set_stopped()
00096 else:
00097 self._gui.label_status.set_died()
00098
00099
00100 if self._gui.respawn_toggle.isChecked():
00101 rospy.loginfo("Respawning _process: {}".format(
00102 self._proxy._process.name))
00103 self._gui.label_status.set_starting()
00104 self._proxy.start_process()
00105 self._gui.label_status.set_running()
00106 self._gui.label_spawncount.setText("({})".format(
00107 self._proxy._process.spawn_count))
00108
00109 def get_node_widget(self):
00110 '''
00111 @rtype: QWidget
00112 '''
00113 return self._gui
00114
00115 def is_node_running(self):
00116 return self._proxy.is_running()