8 import vigir_footstep_planning_msgs.msg
11 from python_qt_binding.QtCore
import Qt, QObject, Slot, QSignalMapper
12 from python_qt_binding.QtGui
import QHBoxLayout, QVBoxLayout, QCheckBox, QLineEdit, QPushButton, QDoubleSpinBox
14 from vigir_footstep_planning_msgs.msg
import StepPlanRequest, StepPlanRequestAction, StepPlanRequestGoal, StepPlanRequestResult, PatternParameters, Feet
24 super(StepInterfaceDialog, self).
__init__(context)
25 self.setObjectName(
'StepInterfaceDialog')
30 context.add_widget(self.
_parent)
33 self._widget.shutdown_plugin()
41 def __init__(self, context, add_execute_widget=True):
42 super(StepInterfaceWidget, self).
__init__()
51 self.
logger = Logger(error_status_widget)
55 controls_hbox = QHBoxLayout()
58 left_controls_vbox = QVBoxLayout()
59 left_controls_vbox.setMargin(0)
61 self.
add_command_button(left_controls_vbox,
"Rotate Left", PatternParameters.ROTATE_LEFT)
62 self.
add_command_button(left_controls_vbox,
"Strafe Left", PatternParameters.STRAFE_LEFT)
64 self.
add_command_button(left_controls_vbox,
"Center on Left", PatternParameters.FEET_REALIGN_ON_LEFT)
66 left_controls_vbox.addStretch()
67 controls_hbox.addLayout(left_controls_vbox, 1)
70 center_controls_vbox = QVBoxLayout()
71 center_controls_vbox.setMargin(0)
75 self.
add_command_button(center_controls_vbox,
"Step Over", PatternParameters.STEP_OVER)
76 self.
add_command_button(center_controls_vbox,
"Center Feet", PatternParameters.FEET_REALIGN_ON_CENTER)
77 self.
add_command_button(center_controls_vbox,
"Wide Stance", PatternParameters.WIDE_STANCE)
79 center_controls_vbox.addStretch()
80 controls_hbox.addLayout(center_controls_vbox, 1)
83 right_controls_vbox = QVBoxLayout()
84 right_controls_vbox.setMargin(0)
86 self.
add_command_button(right_controls_vbox,
"Rotate Right", PatternParameters.ROTATE_RIGHT)
87 self.
add_command_button(right_controls_vbox,
"Strafe Right", PatternParameters.STRAFE_RIGHT)
89 self.
add_command_button(right_controls_vbox,
"Center on Right", PatternParameters.FEET_REALIGN_ON_RIGHT)
91 right_controls_vbox.addStretch()
92 controls_hbox.addLayout(right_controls_vbox, 1)
95 add_layout_with_frame(vbox, controls_hbox,
"Commands:")
98 settings_hbox = QHBoxLayout()
99 settings_hbox.setMargin(0)
102 left_settings_vbox = QVBoxLayout()
103 left_settings_vbox.setMargin(0)
111 self.close_step_checkbox.setText(
"Do closing step")
112 self.close_step_checkbox.setChecked(
True)
117 self.extra_seperation_checkbox.setText(
"Extra Seperation")
118 self.extra_seperation_checkbox.setChecked(
False)
121 left_settings_vbox.addStretch()
125 add_widget_with_frame(left_settings_vbox, self.
step_number,
"Number Steps:")
129 add_widget_with_frame(left_settings_vbox, self.
start_step_index,
"Start Step Index:")
132 settings_hbox.addLayout(left_settings_vbox, 1)
135 center_settings_vbox = QVBoxLayout()
136 center_settings_vbox.setMargin(0)
140 self.start_foot_selection_combo_box.addItem(
"AUTO")
141 self.start_foot_selection_combo_box.addItem(
"LEFT")
142 self.start_foot_selection_combo_box.addItem(
"RIGHT")
145 center_settings_vbox.addStretch()
149 add_widget_with_frame(center_settings_vbox, self.
step_distance,
"Step Distance (m):")
152 self.
side_step = generate_q_double_spin_box(0.0, 0.0, 0.2, 2, 0.01)
153 add_widget_with_frame(center_settings_vbox, self.
side_step,
"Side Step (m):")
157 add_widget_with_frame(center_settings_vbox, self.
step_rotation,
"Step Rotation (deg):")
160 settings_hbox.addLayout(center_settings_vbox, 1)
163 right_settings_vbox = QVBoxLayout()
164 right_settings_vbox.setMargin(0)
167 self.
roll = generate_q_double_spin_box(0.0, -30.0, 30.0, 0, 1.0)
168 add_widget_with_frame(right_settings_vbox, self.
roll,
"Roll (deg):")
171 self.
pitch = generate_q_double_spin_box(0.0, -30.0, 30.0, 0, 1.0)
172 add_widget_with_frame(right_settings_vbox, self.
pitch,
"Pitch (deg):")
176 self.use_terrain_model_checkbox.setText(
"Use Terrain Model")
177 self.use_terrain_model_checkbox.setChecked(
False)
183 self.override_checkbox.setText(
"Override 3D")
184 self.override_checkbox.setChecked(
False)
187 right_settings_vbox.addStretch()
190 self.
dz = generate_q_double_spin_box(0.0, -0.5, 0.5, 2, 0.01)
191 add_widget_with_frame(right_settings_vbox, self.
dz,
"delta z per step (m):")
194 settings_hbox.addLayout(right_settings_vbox, 1)
197 add_layout_with_frame(vbox, settings_hbox,
"Settings:")
204 if add_execute_widget:
208 add_widget_with_frame(vbox, error_status_widget,
"Status:")
211 widget.setLayout(vbox)
215 self.parameter_set_widget.param_cleared_signal.connect(self.
param_cleared)
216 self.parameter_set_widget.param_changed_signal.connect(self.
param_selected)
229 print "Shutting down ..." 233 button = QPushButton(text)
234 self.command_mapper.setMapping(button, command)
235 button.clicked.connect(self.command_mapper.map)
236 parent.addWidget(button)
237 self.command_buttons.append(button)
245 params = PatternParameters()
246 params.steps = self.step_number.value()
247 params.mode = walk_command
248 params.close_step = self.close_step_checkbox.isChecked()
249 params.extra_seperation = self.extra_seperation_checkbox.isChecked()
250 params.use_terrain_model = self.use_terrain_model_checkbox.isChecked()
251 params.override = self.override_checkbox.isChecked()
and not self.use_terrain_model_checkbox.isChecked()
252 params.roll = math.radians(self.roll.value())
253 params.pitch = math.radians(self.pitch.value())
254 params.dz = self.dz.value()
256 params.step_distance_forward = self.step_distance.value()
257 params.step_distance_sideward = self.side_step.value()
258 params.turn_angle = math.radians(self.step_rotation.value())
260 request = StepPlanRequest()
261 request.header = std_msgs.msg.Header()
262 request.header.stamp = rospy.Time.now()
263 request.header.frame_id = self.frame_id_line_edit.text()
265 request.start_step_index = self.start_step_index.value()
267 if self.start_foot_selection_combo_box.currentText() ==
"AUTO":
268 request.start_foot_selection = StepPlanRequest.AUTO
269 elif self.start_foot_selection_combo_box.currentText() ==
"LEFT":
270 request.start_foot_selection = StepPlanRequest.LEFT
271 elif self.start_foot_selection_combo_box.currentText() ==
"RIGHT":
272 request.start_foot_selection = StepPlanRequest.RIGHT
274 self.logger.log_error(
"Unknown start foot selection mode ('" + self.start_foot_selection_combo_box.currentText() +
"')!")
277 if walk_command == PatternParameters.FORWARD:
278 params.mode = PatternParameters.SAMPLING
279 elif walk_command == PatternParameters.BACKWARD:
280 params.mode = PatternParameters.SAMPLING
281 params.step_distance_forward *= -1;
282 params.step_distance_sideward *= -1;
283 params.turn_angle *= -1;
285 request.pattern_parameters = params
286 request.planning_mode = StepPlanRequest.PLANNING_MODE_PATTERN
287 request.parameter_set_name.data = self.parameter_set_widget.current_parameter_set_name()
289 print "Send request = ", request
292 if self.step_plan_request_client.wait_for_server(rospy.Duration(0.5)):
293 self.logger.log_info(
"Sending footstep plan request...")
295 goal = StepPlanRequestGoal()
296 goal.plan_request = request;
297 self.step_plan_request_client.send_goal(goal)
299 if self.step_plan_request_client.wait_for_result(rospy.Duration(5.0)):
300 self.logger.log_info(
"Received footstep plan!")
301 self.logger.log(self.step_plan_request_client.get_result().status)
302 self.step_plan_pub.publish(self.step_plan_request_client.get_result().step_plan)
304 self.logger.log_error(
"Didn't received any results. Check communcation!")
306 self.logger.log_error(
"Can't connect to footstep planner action server!")
310 button.setEnabled(enable)
322 enable_override =
True 323 if state == Qt.Checked:
324 enable_override =
False 325 self.roll.setEnabled(enable_override)
326 self.pitch.setEnabled(enable_override)
327 self.override_checkbox.setEnabled(enable_override)
328 self.dz.setEnabled(enable_override)