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     Containing both proxy and gui instances, this class gives a control of
00010     a node on both ROS & GUI sides.
00011     '''
00012 
00013     # these values need to synch with member variables.
00014     # Eg. self.gui isn't legal.
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         # Should be almost unreachable under current design where this 'start'
00049         # method only gets called when _proxy.is_running() returns false.
00050 
00051         if self._proxy.is_running():
00052             if not restart:
00053                 # If the node is already running and restart isn't desired,
00054                 # do nothing further.
00055                 return
00056             #TODO: Need to consider...is stopping node here
00057             # (i.e. in 'start' method) good?
00058             self.stop()
00059 
00060         # If the launch_prefix has changed, then the _process must be recreated
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         #TODO: Need to check if the node is really running.
00081 
00082         #if self._proxy.is_running():
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             # Checks if it should be respawned
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()


rqt_launch
Author(s): Isaac Saito , Stuart Glaser
autogenerated on Mon Oct 6 2014 07:15:40