pattern_generator_widget.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import math
4 
5 import rospy
6 import tf
7 import std_msgs.msg
8 
9 from rqt_gui_py.plugin import Plugin
10 from python_qt_binding.QtCore import Qt, Slot, QAbstractListModel
11 from python_qt_binding.QtGui import QWidget, QHBoxLayout, QVBoxLayout, QCheckBox, QLabel, QListWidget, QPushButton, QDoubleSpinBox, QFrame
12 
13 from vigir_footstep_planning_msgs.msg import PatternGeneratorParameters
17 
18 
20 
21  def __init__(self, context):
22  super(PatternGeneratorDialog, self).__init__(context)
23  self.setObjectName('PatternGeneratorDialog')
24 
25  self._parent = QWidget()
27 
28  context.add_widget(self._parent)
29 
30  def shutdown_plugin(self):
31  self._widget.shutdown_plugin()
32 
33 
34 class PatternGeneratorWidget(QObject):
35 
36  enable_pattern_generator = False
37 
38  def __init__(self, context):
39  super(PatternGeneratorWidget, self).__init__()
40 
41  # publisher
42  self.pattern_generator_params_pub = rospy.Publisher('pattern_generator/set_params', PatternGeneratorParameters, queue_size = 1)
43 
44  # start widget
45  widget = context
46 
47  # start upper part
48  hbox = QHBoxLayout()
49 
50  # start left column
51  left_vbox = QVBoxLayout()
52 
53  # start button
54  start_command = QPushButton("Start")
55  left_vbox.addWidget(start_command)
56 
57  # simulation checkbox
58  self.simulation_mode_checkbox = QCheckBox()
59  self.simulation_mode_checkbox.setText("Simulation Mode")
60  self.simulation_mode_checkbox.setChecked(False)
61  left_vbox.addWidget(self.simulation_mode_checkbox)
62 
63  # realtime checkbox
64  self.realtime_mode_checkbox = QCheckBox()
65  self.realtime_mode_checkbox.setText("Realtime Mode")
66  self.realtime_mode_checkbox.setChecked(False)
67  left_vbox.addWidget(self.realtime_mode_checkbox)
68 
69  # joystick checkbox
70  self.joystick_mode_checkbox = QCheckBox()
71  self.joystick_mode_checkbox.setText("Joystick Mode")
72  self.joystick_mode_checkbox.setChecked(False)
73  left_vbox.addWidget(self.joystick_mode_checkbox)
74 
75  # ignore invalid steps checkbox
76  self.ignore_invalid_steps_checkbox = QCheckBox()
77  self.ignore_invalid_steps_checkbox.setText("Ignore Invalid Steps")
78  self.ignore_invalid_steps_checkbox.setChecked(False)
79  left_vbox.addWidget(self.ignore_invalid_steps_checkbox)
80 
81  # foot seperation
82  self.foot_seperation = generate_q_double_spin_box(0.2, 0.15, 0.3, 2, 0.01)
83  self.foot_seperation.valueChanged.connect(self.callback_spin_box)
84  add_widget_with_frame(left_vbox, self.foot_seperation, "Foot Seperation (m):")
85 
86  # delta x
87  self.delta_x = generate_q_double_spin_box(0.0, -0.4, 0.4, 2, 0.01)
88  self.delta_x.valueChanged.connect(self.callback_spin_box)
89  add_widget_with_frame(left_vbox, self.delta_x, "dX (m):")
90 
91  # delta y
92  self.delta_y = generate_q_double_spin_box(0.0, -2.2, 2.2, 2, 0.01)
93  self.delta_y.valueChanged.connect(self.callback_spin_box)
94  add_widget_with_frame(left_vbox, self.delta_y, "dY (m):")
95 
96  # delta yaw
97  self.delta_yaw = generate_q_double_spin_box(0.0, -30.0, 30.0, 0, 1.0)
98  self.delta_yaw.valueChanged.connect(self.callback_spin_box)
99  add_widget_with_frame(left_vbox, self.delta_yaw, "dYaw (deg):")
100 
101  # roll
102  self.roll = generate_q_double_spin_box(0.0, -30.0, 30.0, 0, 1.0)
103  self.roll.valueChanged.connect(self.callback_spin_box)
104  add_widget_with_frame(left_vbox, self.roll, "Roll (deg):")
105 
106  # pitch
107  self.pitch = generate_q_double_spin_box(0.0, -30.0, 30.0, 0, 1.0)
108  self.pitch.valueChanged.connect(self.callback_spin_box)
109  add_widget_with_frame(left_vbox, self.pitch, "Pitch (deg):")
110 
111  # end left column
112  left_vbox.addStretch()
113  hbox.addLayout(left_vbox, 1)
114 
115  # start right column
116  right_vbox = QVBoxLayout()
117 
118  # stop button
119  stop_command = QPushButton("Stop")
120  right_vbox.addWidget(stop_command)
121 
122  # ignore collision
123  self.collision_checkbox = QCheckBox()
124  self.collision_checkbox.setText("Ignore Collision")
125  self.collision_checkbox.setChecked(True)
126  right_vbox.addWidget(self.collision_checkbox)
127 
128  # override 3D
129  self.override_checkbox = QCheckBox()
130  self.override_checkbox.setText("Override 3D")
131  self.override_checkbox.setChecked(False)
132  right_vbox.addWidget(self.override_checkbox)
133 
134  # end right coloumn
135  right_vbox.addStretch()
136  hbox.addLayout(right_vbox, 1)
137 
138  # add upper part
139  hbox.setMargin(0)
140  vbox = QVBoxLayout()
141  vbox.addLayout(hbox)
142 
143  # parameter set selection
145  add_widget_with_frame(vbox, self.parameter_set_widget, "Parameter Set:")
146 
147  # end widget
148  widget.setLayout(vbox)
149  #context.add_widget(widget)
150 
151  # signal connections
152  start_command.clicked.connect(self.start_command_callback)
153  stop_command.clicked.connect(self.stop_command_callback)
154  self.joystick_mode_checkbox.clicked.connect(self.joystick_mode_check_callback)
155  self.ignore_invalid_steps_checkbox.clicked.connect(self._publish_parameters)
156 
157  def shutdown_plugin(self):
158  print "Shutting down ..."
159  self.pattern_generator_params_pub.unregister()
160  print "Done!"
161 
162  # message publisher
164  params = PatternGeneratorParameters()
165 
166  params.enable = self.enable_pattern_generator
167  params.simulation_mode = self.simulation_mode_checkbox.isChecked()
168  params.joystick_mode = self.joystick_mode_checkbox.isChecked()
169  params.ignore_invalid_steps = self.ignore_invalid_steps_checkbox.isChecked()
170  params.d_step.position.x = self.delta_x.value()
171  params.d_step.position.y = self.delta_y.value()
172  params.d_step.position.z = 0
173  q = tf.transformations.quaternion_from_euler(math.radians(self.roll.value()), math.radians(self.pitch.value()), math.radians(self.delta_yaw.value()))
174  params.d_step.orientation.x = q[0]
175  params.d_step.orientation.y = q[1]
176  params.d_step.orientation.z = q[2]
177  params.d_step.orientation.w = q[3]
178  params.foot_seperation = self.foot_seperation.value()
179  params.parameter_set_name.data = self.parameter_set_widget.current_parameter_set_name()
180 
181  print "Send stepping command = \n",params
182  self.pattern_generator_params_pub.publish(params)
183 
184  # Define system command strings
187  self._publish_parameters()
188 
190  self.enable_pattern_generator = False
191  self._publish_parameters()
192 
193  def callback_spin_box(self, value_as_int):
194  if self.realtime_mode_checkbox.isChecked():
195  self._publish_parameters()
196 
198  self.enable_pattern_generator = False
199  self._publish_parameters()
200 


vigir_footstep_planning_widgets
Author(s): Alexander Stumpf
autogenerated on Mon Jun 10 2019 15:47:48