Commit 60bcd3bd authored by Lucas Giardino's avatar Lucas Giardino

cambio a handles mas directos y debugeo

parent be6d8025
...@@ -15,18 +15,18 @@ import json ...@@ -15,18 +15,18 @@ import json
from artiq.experiment import * from artiq.experiment import *
# TODO: # TODO:
[ ] Catch errors and send according popus # [ ] Catch errors and send according popus
[ ] Add tabs to store different configurations # [ ] Add tabs to store different configurations
[ ] Refactor to remove the artiq/dds handle issue # [ ] Refactor to remove the artiq/dds handle issue
class SingleChannel(QWidget): #{{{ class SingleChannel(QWidget): #{{{
"""Class to control a single given Urukul channel""" """Class to control a single given Urukul channel"""
def __init__(self, artiq, dds, name="Default Name"): def __init__(self, core, dds, name="Default Name"):
# Must pass artiq and dds handles. I don't know how to work around this # Must pass artiq and dds handles. I don't know how to work around this
# but should be doable somehow # but should be doable somehow
QWidget.__init__(self) QWidget.__init__(self)
self.artiq = artiq self.core = core
self.dds = dds self.dds = dds
# PArameter dictionary to store and save current DDS states # PArameter dictionary to store and save current DDS states
...@@ -59,8 +59,8 @@ class SingleChannel(QWidget): #{{{ ...@@ -59,8 +59,8 @@ class SingleChannel(QWidget): #{{{
# Frecuency input {{{ # Frecuency input {{{
self.freq_input = QDoubleSpinBox() self.freq_input = QDoubleSpinBox()
self.freq_input.setPrefix("Frequency: ") self.freq_input.setPrefix("Frequency: ")
self.freq_input.setRange(1, 400) self.freq_input.setRange(1., 400.)
self.freq_input.setSingleStep(0.01) self.freq_input.setSingleStep(0.1)
self.freq_input.setSuffix(" MHz") self.freq_input.setSuffix(" MHz")
self.freq_input.valueChanged.connect(self.freq_change) self.freq_input.valueChanged.connect(self.freq_change)
vbox.addWidget(self.freq_input) vbox.addWidget(self.freq_input)
...@@ -69,8 +69,8 @@ class SingleChannel(QWidget): #{{{ ...@@ -69,8 +69,8 @@ class SingleChannel(QWidget): #{{{
# Amplitude input {{{ # Amplitude input {{{
self.amp_input = QDoubleSpinBox() self.amp_input = QDoubleSpinBox()
self.amp_input.setPrefix("Amplitude: ") self.amp_input.setPrefix("Amplitude: ")
self.amp_input.setRange(0, 1) self.amp_input.setRange(0., 1.)
self.amp_input.setSingleStep(0.01) self.amp_input.setSingleStep(0.1)
self.amp_input.valueChanged.connect(self.amp_change) self.amp_input.valueChanged.connect(self.amp_change)
vbox.addWidget(self.amp_input) vbox.addWidget(self.amp_input)
# }}} # }}}
...@@ -78,18 +78,22 @@ class SingleChannel(QWidget): #{{{ ...@@ -78,18 +78,22 @@ class SingleChannel(QWidget): #{{{
# Attenuation input {{{ # Attenuation input {{{
self.att_input = QDoubleSpinBox() self.att_input = QDoubleSpinBox()
self.att_input.setPrefix("Attenuation: ") self.att_input.setPrefix("Attenuation: ")
self.att_input.setRange(0, 31) self.att_input.setRange(0., 31.)
self.att_input.setSingleStep(0.01) self.att_input.setSingleStep(0.1)
self.att_input.setSuffix(" dB") self.att_input.setSuffix(" dB")
self.att_input.valueChanged.connect(self.att_change) self.att_input.valueChanged.connect(self.att_change)
vbox.addWidget(self.att_input) vbox.addWidget(self.att_input)
# }}} # }}}
def update_state(key='', new_state): def update_state(self, key, new_state):
"""Update the parameters dictionary""" """Update the parameters dictionary"""
self.state_params[key] = new_state self.state_params[key] = new_state
def get_state_param(self, key):
"""Get a key from the parameters dictionary"""
return self.state_params[key]
def get_state(self): def get_state(self):
"""Returns the parameter dictionary""" """Returns the parameter dictionary"""
return self.state_params return self.state_params
...@@ -102,17 +106,17 @@ class SingleChannel(QWidget): #{{{ ...@@ -102,17 +106,17 @@ class SingleChannel(QWidget): #{{{
def switch_state(self): def switch_state(self):
"""Toggles the state of this DDS""" """Toggles the state of this DDS"""
if self.state_button.isChecked(): if self.state_button.isChecked():
self.swich_state_kernel(True) # Turns it on self.switch_state_kernel(True) # Turns it on
self.state_button.setText("ON") # Change text and color self.state_button.setText("ON") # Change text and color
self.state_button.setStyleSheet("background-color: #5db75d;") self.state_button.setStyleSheet("background-color: #5db75d;")
else: else:
self.swich_state_kernel(False) # Turns it off self.switch_state_kernel(False) # Turns it off
self.state_button.setText("OFF") # Change text and color self.state_button.setText("OFF") # Change text and color
self.state_button.setStyleSheet("background-color: #b75d5d;") self.state_button.setStyleSheet("background-color: #b75d5d;")
@kernel @kernel
def switch_state_kernel(self, state): def switch_state_kernel(self, state):
self.artiq.core.break_realtime() self.core.break_realtime()
self.dds.sw.set_o(state) self.dds.sw.set_o(state)
#}}} #}}}
...@@ -125,8 +129,8 @@ class SingleChannel(QWidget): #{{{ ...@@ -125,8 +129,8 @@ class SingleChannel(QWidget): #{{{
@kernel @kernel
def att_change_kernel(self, new_att): def att_change_kernel(self, new_att):
self.artiq.core.break_realtime() self.core.break_realtime()
self.dds.set_att(att) self.dds.set_att(new_att)
# }}} # }}}
...@@ -138,7 +142,8 @@ class SingleChannel(QWidget): #{{{ ...@@ -138,7 +142,8 @@ class SingleChannel(QWidget): #{{{
@kernel @kernel
def freq_change_kernel(self, new_freq): def freq_change_kernel(self, new_freq):
self.artiq.core.break_realtime() self.core.break_realtime()
delay(10*ms)
self.dds.set(new_freq*MHz) self.dds.set(new_freq*MHz)
# }}} # }}}
...@@ -150,27 +155,31 @@ class SingleChannel(QWidget): #{{{ ...@@ -150,27 +155,31 @@ class SingleChannel(QWidget): #{{{
@kernel @kernel
def amp_change_kernel(self, new_amp): def amp_change_kernel(self, new_amp):
self.artiq.core.break_realtime() self.core.break_realtime()
self.dds.set_amplitude(new_amp) # this needs fixing, reading from the dict is not the way
self.dds.io_update.pulse(8) # Try this to get the amplitude updated? self.dds.set(self.get_state_param('freq'), amplitude=new_amp)
self.dds.cpld.io_update.pulse_mu(8) # Try this to get the amplitude updated?
# }}} # }}}
#}}} #}}}
class DDSManager(QWidget): #{{{ class DDSManager(QWidget): #{{{
"""Main application class""" """Main application class"""
def __init__(self, artiq): def __init__(self, core, ch0, ch1):
super().__init__() super().__init__()
self.artiq = artiq # get the artiq handle #self.artiq = artiq # get the artiq handle
self.core = core
self.ch0 = ch0
self.ch1 = ch1
self.setWindowTitle("DDS Manager GUI") self.setWindowTitle("DDS Manager GUI")
layout = QGridLayout() layout = QGridLayout()
self.setLayout(layout) self.setLayout(layout)
# Create both output widgets # Create both output widgets
self.laser_1 = SingleChannel(self.artiq, self.artiq.ch0, name="Laser 1") self.laser_1 = SingleChannel(core, ch0, name="Laser 1")
layout.addWidget(self.laser_1.get_widget(), 0, 0) layout.addWidget(self.laser_1.get_widget(), 0, 0)
self.laser_2 = SingleChannel(self.artiq, self.artiq.ch1, name="Laser 2") self.laser_2 = SingleChannel(core, ch1, name="Laser 2")
layout.addWidget(self.laser_2.get_widget(), 0, 1) layout.addWidget(self.laser_2.get_widget(), 0, 1)
save_btn = QPushButton("Save state") save_btn = QPushButton("Save state")
...@@ -199,7 +208,7 @@ class DDSManager(QWidget): #{{{ ...@@ -199,7 +208,7 @@ class DDSManager(QWidget): #{{{
class GUIManager(EnvExperiment): #{{{ class GUIManager(EnvExperiment): #{{{
def build(self): def build(self):
self.setattr_device("core") self.core = self.get_device("core")
self.setattr_device("scheduler") self.setattr_device("scheduler")
self.ch0 = self.get_device("urukul0_ch0") self.ch0 = self.get_device("urukul0_ch0")
self.ch1 = self.get_device("urukul0_ch1") self.ch1 = self.get_device("urukul0_ch1")
...@@ -207,7 +216,7 @@ class GUIManager(EnvExperiment): #{{{ ...@@ -207,7 +216,7 @@ class GUIManager(EnvExperiment): #{{{
def run(self): def run(self):
self.init_kernel() self.init_kernel()
app = QApplication(sys.argv) app = QApplication(sys.argv)
screen = DDSManager(artiq=self) screen = DDSManager(self.core, self.ch0, self.ch1)
screen.show() screen.show()
sys.exit(app.exec_()) sys.exit(app.exec_())
...@@ -215,8 +224,12 @@ class GUIManager(EnvExperiment): #{{{ ...@@ -215,8 +224,12 @@ class GUIManager(EnvExperiment): #{{{
def init_kernel(self): def init_kernel(self):
"""Initialize core and channels""" """Initialize core and channels"""
self.core.reset() self.core.reset()
delay(100*ms)
self.ch0.cpld.init() self.ch0.cpld.init()
self.ch0.init() self.ch0.init()
self.ch1.cpld.init() self.ch1.cpld.init()
self.ch1.init() self.ch1.init()
self.ch0.sw.off()
self.ch1.sw.off()
delay(100*ms)
#}}} #}}}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment