node_controller.py
Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 
00003 import rospy
00004 
00005 
00006 # Provides callback functions for the start and stop buttons
00007 class NodeController(object):
00008 
00009     '''
00010     Containing both proxy and gui instances, this class gives a control of
00011     a node on both ROS & GUI sides.
00012     '''
00013 
00014     def __init__(self, proxy, gui):
00015         '''
00016         @type proxy: rqt_launch.NodeProxy
00017         @type gui: QWidget
00018         '''
00019         self._proxy = proxy
00020 
00021         self._gui = gui
00022         self._gui.set_node_controller(self)
00023 
00024     def start_stop_slot(self, signal):
00025         '''
00026         Works as a slot particularly intended to work for
00027         QAbstractButton::toggled(checked). Internally calls
00028         NodeController.start / stop depending on `signal`.
00029 
00030         @type signal: bool
00031         '''
00032         if self._proxy.is_running():
00033             self.stop()
00034             rospy.logdebug('---start_stop_slot stOP')
00035         else:
00036             self.start()
00037             rospy.logdebug('==start_stop_slot StART')
00038 
00039     def start(self, restart=True):
00040         '''
00041         Start a ROS node as a new _process.
00042         '''
00043         rospy.logdebug('Controller.start restart={}'.format(restart))
00044 
00045         # Should be almost unreachable under current design where this 'start'
00046         # method only gets called when _proxy.is_running() returns false.
00047 
00048         if self._proxy.is_running():
00049             if not restart:
00050                 # If the node is already running and restart isn't desired,
00051                 # do nothing further.
00052                 return
00053             # TODO: Need to consider...is stopping node here
00054             # (i.e. in 'start' method) good?
00055             self.stop()
00056 
00057         # If the launch_prefix has changed, then the _process must be recreated
00058         if (self._proxy.config.launch_prefix != self._gui._lineEdit_launch_args.text()):
00059             self._proxy.config.launch_prefix = self._gui._lineEdit_launch_args.text()
00060             self._proxy.recreate_process()
00061 
00062         self._gui.set_node_started(False)
00063         self._gui.label_status.set_starting()
00064         self._proxy.start_process()
00065         self._gui.label_status.set_running()
00066         self._gui.label_spawncount.setText("({})".format(self._proxy.get_spawn_count()))
00067 
00068     def stop(self):
00069         '''
00070         Stop a ROS node's _process.
00071         '''
00072 
00073         # TODO: Need to check if the node is really running.
00074 
00075         # if self._proxy.is_running():
00076         self._gui.set_node_started(True)
00077         self._gui.label_status.set_stopping()
00078         self._proxy.stop_process()
00079         self._gui.label_status.set_stopped()
00080 
00081     def check_process_status(self):
00082         if self._proxy.has_died():
00083             rospy.logerr("Process died: {}".format(self._proxy.get_proc_name()))
00084             self._proxy.stop_process()
00085             self._gui.set_node_started(True)
00086             if self._proxy._process.exit_code == 0:
00087                 self._gui.label_status.set_stopped()
00088             else:
00089                 self._gui.label_status.set_died()
00090 
00091             # Checks if it should be respawned
00092             if self._gui.respawn_toggle.isChecked():
00093                 rospy.loginfo("Respawning _process: {}".format(self._proxy._process.name))
00094                 self._gui.label_status.set_starting()
00095                 self._proxy.start_process()
00096                 self._gui.label_status.set_running()
00097                 self._gui.label_spawncount.setText("({})".format(
00098                     self._proxy._process.spawn_count))
00099 
00100     def get_node_widget(self):
00101         '''
00102         @rtype: QWidget
00103         '''
00104         return self._gui
00105 
00106     def is_node_running(self):
00107         return self._proxy.is_running()


rqt_launch
Author(s): Isaac Saito, Stuart Glaser
autogenerated on Thu Jun 6 2019 21:28:15