def connection_established(self):
        self.control = self.app().control
        params = self.app().parameters
        self.parameters = params

        def update_status(_):
            locked = params.lock.value
            task = params.task.value
            al_failed = params.autolock_failed.value
            running = params.autolock_running.value
            retrying = params.autolock_retrying.value
            percentage = params.autolock_percentage.value
            preparing = params.autolock_preparing.value

            if locked or (task is not None and not al_failed):
                self.show()
            else:
                self.hide()

            if task:
                watching = params.autolock_watching.value
            else:
                running = False
                watching = False

            def set_text(text):
                self.ids.lock_status.setText(text)

            if not running and locked:
                set_text("Locked!")
            if running and watching:
                set_text("Locked! Watching continuously...")
            if running and not watching and not locked and preparing:
                if not retrying:
                    set_text("Autolock is running... Analyzing data (%d %%)" %
                             percentage)
                else:
                    set_text("Trying again to lock...")

        for param in (
                params.lock,
                params.task,
                params.autolock_running,
                params.autolock_preparing,
                params.autolock_watching,
                params.autolock_failed,
                params.autolock_locked,
                params.autolock_retrying,
                params.autolock_percentage,
        ):
            param.on_change(update_status)

        param2ui(params.control_signal_history_length,
                 self.ids.control_signal_history_length)
    def connection_established(self):
        self.control = self.app.control
        params = self.app.parameters
        self.parameters = params

        self.parameters.psd_data_partial.on_change(self.psd_data_received, )
        self.parameters.psd_data_complete.on_change(self.psd_data_received, )

        param2ui(
            self.parameters.psd_acquisition_max_decimation,
            self.ids.maximum_measurement_time,
            lambda max_decimation: max_decimation - 12,
        )

        def update_status(_):
            psd_running = self.parameters.psd_acquisition_running.value
            if psd_running:
                self.ids.container_psd_running.show()
                self.ids.container_psd_not_running.hide()
            else:
                self.ids.container_psd_running.hide()
                self.ids.container_psd_not_running.show()

        self.parameters.psd_acquisition_running.on_change(update_status)
Example #3
0
    def connection_established(self):
        params = self.app().parameters
        self.control = self.app().control
        self.parameters = params

        param2ui(
            params.modulation_frequency,
            self.ids.modulation_frequency,
            lambda value: value / MHz,
        )
        param2ui(
            params.modulation_amplitude,
            self.ids.modulation_amplitude,
            lambda value: value / Vpp,
        )
        param2ui(params.ramp_speed, self.ids.ramp_speed)

        params.dual_channel.on_change(self.dual_channel_changed)
Example #4
0
    def connection_established(self):
        params = self.app().parameters
        self.control = self.app().control
        self.parameters = params

        param2ui(params.plot_line_width, self.ids.plot_line_width)
        param2ui(params.plot_line_opacity, self.ids.plot_line_opacity)
        param2ui(params.plot_fill_opacity, self.ids.plot_fill_opacity)

        def preview_colors(*args):
            for color_idx in range(N_COLORS):
                element = getattr(self.ids, "display_color_%d" % color_idx)
                param = getattr(self.parameters, "plot_color_%d" % color_idx)
                element.setStyleSheet("background-color: " +
                                      color_to_hex(param.value))

        for color_idx in range(N_COLORS):
            getattr(self.parameters,
                    "plot_color_%d" % color_idx).on_change(preview_colors)
    def connection_established(self):
        params = self.app().parameters
        self.control = self.app().control
        self.parameters = params

        def dual_channel_changed(value):
            self.ids.dual_channel_mixing.setVisible(value)
            self.ids.fast_in_1_status.setText(
                "error signal" if not value else "error signal 1")
            self.ids.fast_in_2_status.setText(
                "monitor" if not value else "error signal 2")
            return value

        param2ui(params.dual_channel, self.ids.dual_channel,
                 dual_channel_changed)

        param2ui(
            params.channel_mixing,
            self.ids.channel_mixing_slider,
            lambda value: value + 128,
        )
        # this is required to update the descriptive labels in the beginning
        self.channel_mixing_changed()

        param2ui(params.mod_channel, self.ids.mod_channel)
        param2ui(params.control_channel, self.ids.control_channel)
        param2ui(params.sweep_channel, self.ids.sweep_channel)
        param2ui(params.pid_on_slow_enabled, self.ids.slow_control_channel)

        param2ui(params.polarity_fast_out1, self.ids.polarity_fast_out1)
        param2ui(params.polarity_fast_out2, self.ids.polarity_fast_out2)
        param2ui(params.polarity_analog_out0, self.ids.polarity_analog_out0)

        def show_polarity_settings(*args):
            used_channels = set((
                params.control_channel.value,
                params.sweep_channel.value,
            ))

            if params.pid_on_slow_enabled.value:
                used_channels.add(ANALOG_OUT0)

            self.ids.polarity_selector.setVisible(len(used_channels) > 1)

            def set_visibility(element, channel_id):
                element.setVisible(channel_id in used_channels)

            set_visibility(self.ids.polarity_container_fast_out1, FAST_OUT1)
            set_visibility(self.ids.polarity_container_fast_out2, FAST_OUT2)
            set_visibility(self.ids.polarity_container_analog_out0,
                           ANALOG_OUT0)

        params.control_channel.on_change(show_polarity_settings)
        params.sweep_channel.on_change(show_polarity_settings)
        params.mod_channel.on_change(show_polarity_settings)
        params.pid_on_slow_enabled.on_change(show_polarity_settings)

        for idx in range(4):
            if idx == 0:
                continue
            name = "analog_out_%d" % idx
            param2ui(
                getattr(params, name),
                getattr(self.ids, name),
                process_value=lambda v: ANALOG_OUT_V * v,
            )
    def connection_established(self):
        self.control = self.app.control
        params = self.app.parameters
        self.parameters = params

        param2ui(params.ramp_amplitude, self.ids.zoom_slider,
                 ramp_amplitude_to_zoom_step)

        def display_ramp_range(*args):
            center = params.center.value
            amp = params.ramp_amplitude.value
            min_ = center - amp
            max_ = center + amp
            self.ids.ramp_status.setText("%.3fV to %.3fV" % (min_, max_))

        params.center.on_change(display_ramp_range)
        params.ramp_amplitude.on_change(display_ramp_range)

        def change_manual_navigation_visibility(*args):
            al_running = params.autolock_running.value
            optimization = params.optimization_running.value
            locked = params.lock.value

            self.get_widget("manual_navigation").setVisible(
                not al_running and not locked and not optimization)
            self.get_widget("top_lock_panel").setVisible(locked)
            self.get_widget("statusbar_unlocked").setVisible(
                not al_running and not locked and not optimization)

        params.lock.on_change(change_manual_navigation_visibility)
        params.autolock_running.on_change(change_manual_navigation_visibility)
        params.optimization_running.on_change(
            change_manual_navigation_visibility)

        params.to_plot.on_change(self.update_std)

        params.pid_on_slow_enabled.on_change(
            lambda v: self.ids.legend_slow_signal_history.setVisible(v))
        params.dual_channel.on_change(
            lambda v: self.ids.legend_monitor_signal_history.setVisible(not v))

        self.ids.settings_toolbox.setCurrentIndex(0)

        def center_or_amplitude_changed(_):
            center = params.center.value
            amplitude = params.ramp_amplitude.value

            self.ids.go_right_btn.setEnabled(center + amplitude < 1)
            self.ids.go_left_btn.setEnabled(center - amplitude > -1)

        params.ramp_amplitude.on_change(center_or_amplitude_changed)
        params.center.on_change(center_or_amplitude_changed)

        params.lock.on_change(lambda *args: self.reset_std_history())

        def update_legend_color(*args):
            set_color = lambda el, color_name: el.setStyleSheet(
                "color: " + color_to_hex(
                    getattr(self.parameters, "plot_color_%d" % COLORS[
                        color_name]).value))

            set_color(self.ids.legend_spectrum_1, "spectrum_1")
            set_color(self.ids.legend_spectrum_2, "spectrum_2")
            set_color(self.ids.legend_spectrum_combined, "spectrum_combined")
            set_color(self.ids.legend_error_signal, "spectrum_combined")
            set_color(self.ids.legend_control_signal, "control_signal")
            set_color(self.ids.legend_control_signal_history,
                      "control_signal_history")
            set_color(self.ids.legend_slow_signal_history, "slow_history")
            set_color(self.ids.legend_monitor_signal_history,
                      "monitor_signal_history")

        for color_idx in range(N_COLORS):
            getattr(self.parameters,
                    "plot_color_%d" % color_idx).on_change(update_legend_color)

        def update_legend_text(dual_channel):
            self.ids.legend_spectrum_1.setText(
                "error signal" if not dual_channel else "error signal 1")
            self.ids.legend_spectrum_2.setText(
                "monitor" if not dual_channel else "error signal 2")
            self.ids.legend_spectrum_combined.setVisible(dual_channel)

        self.parameters.dual_channel.on_change(update_legend_text)
    def connection_established(self):
        params = self.app().parameters
        self.parameters = params
        self.control = self.app().control

        param2ui(params.p, self.ids.kp)
        param2ui(params.i, self.ids.ki)
        param2ui(params.d, self.ids.kd)

        # param2ui(params.check_lock, self.ids.checkLockCheckbox)
        # param2ui(params.watch_lock, self.ids.watchLockCheckbox)
        # param2ui(
        #    params.watch_lock_threshold,
        #    self.ids.watch_lock_threshold,
        #    lambda v: v * 100,
        # )
        param2ui(params.autolock_determine_offset, self.ids.autoOffsetCheckbox)
        param2ui(
            params.automatic_mode,
            self.ids.lock_control_container,
            lambda value: 0 if value else 1,
        )
        param2ui(params.pid_on_slow_strength, self.ids.pid_on_slow_strength)

        def slow_pid_visibility(*args):
            self.ids.slow_pid_group.setVisible(
                self.parameters.pid_on_slow_enabled.value)

        params.pid_on_slow_enabled.on_change(slow_pid_visibility)

        def lock_status_changed(_):
            locked = params.lock.value
            task = params.task.value
            al_failed = params.autolock_failed.value
            task_running = (task is not None) and (not al_failed)

            if locked or task_running or al_failed:
                self.ids.lock_control_container.hide()
            else:
                self.ids.lock_control_container.show()

            self.ids.lock_failed.setVisible(al_failed)

        for param in (
                params.lock,
                params.autolock_preparing,
                params.autolock_watching,
                params.autolock_failed,
                params.autolock_locked,
        ):
            param.on_change(lock_status_changed)

        param2ui(params.target_slope_rising, self.ids.button_slope_rising)
        param2ui(
            params.target_slope_rising,
            self.ids.button_slope_falling,
            lambda value: not value,
        )

        def autolock_selection_status_changed(value):
            self.ids.auto_mode_activated.setVisible(value)
            self.ids.auto_mode_not_activated.setVisible(not value)

        params.autolock_selection.on_change(autolock_selection_status_changed)

        param2ui(params.autolock_mode_preference,
                 self.ids.autolock_mode_preference)
    def connection_established(self):
        params = self.app().parameters
        self.parameters = params
        self.control = self.app().control

        def opt_running_changed(_):
            running = params.optimization_running.value
            approaching = params.optimization_approaching.value
            failed = params.optimization_failed.value

            self.ids.optimization_not_running_container.setVisible(
                not failed and not running)
            self.ids.optimization_running_container.setVisible(
                not failed and running and not approaching)
            self.ids.optimization_preparing.setVisible(not failed and running
                                                       and approaching)
            self.ids.optimization_failed.setVisible(failed)

        params.optimization_running.on_change(opt_running_changed)
        params.optimization_approaching.on_change(opt_running_changed)
        params.optimization_failed.on_change(opt_running_changed)

        def opt_selection_changed(value):
            self.ids.optimization_selecting.setVisible(value)
            self.ids.optimization_not_selecting.setVisible(not value)

        params.optimization_selection.on_change(opt_selection_changed)

        def mod_param_changed(_):
            dual_channel = params.dual_channel.value
            channel = params.optimization_channel.value
            optimized = params.optimization_optimized_parameters.value

            self.ids.optimization_display_parameters.setText("""<br />
                <b>current parameters</b>: %.2f&nbsp;MHz, %.2f&nbsp;Vpp, %.2f&nbsp;deg<br />
                <b>optimized parameters</b>: %.2f&nbsp;MHz, %.2f&nbsp;Vpp, %.2f&nbsp;deg
                <br />
                """ % (
                params.modulation_frequency.value / MHz,
                params.modulation_amplitude.value / Vpp,
                (params.demodulation_phase_a,
                 params.demodulation_phase_b)[0 if not dual_channel else
                                              (0, 1)[channel]].value,
                optimized[0] / MHz,
                optimized[1] / Vpp,
                optimized[2],
            ))

        for p in (
                params.modulation_amplitude,
                params.modulation_frequency,
                params.demodulation_phase_a,
        ):
            p.on_change(mod_param_changed)

        def improvement_changed(improvement):
            self.ids.optimization_improvement.setText("%d %%" %
                                                      (improvement * 100))

        params.optimization_improvement.on_change(improvement_changed)

        param2ui(params.optimization_mod_freq_enabled,
                 self.ids.optimization_mod_freq)
        param2ui(params.optimization_mod_freq_min,
                 self.ids.optimization_mod_freq_min)
        param2ui(params.optimization_mod_freq_max,
                 self.ids.optimization_mod_freq_max)
        param2ui(params.optimization_mod_amp_enabled,
                 self.ids.optimization_mod_amp)
        param2ui(params.optimization_mod_amp_min,
                 self.ids.optimization_mod_amp_min)
        param2ui(params.optimization_mod_amp_max,
                 self.ids.optimization_mod_amp_max)

        def dual_channel_changed(value):
            self.ids.optimization_channel_selector_box.setVisible(value)

        params.dual_channel.on_change(dual_channel_changed)
Example #9
0
    def connection_established(self):
        params = self.app().parameters
        self.control = self.app().control
        self.parameters = params

        # self.close_button.clicked.connect(self.close_app)
        # self.shutdown_button.clicked.connect(self.shutdown_server)

        param2ui(self.get_param("demodulation_phase"),
                 self.ids.demodulation_phase)
        param2ui(
            self.get_param("demodulation_multiplier"),
            self.ids.demodulation_frequency,
            lambda value: value - 1,
        )
        param2ui(self.get_param("offset"), self.ids.signal_offset,
                 lambda v: v / 8191.0)
        param2ui(self.get_param("invert"), self.ids.invert)
        param2ui(self.get_param("filter_automatic"), self.ids.filter_automatic)

        def filter_automatic_changed(value):
            self.ids.automatic_filtering_enabled.setVisible(value)
            self.ids.automatic_filtering_disabled.setVisible(not value)

        self.get_param("filter_automatic").on_change(filter_automatic_changed)

        for filter_i in [1, 2]:
            param2ui(
                self.get_param("filter_%d_enabled" % filter_i),
                getattr(self.ids, "filter_%d_enabled" % filter_i),
            )
            param2ui(
                self.get_param("filter_%d_frequency" % filter_i),
                getattr(self.ids, "filter_%d_frequency" % filter_i),
            )
            param2ui(
                self.get_param("filter_%d_type" % filter_i),
                getattr(self.ids, "filter_%d_type" % filter_i),
                lambda type_: {
                    LOW_PASS_FILTER: 0,
                    HIGH_PASS_FILTER: 1
                }[type_],
            )