Commit a77cf865 authored by Martin Drechsler's avatar Martin Drechsler

added scanFunction file. Now, the scan is performed with a generator.

parent eb3686c7
......@@ -14,6 +14,8 @@ import telnetlib
import os
from messages import show_warning
import scanFunctions
#An example of a class
class anal_control_signal(QWidget):
_registry = []
......@@ -94,15 +96,11 @@ class anal_control_signal(QWidget):
def scanEvent(self):
if float(self.scan_step) < float(self.scan_sb_start.val) or float(self.scan_step) > float(self.scan_sb_stop.val):
self.scan_direction = (-1) * self.scan_direction
self.scan_step = self.scan_step + self.scan_direction
self.scan_step = next(self.scan_array_gen)
self.AO.set_out(self.scan_step)
#print(self.scan_step)
def PbarEvent(self):
try:
self.scanpBar.setValue( 100 * float(self.scan_step-float(self.scan_sb_start.val))/float(self.scan_sb_stop.val-self.scan_sb_start.val) )
......@@ -114,12 +112,7 @@ class anal_control_signal(QWidget):
def doScanAction(self):
#self.scan_direction = -float( (self.scan_sb_stop.val-self.scan_sb_start.val)/self.scan_sb_period.val ) * 5e-3 * 2
#self.scan_step = float(self.scan_sb_start.val)
if self.ScanTimer.isActive():
self.ScanTimer.stop()
self.scan_button.setText('Start scan')
......@@ -131,23 +124,18 @@ class anal_control_signal(QWidget):
else:
b = float(self.scan_sb_stop.val)
a = float(self.scan_sb_start.val)
dt = 5.0e-3
T = float(self.scan_sb_period.val)
n = int( T/(2*dt) )
self.scan_direction = -abs(b-a)/n # this is the size in voltage of each step
self.scan_step = float(self.sb.val) # from here it beggins
dt = 5.0e-3
self.scan_array = scanFunctions.create_scan_array(self.scan_sb_start.val, self.scan_sb_stop.val, self.scan_sb_period.val, dt)
self.scan_array_gen = scanFunctions.yield_scan_array(self.scan_array)
if self.scan_step > b or self.scan_step < a:
if self.scan_step > float(self.scan_sb_stop.val) or self.scan_step < float(self.scan_sb_start.val):
details = 'Remember remember the fifth of November.' + '\n' + 'Also remember that scan starts from the value of the corresponding spin box'
show_warning('Scan can not start outside scan range and scan start should be lower than scan stop', details_text= details)
elif n < 5:
show_warning('%i steps are too few, you need at least 5 steps' % (n) )
pass
elif len(self.scan_array) < 5:
show_warning('%i steps are too few, you need at least 5 steps' % (len(self.scan_array)) )
else:
self.sb.setEnabled(False)
self.scan_button.setStyleSheet("background-color: green")
......
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Oct 26 11:24:28 2018
@author: martindrech
Auxiliary functions for performing scans in a cleaner way
"""
import numpy as np
def create_scan_array(scan_start, scan_stop, scan_period, dt):
"""
Returns the array that represents one period of the scan, including up and down paths of the triangle.
"""
scan_start = float(scan_start)
scan_stop = float(scan_stop)
scan_period = float(scan_period)
number_of_points = 1 + (scan_period+dt)//(2*dt)
scan_array = np.linspace(scan_start, scan_stop, int(number_of_points))
return np.concatenate((scan_array, np.flip(scan_array, 0)[1:]))
def yield_array(arr):
larr = len(arr)
cursor = 0
while cursor < larr:
yield arr[cursor]
cursor = cursor + 1
def yield_scan_array(arr):
while True:
yield from yield_array(arr)
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