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(self._get_spawn_count_text())
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(self._get_spawn_count_text())
98 
99  def get_node_widget(self):
100  '''
101  @rtype: QWidget
102  '''
103  return self._gui
104 
105  def is_node_running(self):
106  return self._proxy.is_running()
107 
109  return "({})".format(self._proxy.get_spawn_count())


rqt_launch
Author(s): Isaac Saito, Stuart Glaser
autogenerated on Wed Oct 14 2020 03:50:59