Ejemplo n.º 1
0
    def ini_model(self):
        try:
            model_name = self.settings.child('models', 'model_class').value()
            model = importlib.import_module('.' +model_name, self.model_mod.__name__+'.models')
            self.model_class = getattr(model, model_name)(self)


            #try to get corresponding managers file
            filename = os.path.join(get_set_pid_path(), model_name + '.xml')
            if os.path.isfile(filename):
                self.actuator_modules,  self.detector_modules = self.set_file_preset(model_name)
            else:
                self.actuator_modules, self.detector_modules = self.set_default_preset()

            # # connecting to logger
            # for mov in self.actuator_modules:
            #     mov.log_signal[str].connect(self.add_log)
            # for det in self.detector_modules:
            #     det.log_signal[str].connect(self.add_log)
            # self.log_signal[str].connect(self.add_log)

            self.model_class.ini_model()

            self.enable_controls_pid(True)
            self.model_led.set_as_true()
            self.ini_model_action.setEnabled(False)



        except Exception as e:
            self.update_status(getLineInfo() + str(e), log_type='log')
Ejemplo n.º 2
0
    def ini_model(self):
        """
        Defines all the action to be performed on the initialized modules (main pid, actuators, detectors)
        Either here for specific things (ROI, ...) or within the preset of the current model

        """
        model_name = self.pid_controller.settings.child('models', 'model_class').value()

        self.pid_controller.detector_modules[0].ui.viewers[0].ui.roiBtn.click()

        #try to get corresponding roi file
        filename = os.path.join(get_set_pid_path(), model_name + '.roi2D')
        if os.path.isfile(filename):
            self.pid_controller.detector_modules[0].ui.viewers[0].load_ROI(filename)

        QtWidgets.QApplication.processEvents()
        if self.pid_controller.detector_modules[0].Initialized_state:
            #self.pid_controller.detector_modules[0].settings.child('main_settings', 'wait_time').setValue(0)
            self.pid_controller.detector_modules[0].grab_data()
        QThread.msleep(500)
        QtWidgets.QApplication.processEvents()

        self.pid_controller.settings.child('main_settings', 'update_modules').setValue(True)
        QtWidgets.QApplication.processEvents()
        QThread.msleep(500)
        QtWidgets.QApplication.processEvents()

        items = self.pid_controller.settings.child('main_settings', 'detector_modules').value().copy()
        if items is not None:
            items['selected'] = items['all_items'][0:2]
            self.pid_controller.settings.child('main_settings', 'detector_modules').setValue(items)

        self.pid_controller.settings.child('main_settings', 'pid_controls', 'output_limits',
                                           'output_limit_min').setValue(0) #in microns
        self.pid_controller.settings.child('main_settings', 'pid_controls', 'output_limits',
                                           'output_limit_min_enabled').setValue(True)
        self.pid_controller.settings.child('main_settings', 'pid_controls', 'output_limits',
                                           'output_limit_max').setValue(15) #in microns
        self.pid_controller.settings.child('main_settings', 'pid_controls', 'output_limits',
                                           'output_limit_max_enabled').setValue(True)

        self.pid_controller.settings.child('main_settings', 'pid_controls', 'pid_constants', 'kp').setValue(0.5)
        self.pid_controller.settings.child('main_settings', 'pid_controls', 'pid_constants', 'ki').setValue(0.2)
        self.pid_controller.settings.child('main_settings', 'pid_controls', 'pid_constants', 'kd').setValue(0.0001)

        self.pid_controller.settings.child('main_settings', 'pid_controls', 'filter', 'filter_enable').setValue(True)
        self.pid_controller.settings.child('main_settings', 'pid_controls', 'filter',
               'filter_step').setValue(self.settings.child('stabilization', 'laser_wl').value()/1000/6/2) #in microns

        self.pid_controller.setpoint_sb.setValue(7.5)
        self.pid_controller.settings.child('main_settings', 'pid_controls', 'sample_time').setValue(50)
Ejemplo n.º 3
0
def test_get_set_pid_path():
    local_path = utils.get_set_local_dir()
    pid_path = utils.get_set_pid_path()
    assert Path(pid_path) == Path(local_path).joinpath('pid_configs')
    assert Path(pid_path).is_dir()
Ejemplo n.º 4
0
    def set_PID_preset(self, pid_model):
        self.pid_type = True
        filename = os.path.join(get_set_pid_path(), pid_model + '.xml')
        if os.path.isfile(filename):
            children = custom_tree.XML_file_to_parameter(filename)
            self.preset_params = Parameter.create(title='Preset',
                                                  name='Preset',
                                                  type='group',
                                                  children=children)

        else:
            model_mod = importlib.import_module('pymodaq_pid_models')
            model = importlib.import_module('.' + pid_model,
                                            model_mod.__name__ + '.models')
            model_class = getattr(model, pid_model)
            actuators = model_class.actuators
            actuators_name = model_class.actuators_name
            detectors_type = model_class.detectors_type
            detectors_name = model_class.detectors_name
            detectors = model_class.detectors

            param = [
                {
                    'title': 'Filename:',
                    'name': 'filename',
                    'type': 'str',
                    'value': pid_model,
                    'readonly': True
                },
            ]

            params_move = [{
                'title': 'Moves:',
                'name': 'Moves',
                'type': 'groupmove'
            }]  # PresetScalableGroupMove(name="Moves")]
            params_det = [{
                'title': 'Detectors:',
                'name': 'Detectors',
                'type': 'groupdet'
            }]  # [PresetScalableGroupDet(name="Detectors")]
            self.preset_params = Parameter.create(title='Preset',
                                                  name='Preset',
                                                  type='group',
                                                  children=param +
                                                  params_move + params_det)

            QtWidgets.QApplication.processEvents()
            for ind_act, act in enumerate(actuators):
                self.preset_params.child(('Moves')).addNew(act)
                self.preset_params.child(
                    'Moves', 'move{:02.0f}'.format(ind_act),
                    'name').setValue(actuators_name[ind_act])
                QtWidgets.QApplication.processEvents()

            for ind_det, det in enumerate(detectors):
                self.preset_params.child(
                    ('Detectors')).addNew(detectors_type[ind_det] + '/' + det)
                self.preset_params.child(
                    'Detectors', 'det{:02.0f}'.format(ind_det),
                    'name').setValue(detectors_name[ind_det])
                QtWidgets.QApplication.processEvents()

        self.show_preset()
Ejemplo n.º 5
0
                'renamable':
                False
            }

            self.addChild(child)
        except Exception as e:
            print(str(e))


registerParameterType('groupdet', PresetScalableGroupDet, override=True)

#check if preset_mode directory exists on the drive
from pymodaq.daq_utils.daq_utils import get_set_local_dir
local_path = get_set_local_dir()

pid_path = get_set_pid_path()

preset_path = os.path.join(local_path, 'preset_modes')
if not os.path.isdir(preset_path):
    os.makedirs(preset_path)


class PresetManager():
    def __init__(self, msgbox=False):

        self.preset_params = None
        self.pid_type = False
        if msgbox:
            msgBox = QtWidgets.QMessageBox()
            msgBox.setText("Preset Manager?")
            msgBox.setInformativeText("What do you want to do?")
Ejemplo n.º 6
0
from pyqtgraph.parametertree import Parameter, ParameterTree
from pymodaq.daq_utils.parameter import ioxml
from pymodaq.daq_utils.parameter import pymodaq_ptypes
from pymodaq.daq_utils.managers import preset_manager_utils
from pymodaq.daq_utils import daq_utils as utils
from pymodaq.daq_utils import gui_utils
from pymodaq.daq_utils.h5modules import H5Saver
import importlib
from pymodaq.daq_utils.pid.pid_params import params as pid_params
from pathlib import Path

logger = utils.set_logger(utils.get_module_name(__file__))

# check if preset_mode directory exists on the drive

pid_path = utils.get_set_pid_path()
preset_path = utils.get_set_preset_path()
overshoot_path = utils.get_set_overshoot_path()
layout_path = utils.get_set_layout_path()


class PresetManager:
    def __init__(self,
                 msgbox=False,
                 path=None,
                 extra_params=[],
                 param_options=[]):

        if path is None:
            path = preset_path
        else:
Ejemplo n.º 7
0
    def set_file_preset(self,model):
        """
            Set a file managers from the converted xml file given by the filename parameter.


            =============== =========== ===================================================
            **Parameters**    **Type**    **Description**
            *filename*        string      the name of the xml file to be converted/treated
            =============== =========== ===================================================

            Returns
            -------
            (Object list, Object list) tuple
                The updated (Move modules list, Detector modules list).

            See Also
            --------
            custom_tree.XML_file_to_parameter, set_param_from_param, stop_moves, update_status,DAQ_Move_main.daq_move, DAQ_viewer_main.daq_viewer
        """

        filename = os.path.join(get_set_pid_path(), model + '.xml')
        self.preset_file = filename
        self.preset_manager.set_file_preset(filename, show=False)
        self.move_docks = []
        self.det_docks_settings = []
        self.det_docks_viewer = []
        move_forms = []
        actuator_modules = []
        detector_modules = []
        move_types = []


        #################################################################
        ###### sort plugins by IDs and within the same IDs by Master and Slave status
        plugins=[{'type': 'move', 'value': child} for child in self.preset_manager.preset_params.child(('Moves')).children()]+[{'type': 'det', 'value': child} for child in self.preset_manager.preset_params.child(('Detectors')).children()]

        for plug in plugins:
            plug['ID']=plug['value'].child('params','main_settings','controller_ID').value()
            if plug["type"]=='det':
                plug['status']=plug['value'].child('params','detector_settings','controller_status').value()
            else:
                plug['status']=plug['value'].child('params','move_settings', 'multiaxes', 'multi_status').value()

        IDs=list(set([plug['ID'] for plug in plugins]))
        #%%
        plugins_sorted=[]
        for id in IDs:
            plug_Ids=[]
            for plug in plugins:
                if plug['ID']==id:
                    plug_Ids.append(plug)
            plug_Ids.sort(key=lambda status: status['status'])
            plugins_sorted.append(plug_Ids)
        #################################################################
        #######################

        ind_move=-1
        ind_det=-1
        for plug_IDs in plugins_sorted:
            for ind_plugin, plugin in enumerate(plug_IDs):


                plug_name=plugin['value'].child(('name')).value()
                plug_init=plugin['value'].child(('init')).value()
                plug_settings=plugin['value'].child(('params'))

                if plugin['type'] == 'move':
                    ind_move+=1
                    plug_type=plug_settings.child('main_settings','move_type').value()
                    self.move_docks.append(Dock(plug_name, size=(150,250)))
                    if ind_move==0:
                        self.dock_area.addDock(self.move_docks[-1], 'top',self.logger_dock)
                    else:
                        self.dock_area.addDock(self.move_docks[-1], 'above',self.move_docks[-2])
                    move_forms.append(QtWidgets.QWidget())
                    mov_mod_tmp=DAQ_Move(move_forms[-1],plug_name)

                    mov_mod_tmp.ui.Stage_type_combo.setCurrentText(plug_type)
                    mov_mod_tmp.ui.Quit_pb.setEnabled(False)
                    QtWidgets.QApplication.processEvents()

                    set_param_from_param(mov_mod_tmp.settings,plug_settings)
                    QtWidgets.QApplication.processEvents()

                    mov_mod_tmp.bounds_signal[bool].connect(self.stop_moves)
                    self.move_docks[-1].addWidget(move_forms[-1])
                    actuator_modules.append(mov_mod_tmp)

                    try:
                        if ind_plugin==0: #should be a master type plugin
                            if plugin['status']!="Master":
                                raise Exception('error in the master/slave type for plugin {}'.format(plug_name))
                            if plug_init:
                                actuator_modules[-1].ui.IniStage_pb.click()
                                QtWidgets.QApplication.processEvents()
                                if 'Mock' in plug_type:
                                    QThread.msleep(500)
                                else:
                                    QThread.msleep(4000)  # to let enough time for real hardware to init properly
                                QtWidgets.QApplication.processEvents()
                                master_controller=actuator_modules[-1].controller
                        else:
                            if plugin['status']!="Slave":
                                raise Exception('error in the master/slave type for plugin {}'.format(plug_name))
                            if plug_init:
                                actuator_modules[-1].controller=master_controller
                                actuator_modules[-1].ui.IniStage_pb.click()
                                QtWidgets.QApplication.processEvents()
                                if 'Mock' in plug_type:
                                    QThread.msleep(500)
                                else:
                                    QThread.msleep(4000)  # to let enough time for real hardware to init properly
                                QtWidgets.QApplication.processEvents()
                    except Exception as e:
                        self.update_status(getLineInfo()+ str(e),'log')


                else:
                    ind_det+=1
                    plug_type=plug_settings.child('main_settings','DAQ_type').value()
                    plug_subtype=plug_settings.child('main_settings','detector_type').value()

                    self.det_docks_settings.append(Dock(plug_name+" settings", size=(150,250)))
                    self.det_docks_viewer.append(Dock(plug_name+" viewer", size=(350,350)))

                    if ind_det==0:
                        self.logger_dock.area.addDock(self.det_docks_settings[-1], 'bottom', self.dock_input) #dock_area of the logger dock
                    else:
                        self.dock_area.addDock(self.det_docks_settings[-1], 'bottom',self.det_docks_settings[-2])
                    self.dock_area.addDock(self.det_docks_viewer[-1],'right',self.det_docks_settings[-1])

                    det_mod_tmp=DAQ_Viewer(self.dock_area,dock_settings=self.det_docks_settings[-1],
                                                        dock_viewer=self.det_docks_viewer[-1],title=plug_name,
                                           DAQ_type=plug_type, parent_scan=self)
                    detector_modules.append(det_mod_tmp)
                    detector_modules[-1].ui.Detector_type_combo.setCurrentText(plug_subtype)
                    detector_modules[-1].ui.Quit_pb.setEnabled(False)
                    set_param_from_param(det_mod_tmp.settings,plug_settings)
                    QtWidgets.QApplication.processEvents()


                    try:
                        if ind_plugin==0: #should be a master type plugin
                            if plugin['status']!="Master":
                                raise Exception('error in the master/slave type for plugin {}'.format(plug_name))
                            if plug_init:
                                detector_modules[-1].ui.IniDet_pb.click()
                                QtWidgets.QApplication.processEvents()
                                if 'Mock' in plug_subtype:
                                    QThread.msleep(500)
                                else:
                                    QThread.msleep(4000)  # to let enough time for real hardware to init properly
                                QtWidgets.QApplication.processEvents()
                                master_controller=detector_modules[-1].controller
                        else:
                            if plugin['status']!="Slave":
                                raise Exception('error in the master/slave type for plugin {}'.format(plug_name))
                            if plug_init:
                                detector_modules[-1].controller=master_controller
                                detector_modules[-1].ui.IniDet_pb.click()
                                QtWidgets.QApplication.processEvents()
                                if 'Mock' in plug_subtype:
                                    QThread.msleep(500)
                                else:
                                    QThread.msleep(4000)  # to let enough time for real hardware to init properly
                                QtWidgets.QApplication.processEvents()
                    except Exception as e:
                        self.update_status(getLineInfo()+ str(e),'log')

                    detector_modules[-1].settings.child('main_settings','overshoot').show()
                    detector_modules[-1].overshoot_signal[bool].connect(self.stop_moves)

        QtWidgets.QApplication.processEvents()

        return actuator_modules,detector_modules