Blame view
redpitaya/client/pid_vco.py
15.1 KB
145da201a - |
1 2 3 4 |
#!/usr/bin/env python2 # -*- coding: utf-8 -*- ################################################## # GNU Radio Python Flow Graph |
a60abb54d prepare to deploy |
5 6 |
# Title: Pid Vco # Generated: Tue Apr 11 15:32:11 2017 |
145da201a - |
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
################################################## if __name__ == '__main__': import ctypes import sys if sys.platform.startswith('linux'): try: x11 = ctypes.cdll.LoadLibrary('libX11.so') x11.XInitThreads() except: print "Warning: failed to XInitThreads()" from PyQt4 import Qt from gnuradio import eng_notation from gnuradio import gr from gnuradio.eng_option import eng_option from gnuradio.filter import firdes from gnuradio.qtgui import Range, RangeWidget from optparse import OptionParser import redpitaya_gnuradio import sys |
a60abb54d prepare to deploy |
28 |
class pid_vco(gr.top_block, Qt.QWidget): |
145da201a - |
29 30 |
def __init__(self): |
a60abb54d prepare to deploy |
31 |
gr.top_block.__init__(self, "Pid Vco") |
145da201a - |
32 |
Qt.QWidget.__init__(self) |
a60abb54d prepare to deploy |
33 |
self.setWindowTitle("Pid Vco") |
145da201a - |
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) |
a60abb54d prepare to deploy |
49 |
self.settings = Qt.QSettings("GNU Radio", "pid_vco") |
145da201a - |
50 51 52 53 54 55 |
self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.port = port = 1001 |
a60abb54d prepare to deploy |
56 57 |
self.poff = poff = 0 self.pinc = pinc = 0 |
145da201a - |
58 |
self.pid_sign = pid_sign = 0 |
a60abb54d prepare to deploy |
59 60 |
self.pid_setpoint = pid_setpoint = 0 self.pid_rst_int = pid_rst_int = 0 |
145da201a - |
61 62 63 |
self.pid_kp = pid_kp = 0 self.pid_ki = pid_ki = 0 self.pid_kd = pid_kd = 0 |
a60abb54d prepare to deploy |
64 |
self.dds_range = dds_range = 0 |
145da201a - |
65 66 67 68 69 |
self.dds_offset = dds_offset = 0 self.dds_nco = dds_nco = 0 self.dds_f0 = dds_f0 = 0 self.dds_ampl = dds_ampl = 0 self.dac1_offset = dac1_offset = 0 |
a60abb54d prepare to deploy |
70 |
self.addr = addr = "192.168.0.203" |
145da201a - |
71 72 73 74 75 |
self.adc1_offset = adc1_offset = 0 ################################################## # Blocks ################################################## |
a60abb54d prepare to deploy |
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
_poff_check_box = Qt.QCheckBox('poff') self._poff_choices = {True: 1, False: 0} self._poff_choices_inv = dict((v,k) for k,v in self._poff_choices.iteritems()) self._poff_callback = lambda i: Qt.QMetaObject.invokeMethod(_poff_check_box, "setChecked", Qt.Q_ARG("bool", self._poff_choices_inv[i])) self._poff_callback(self.poff) _poff_check_box.stateChanged.connect(lambda i: self.set_poff(self._poff_choices[bool(i)])) self.top_grid_layout.addWidget(_poff_check_box, 2, 4) _pinc_check_box = Qt.QCheckBox('pinc') self._pinc_choices = {True: 1, False: 0} self._pinc_choices_inv = dict((v,k) for k,v in self._pinc_choices.iteritems()) self._pinc_callback = lambda i: Qt.QMetaObject.invokeMethod(_pinc_check_box, "setChecked", Qt.Q_ARG("bool", self._pinc_choices_inv[i])) self._pinc_callback(self.pinc) _pinc_check_box.stateChanged.connect(lambda i: self.set_pinc(self._pinc_choices[bool(i)])) self.top_grid_layout.addWidget(_pinc_check_box, 1, 4) |
145da201a - |
90 91 92 93 94 95 96 |
_pid_sign_check_box = Qt.QCheckBox('pid_sign') self._pid_sign_choices = {True: 1, False: 0} self._pid_sign_choices_inv = dict((v,k) for k,v in self._pid_sign_choices.iteritems()) self._pid_sign_callback = lambda i: Qt.QMetaObject.invokeMethod(_pid_sign_check_box, "setChecked", Qt.Q_ARG("bool", self._pid_sign_choices_inv[i])) self._pid_sign_callback(self.pid_sign) _pid_sign_check_box.stateChanged.connect(lambda i: self.set_pid_sign(self._pid_sign_choices[bool(i)])) self.top_grid_layout.addWidget(_pid_sign_check_box, 3, 2) |
a60abb54d prepare to deploy |
97 98 99 100 101 102 103 104 |
self._pid_setpoint_range = Range(-2**13, 2**13-1, 1, 0, 200) self._pid_setpoint_win = RangeWidget(self._pid_setpoint_range, self.set_pid_setpoint, 'pid_setpoint', "counter_slider", int) self.top_grid_layout.addWidget(self._pid_setpoint_win, 2, 2) _pid_rst_int_push_button = Qt.QPushButton('pid_rst_int') self._pid_rst_int_choices = {'Pressed': 1, 'Released': 0} _pid_rst_int_push_button.pressed.connect(lambda: self.set_pid_rst_int(self._pid_rst_int_choices['Pressed'])) _pid_rst_int_push_button.released.connect(lambda: self.set_pid_rst_int(self._pid_rst_int_choices['Released'])) self.top_grid_layout.addWidget(_pid_rst_int_push_button, 4, 2) |
145da201a - |
105 106 107 108 109 110 111 112 113 |
self._pid_kp_range = Range(0, 2**14-1, 1, 0, 200) self._pid_kp_win = RangeWidget(self._pid_kp_range, self.set_pid_kp, 'pid_kp', "counter_slider", int) self.top_grid_layout.addWidget(self._pid_kp_win, 2, 1) self._pid_ki_range = Range(0, 2**14-1, 1, 0, 200) self._pid_ki_win = RangeWidget(self._pid_ki_range, self.set_pid_ki, 'pid_ki', "counter_slider", int) self.top_grid_layout.addWidget(self._pid_ki_win, 3, 1) self._pid_kd_range = Range(0, 2**14-1, 1, 0, 200) self._pid_kd_win = RangeWidget(self._pid_kd_range, self.set_pid_kd, 'pid_kd', "counter_slider", int) self.top_grid_layout.addWidget(self._pid_kd_win, 4, 1) |
a60abb54d prepare to deploy |
114 115 116 |
self._dds_range_range = Range(-2**13, 2**13-1, 1, 0, 200) self._dds_range_win = RangeWidget(self._dds_range_range, self.set_dds_range, 'dds_range', "counter_slider", int) self.top_grid_layout.addWidget(self._dds_range_win, 5, 3) |
145da201a - |
117 118 119 120 121 122 |
self._dds_offset_range = Range(-2**13, 2**13-1, 1, 0, 200) self._dds_offset_win = RangeWidget(self._dds_offset_range, self.set_dds_offset, 'dds_offset', "counter_slider", int) self.top_grid_layout.addWidget(self._dds_offset_win, 3, 3) self._dds_nco_range = Range(0, 60000000, 1, 0, 200) self._dds_nco_win = RangeWidget(self._dds_nco_range, self.set_dds_nco, 'dds_nco', "counter_slider", int) self.top_grid_layout.addWidget(self._dds_nco_win, 2, 3) |
a60abb54d prepare to deploy |
123 |
self._dds_f0_range = Range(0, 60000000, 1, 0, 200) |
145da201a - |
124 125 |
self._dds_f0_win = RangeWidget(self._dds_f0_range, self.set_dds_f0, 'dds_f0', "counter_slider", int) self.top_grid_layout.addWidget(self._dds_f0_win, 4, 3) |
a60abb54d prepare to deploy |
126 |
self._dds_ampl_range = Range(0, 2**13-1, 1, 0, 200) |
145da201a - |
127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
self._dds_ampl_win = RangeWidget(self._dds_ampl_range, self.set_dds_ampl, 'dds_ampl', "counter_slider", int) self.top_grid_layout.addWidget(self._dds_ampl_win, 1, 3) self._dac1_offset_range = Range(-2**13, 2**13-1, 1, 0, 200) self._dac1_offset_win = RangeWidget(self._dac1_offset_range, self.set_dac1_offset, 'dac1_offset', "counter_slider", int) self.top_grid_layout.addWidget(self._dac1_offset_win, 1, 2) self._adc1_offset_range = Range(-2**13, 2**13-1, 1, 0, 200) self._adc1_offset_win = RangeWidget(self._adc1_offset_range, self.set_adc1_offset, 'adc1_offset', "counter_slider", int) self.top_grid_layout.addWidget(self._adc1_offset_win, 1, 1) self.nco_counter_send_conf_0 = redpitaya_gnuradio.nco_counter_send_conf( addr=addr, port=port, device='/dev/dds_nco', freq_ref=125000000, freq_dds=dds_nco, |
a60abb54d prepare to deploy |
141 |
acc_size=32, |
145da201a - |
142 |
offset=0, |
a60abb54d prepare to deploy |
143 144 |
pinc_sw=pinc, poff_sw=poff, |
145da201a - |
145 146 147 148 149 |
) self.add_const_set_offset_0_0_0_1_0_0_0_0_0 = redpitaya_gnuradio.add_const_set_offset( addr=addr, port=port, |
a60abb54d prepare to deploy |
150 151 |
device='/dev/pid_rst_int', const=pid_rst_int, |
145da201a - |
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
) self.add_const_set_offset_0_0_0_1_0_0_0_0 = redpitaya_gnuradio.add_const_set_offset( addr=addr, port=port, device='/dev/pid_sign', const=pid_sign, ) self.add_const_set_offset_0_0_0_1_0_0_0 = redpitaya_gnuradio.add_const_set_offset( addr=addr, port=port, device='/dev/pid_kd', const=pid_kd, ) self.add_const_set_offset_0_0_0_1_0_0 = redpitaya_gnuradio.add_const_set_offset( addr=addr, port=port, device='/dev/pid_ki', const=pid_ki, ) self.add_const_set_offset_0_0_0_1_0 = redpitaya_gnuradio.add_const_set_offset( addr=addr, port=port, device='/dev/pid_kp', const=pid_kp, ) self.add_const_set_offset_0_0_0_1 = redpitaya_gnuradio.add_const_set_offset( addr=addr, port=port, |
a60abb54d prepare to deploy |
185 186 187 188 189 190 191 192 193 |
device='/dev/pid_setpoint', const=pid_setpoint, ) self.add_const_set_offset_0_0_0_0_1_0_0 = redpitaya_gnuradio.add_const_set_offset( addr=addr, port=port, device='/dev/dds_range', const=dds_range, |
145da201a - |
194 195 196 197 198 199 |
) self.add_const_set_offset_0_0_0_0_1_0 = redpitaya_gnuradio.add_const_set_offset( addr=addr, port=port, device='/dev/dds_f0', |
a60abb54d prepare to deploy |
200 |
const=int(dds_f0/(125e6/2**32)), |
145da201a - |
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
) self.add_const_set_offset_0_0_0_0_1 = redpitaya_gnuradio.add_const_set_offset( addr=addr, port=port, device='/dev/dds_offset', const=dds_offset, ) self.add_const_set_offset_0_0_0_0_0 = redpitaya_gnuradio.add_const_set_offset( addr=addr, port=port, device='/dev/dds_ampl', const=dds_ampl, ) self.add_const_set_offset_0_0_0_0 = redpitaya_gnuradio.add_const_set_offset( addr=addr, port=port, device='/dev/dac1_offset', const=dac1_offset, ) self.add_const_set_offset_0_0_0 = redpitaya_gnuradio.add_const_set_offset( addr=addr, port=port, device='/dev/adc1_offset', const=adc1_offset, ) def closeEvent(self, event): |
a60abb54d prepare to deploy |
233 |
self.settings = Qt.QSettings("GNU Radio", "pid_vco") |
145da201a - |
234 235 236 237 238 239 240 241 |
self.settings.setValue("geometry", self.saveGeometry()) event.accept() def get_port(self): return self.port def set_port(self, port): self.port = port |
a60abb54d prepare to deploy |
242 243 244 245 246 247 248 |
def get_poff(self): return self.poff def set_poff(self, poff): self.poff = poff self._poff_callback(self.poff) self.nco_counter_send_conf_0.set_nco(device='/dev/dds_nco', freq_ref=125000000, freq_dds=self.dds_nco, acc_size=32, offset=0, pinc_sw=self.pinc, poff_sw=self.poff) |
145da201a - |
249 |
|
a60abb54d prepare to deploy |
250 251 252 253 254 255 256 |
def get_pinc(self): return self.pinc def set_pinc(self, pinc): self.pinc = pinc self._pinc_callback(self.pinc) self.nco_counter_send_conf_0.set_nco(device='/dev/dds_nco', freq_ref=125000000, freq_dds=self.dds_nco, acc_size=32, offset=0, pinc_sw=self.pinc, poff_sw=self.poff) |
145da201a - |
257 258 259 260 261 262 263 264 |
def get_pid_sign(self): return self.pid_sign def set_pid_sign(self, pid_sign): self.pid_sign = pid_sign self._pid_sign_callback(self.pid_sign) self.add_const_set_offset_0_0_0_1_0_0_0_0.set_const(device='/dev/pid_sign', const=self.pid_sign) |
a60abb54d prepare to deploy |
265 266 267 268 269 270 271 272 273 274 275 276 277 |
def get_pid_setpoint(self): return self.pid_setpoint def set_pid_setpoint(self, pid_setpoint): self.pid_setpoint = pid_setpoint self.add_const_set_offset_0_0_0_1.set_const(device='/dev/pid_setpoint', const=self.pid_setpoint) def get_pid_rst_int(self): return self.pid_rst_int def set_pid_rst_int(self, pid_rst_int): self.pid_rst_int = pid_rst_int self.add_const_set_offset_0_0_0_1_0_0_0_0_0.set_const(device='/dev/pid_rst_int', const=self.pid_rst_int) |
145da201a - |
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
def get_pid_kp(self): return self.pid_kp def set_pid_kp(self, pid_kp): self.pid_kp = pid_kp self.add_const_set_offset_0_0_0_1_0.set_const(device='/dev/pid_kp', const=self.pid_kp) def get_pid_ki(self): return self.pid_ki def set_pid_ki(self, pid_ki): self.pid_ki = pid_ki self.add_const_set_offset_0_0_0_1_0_0.set_const(device='/dev/pid_ki', const=self.pid_ki) def get_pid_kd(self): return self.pid_kd def set_pid_kd(self, pid_kd): self.pid_kd = pid_kd self.add_const_set_offset_0_0_0_1_0_0_0.set_const(device='/dev/pid_kd', const=self.pid_kd) |
a60abb54d prepare to deploy |
298 299 |
def get_dds_range(self): return self.dds_range |
145da201a - |
300 |
|
a60abb54d prepare to deploy |
301 302 303 |
def set_dds_range(self, dds_range): self.dds_range = dds_range self.add_const_set_offset_0_0_0_0_1_0_0.set_const(device='/dev/dds_range', const=self.dds_range) |
145da201a - |
304 305 306 307 308 309 310 311 312 313 314 315 316 |
def get_dds_offset(self): return self.dds_offset def set_dds_offset(self, dds_offset): self.dds_offset = dds_offset self.add_const_set_offset_0_0_0_0_1.set_const(device='/dev/dds_offset', const=self.dds_offset) def get_dds_nco(self): return self.dds_nco def set_dds_nco(self, dds_nco): self.dds_nco = dds_nco |
a60abb54d prepare to deploy |
317 |
self.nco_counter_send_conf_0.set_nco(device='/dev/dds_nco', freq_ref=125000000, freq_dds=self.dds_nco, acc_size=32, offset=0, pinc_sw=self.pinc, poff_sw=self.poff) |
145da201a - |
318 319 320 321 322 323 |
def get_dds_f0(self): return self.dds_f0 def set_dds_f0(self, dds_f0): self.dds_f0 = dds_f0 |
a60abb54d prepare to deploy |
324 |
self.add_const_set_offset_0_0_0_0_1_0.set_const(device='/dev/dds_f0', const=int(self.dds_f0/(125e6/2**32))) |
145da201a - |
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
def get_dds_ampl(self): return self.dds_ampl def set_dds_ampl(self, dds_ampl): self.dds_ampl = dds_ampl self.add_const_set_offset_0_0_0_0_0.set_const(device='/dev/dds_ampl', const=self.dds_ampl) def get_dac1_offset(self): return self.dac1_offset def set_dac1_offset(self, dac1_offset): self.dac1_offset = dac1_offset self.add_const_set_offset_0_0_0_0.set_const(device='/dev/dac1_offset', const=self.dac1_offset) def get_addr(self): return self.addr def set_addr(self, addr): self.addr = addr def get_adc1_offset(self): return self.adc1_offset def set_adc1_offset(self, adc1_offset): self.adc1_offset = adc1_offset self.add_const_set_offset_0_0_0.set_const(device='/dev/adc1_offset', const=self.adc1_offset) |
a60abb54d prepare to deploy |
352 |
def main(top_block_cls=pid_vco, options=None): |
145da201a - |
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
from distutils.version import StrictVersion if StrictVersion(Qt.qVersion()) >= StrictVersion("4.5.0"): style = gr.prefs().get_string('qtgui', 'style', 'raster') Qt.QApplication.setGraphicsSystem(style) qapp = Qt.QApplication(sys.argv) tb = top_block_cls() tb.start() tb.show() def quitting(): tb.stop() tb.wait() qapp.connect(qapp, Qt.SIGNAL("aboutToQuit()"), quitting) qapp.exec_() if __name__ == '__main__': main() |