9 from python_qt_binding
import loadUi
10 from python_qt_binding.QtCore
import Signal
11 from python_qt_binding.QtGui
import QWidget, QHBoxLayout, QVBoxLayout, QPushButton, QComboBox
14 from vigir_footstep_planning_msgs.msg
import StepPlan, ExecuteStepPlanAction, ExecuteStepPlanGoal
24 execute_step_plan_client =
None 27 step_queue_size_signal = Signal(int)
28 executed_steps_signal = Signal(int)
30 def __init__(self, parent=None, logger=Logger(), step_plan_topic=str()):
31 super(QExecuteStepPlanWidget, self).
__init__(parent, logger)
36 vbox.setContentsMargins(0, 0, 0, 0)
39 if len(step_plan_topic) == 0:
40 step_plan_topic_widget =
QTopicWidget(topic_type=
'vigir_footstep_planning_msgs/StepPlan')
42 vbox.addWidget(step_plan_topic_widget)
47 execute_topic_widget =
QTopicWidget(topic_type=
'vigir_footstep_planning_msgs/ExecuteStepPlanAction', is_action_topic=
True)
49 vbox.addWidget(execute_topic_widget)
52 execute_step_plan_widget = QWidget()
54 ui_file = os.path.join(rp.get_path(
'vigir_footstep_planning_lib'),
'resource',
'execute_step_plan.ui')
55 loadUi(ui_file, execute_step_plan_widget, {
'QWidget': QWidget})
56 vbox.addWidget(execute_step_plan_widget)
72 self.execution_progress_bar.setFormat(
"0/0")
73 self.step_queue_size_signal.connect(self.execution_progress_bar.setMaximum)
74 self.executed_steps_signal.connect(self.execution_progress_bar.setValue)
91 if len(step_plan_topic) == 0:
92 step_plan_topic_widget.emit_topic_name()
93 execute_topic_widget.emit_topic_name()
96 self.execute_button.setEnabled(
False)
97 self.execute_button.setText(
"Execute [empty]")
98 self.repeat_button.setEnabled(
False)
99 self.repeat_button.setText(
"Repeat [empty]")
100 self.stop_button.setEnabled(
False)
101 self.execution_progress_bar.reset()
102 self.execution_progress_bar.setFormat(
"0/0")
103 self.status_line_edit.setText(
"N/A")
104 self.step_queue_line_edit.setText(
"N/A [empty]")
105 self.first_changeable_step_line_edit.setText(
"N/A")
108 print "Shutting down ..." 110 self.step_plan_sub.unregister()
114 if len(topic_name) > 0:
116 self.step_plan_sub.unregister()
118 print "Step Plan topic changed: " + topic_name
121 if len(topic_name) > 0:
123 self.execute_button.setEnabled(self.
step_plan is not None)
124 self.repeat_button.setEnabled(
False)
125 self.stop_button.setEnabled(
False)
126 print "Execution topic changed: " + topic_name
129 if not len(step_plan.steps):
133 self.execute_button.setText(
"Execute [" + str(self.step_plan.steps[0].step_index) +
"; " +
134 str(self.step_plan.steps[-1].step_index) +
"]")
139 if self.execute_step_plan_client.wait_for_server(rospy.Duration(0.5)):
142 self.repeat_button.setEnabled(
True)
143 self.repeat_button.setText(
"Repeat [" + str(self.step_plan.steps[0].step_index) +
"; " +
144 str(self.step_plan.steps[-1].step_index) +
"]")
145 self.stop_button.setEnabled(
True)
146 self.step_queue_size_signal.emit(0)
148 self.logger.log_info(
"Requesting footstep plan execution...")
149 goal = ExecuteStepPlanGoal()
153 self.logger.log_error(
"Can't connect to footstep controller action server!")
156 self.stop_button.setEnabled(
False)
157 self.execute_step_plan_client.cancel_goal()
158 self.logger.log_info(
"Preempting step plan.")
162 self.logger.log_info(
"Execution of step plan started.")
166 self.stop_button.setEnabled(
False)
168 self.logger.log_info(
"Execution of step plan finished.")
170 self.stop_button.setEnabled(
False)
171 self.step_queue_size_signal.emit(len(self.step_plan.steps))
172 self.status_line_edit.setText(
"FAILED")
173 self.logger.log_error(
"Execution of step plan failed!")
178 if feedback.last_performed_step_index >= 0:
179 if feedback.queue_size > 0:
180 self.step_queue_size_signal.emit(feedback.last_queued_step_index)
181 self.executed_steps_signal.emit(feedback.last_performed_step_index)
182 self.execution_progress_bar.setFormat(str(feedback.last_performed_step_index) +
"/" +
183 str(self.execution_progress_bar.maximum()))
186 self.status_line_edit.setText(walk_controller_state_to_string(feedback.controller_state))
188 if feedback.queue_size > 0:
189 self.step_queue_line_edit.setText(str(feedback.currently_executing_step_index) +
" [" +
190 str(feedback.first_queued_step_index) +
"; " +
191 str(feedback.last_queued_step_index) +
"]")
193 self.first_changeable_step_line_edit.setText(str(feedback.first_changeable_step_index))
195 self.step_queue_line_edit.setText(
"N/A [empty]")
196 self.first_changeable_step_line_edit.setText(
"N/A")