Completed
Pull Request — master (#380)
by
unknown
03:38
created

ProcessDummy.setControlValue()   A

Complexity

Conditions 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
1
# -*- coding: utf-8 -*-
2
"""
3
Dummy implementation for process control.
4
5
Qudi is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9
10
Qudi is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU General Public License for more details.
14
15
You should have received a copy of the GNU General Public License
16
along with Qudi. If not, see <http://www.gnu.org/licenses/>.
17
18
Copyright (c) the Qudi Developers. See the COPYRIGHT.txt file at the
19
top-level directory of this distribution and at <https://github.com/Ulm-IQO/qudi/>
20
"""
21
22
from core.module import Base
23
from interface.process_interface import ProcessInterface
24
from interface.process_control_interface import ProcessControlInterface
25
from qtpy import QtCore
26
import numpy as np
27
28
class ProcessDummy(Base, ProcessInterface, ProcessControlInterface):
29
    """ Methods to control slow laser switching devices.
30
    """
31
    _modclass = 'Process'
32
    _modtype = 'hardware'
33
34
    def on_activate(self):
35
        """ Activate module.
36
        """
37
        self.temperature = 300.0
38
        self.pwmpower = 0
39
40
        self.recalctimer = QtCore.QTimer()
41
        self.recalctimer.timeout.connect(self._recalcTemp)
42
        self.recalctimer.start(100)
43
44
    def on_deactivate(self):
45
        """ Deactivate module.
46
        """
47
        pass
48
49
    def get_process_value(self):
50
        """ Process value, here temperature.
51
52
            @return float: process value
53
        """
54
        return self.temperature
55
56
    def get_process_unit(self):
57
        """ Process unit, here kelvin.
58
59
            @return float: process unit
60
        """
61
        return ('K', 'kelvin')
62
63
    def set_control_value(self, value):
64
        """ Set control value, here heating power.
65
66
            @param flaot value: control value
67
        """
68
        self.pwmpower = value
69
70
    def get_enabled(self):
71
        pass
72
73
    def set_enabled(self):
74
        pass
75
76
77
    def get_control_value(self):
78
        """ Get current control value, here heating power
79
80
            @return float: current control value
81
        """
82
        return self.pwmpower
83
84
    def get_control_unit(self):
85
        """ Get unit of control value.
86
87
            @return tuple(str): short and text unit of control value
88
        """
89
        return ('%', 'percent')
90
91
    def get_control_limits(self):
92
        """ Get minimum and maximum of control value.
93
94
            @return tuple(float, float): minimum and maximum of control value
95
        """
96
        return (-100, 100)
97
98
    def _recalcTemp(self):
99
        """ Update current temperature based on model.
100
        """
101
        pfactor = 1
102
        heatCapacity = self.metalHeatCapacity(self.temperature)
103
        dt = self.pwmpower * abs((self.temperature - 4)/self.temperature) * pfactor / heatCapacity
104
        if abs(dt) > 10:
105
            dt = 10*np.sign(dt)
106
        self.temperature = self.temperature + dt
107
        # print(self.temperature, self.pwmpower, heatCapacity)
108
109
    def metalHeatCapacity(self, T):
110
        """ Calculate heat capacity of copper at given temperature.
111
112
            @param float T: temperature at which to calculate heat capacity
113
114
            @return float: hrat capacity at temperature T
115
        """
116
        NA = 6.02214086 * 10**23  # Avogadro constant
117
        k = 1.38064852 * 10**(-23)  # Boltzmann constant
118
        TD = 343.5 # Debye temperatre of copper
119
        Ef = 7 * 1.602176565 * 10**(-19) # fermi energy of copper (7eV)
120
        heatcapacity = np.pi**2 * NA * k**2 * T / (2*Ef) + 12 * np.pi**4 * NA * k * T**3 / (5 * TD**3)
121
        if heatcapacity < 0.0005:
122
            return 0.0005
123
        return heatcapacity
124
125