node_controller.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 import rospy
4 
5 
6 # Provides callback functions for the start and stop buttons
7 class NodeController(object):
8 
9  '''
10  Containing both proxy and gui instances, this class gives a control of
11  a node on both ROS & GUI sides.
12  '''
13 
14  def __init__(self, proxy, gui):
15  '''
16  @type proxy: rqt_launch.NodeProxy
17  @type gui: QWidget
18  '''
19  self._proxy = proxy
20 
21  self._gui = gui
22  self._gui.set_node_controller(self)
23 
24  def start_stop_slot(self, signal):
25  '''
26  Works as a slot particularly intended to work for
27  QAbstractButton::toggled(checked). Internally calls
28  NodeController.start / stop depending on `signal`.
29 
30  @type signal: bool
31  '''
32  if self._proxy.is_running():
33  self.stop()
34  rospy.logdebug('---start_stop_slot stOP')
35  else:
36  self.start()
37  rospy.logdebug('==start_stop_slot StART')
38 
39  def start(self, restart=True):
40  '''
41  Start a ROS node as a new _process.
42  '''
43  rospy.logdebug('Controller.start restart={}'.format(restart))
44 
45  # Should be almost unreachable under current design where this 'start'
46  # method only gets called when _proxy.is_running() returns false.
47 
48  if self._proxy.is_running():
49  if not restart:
50  # If the node is already running and restart isn't desired,
51  # do nothing further.
52  return
53  # TODO: Need to consider...is stopping node here
54  # (i.e. in 'start' method) good?
55  self.stop()
56 
57  # If the launch_prefix has changed, then the _process must be recreated
58  if (self._proxy.config.launch_prefix != self._gui._lineEdit_launch_args.text()):
59  self._proxy.config.launch_prefix = self._gui._lineEdit_launch_args.text()
60  self._proxy.recreate_process()
61 
62  self._gui.set_node_started(False)
63  self._gui.label_status.set_starting()
64  self._proxy.start_process()
65  self._gui.label_status.set_running()
66  self._gui.label_spawncount.setText("({})".format(self._proxy.get_spawn_count()))
67 
68  def stop(self):
69  '''
70  Stop a ROS node's _process.
71  '''
72 
73  # TODO: Need to check if the node is really running.
74 
75  # if self._proxy.is_running():
76  self._gui.set_node_started(True)
77  self._gui.label_status.set_stopping()
78  self._proxy.stop_process()
79  self._gui.label_status.set_stopped()
80 
82  if self._proxy.has_died():
83  rospy.logerr("Process died: {}".format(self._proxy.get_proc_name()))
84  self._proxy.stop_process()
85  self._gui.set_node_started(True)
86  if self._proxy._process.exit_code == 0:
87  self._gui.label_status.set_stopped()
88  else:
89  self._gui.label_status.set_died()
90 
91  # Checks if it should be respawned
92  if self._gui.respawn_toggle.isChecked():
93  rospy.loginfo("Respawning _process: {}".format(self._proxy._process.name))
94  self._gui.label_status.set_starting()
95  self._proxy.start_process()
96  self._gui.label_status.set_running()
97  self._gui.label_spawncount.setText("({})".format(
98  self._proxy._process.spawn_count))
99 
100  def get_node_widget(self):
101  '''
102  @rtype: QWidget
103  '''
104  return self._gui
105 
106  def is_node_running(self):
107  return self._proxy.is_running()


rqt_launch
Author(s): Isaac Saito, Stuart Glaser
autogenerated on Wed Jun 5 2019 21:35:22