forked from M-Labs/thermostat
GUI: Control Panel changes #2
@ -28,7 +28,7 @@ class PIDAutoTuner(QObject):
|
|||||||
def load_params_and_set_ready(self, ch):
|
def load_params_and_set_ready(self, ch):
|
||||||
self.autotuners[ch].setParam(
|
self.autotuners[ch].setParam(
|
||||||
self.target_temp[ch],
|
self.target_temp[ch],
|
||||||
self.test_current[ch] / 1000,
|
self.test_current[ch],
|
||||||
self.temp_swing[ch],
|
self.temp_swing[ch],
|
||||||
1 / self.sampling_interval[ch],
|
1 / self.sampling_interval[ch],
|
||||||
self.lookback[ch],
|
self.lookback[ch],
|
||||||
|
@ -4,6 +4,7 @@ from pyqtgraph.parametertree import (
|
|||||||
Parameter,
|
Parameter,
|
||||||
registerParameterType,
|
registerParameterType,
|
||||||
)
|
)
|
||||||
|
import pytec.gui.view.pin_si_prefix
|
||||||
|
|
||||||
|
|
||||||
class MutexParameter(pTypes.ListParameter):
|
class MutexParameter(pTypes.ListParameter):
|
||||||
@ -136,10 +137,10 @@ class CtrlPanel(QObject):
|
|||||||
)
|
)
|
||||||
self.params[channel].child(
|
self.params[channel].child(
|
||||||
"pid", "pid_output_clamping", "output_min"
|
"pid", "pid_output_clamping", "output_min"
|
||||||
).setValue(settings["parameters"]["output_min"] * 1000)
|
).setValue(settings["parameters"]["output_min"])
|
||||||
self.params[channel].child(
|
self.params[channel].child(
|
||||||
"pid", "pid_output_clamping", "output_max"
|
"pid", "pid_output_clamping", "output_max"
|
||||||
).setValue(settings["parameters"]["output_max"] * 1000)
|
).setValue(settings["parameters"]["output_max"])
|
||||||
self.params[channel].child(
|
self.params[channel].child(
|
||||||
"output", "control_method", "target"
|
"output", "control_method", "target"
|
||||||
).setValue(settings["target"])
|
).setValue(settings["target"])
|
||||||
@ -154,7 +155,7 @@ class CtrlPanel(QObject):
|
|||||||
)
|
)
|
||||||
self.params[channel].child(
|
self.params[channel].child(
|
||||||
"output", "control_method", "i_set"
|
"output", "control_method", "i_set"
|
||||||
).setValue(settings["i_set"] * 1000)
|
).setValue(settings["i_set"])
|
||||||
if settings["temperature"] is not None:
|
if settings["temperature"] is not None:
|
||||||
self.params[channel].child("temperature").setValue(
|
self.params[channel].child("temperature").setValue(
|
||||||
settings["temperature"]
|
settings["temperature"]
|
||||||
@ -188,10 +189,10 @@ class CtrlPanel(QObject):
|
|||||||
pwm_params["max_v"]["value"]
|
pwm_params["max_v"]["value"]
|
||||||
)
|
)
|
||||||
self.params[channel].child("output", "limits", "max_i_pos").setValue(
|
self.params[channel].child("output", "limits", "max_i_pos").setValue(
|
||||||
pwm_params["max_i_pos"]["value"] * 1000
|
pwm_params["max_i_pos"]["value"]
|
||||||
)
|
)
|
||||||
self.params[channel].child("output", "limits", "max_i_neg").setValue(
|
self.params[channel].child("output", "limits", "max_i_neg").setValue(
|
||||||
pwm_params["max_i_neg"]["value"] * 1000
|
pwm_params["max_i_neg"]["value"]
|
||||||
)
|
)
|
||||||
|
|
||||||
for limit in "max_i_pos", "max_i_neg", "max_v":
|
for limit in "max_i_pos", "max_i_neg", "max_v":
|
||||||
|
@ -44,14 +44,16 @@
|
|||||||
"title": "Set Current",
|
"title": "Set Current",
|
||||||
"type": "float",
|
"type": "float",
|
||||||
"value": 0,
|
"value": 0,
|
||||||
"step": 100,
|
"step": 0.1,
|
||||||
"limits": [
|
"limits": [
|
||||||
-2000,
|
-2,
|
||||||
2000
|
2
|
||||||
],
|
],
|
||||||
"triggerOnShow": true,
|
"triggerOnShow": true,
|
||||||
"decimals": 6,
|
"decimals": 6,
|
||||||
"suffix": "mA",
|
"pinSiPrefix": "m",
|
||||||
|
"suffix": "A",
|
||||||
|
"siPrefix": true,
|
||||||
"thermostat:set_param": {
|
"thermostat:set_param": {
|
||||||
"topic": "pwm",
|
"topic": "pwm",
|
||||||
"field": "i_set"
|
"field": "i_set"
|
||||||
@ -91,13 +93,15 @@
|
|||||||
"title": "Max Cooling Current",
|
"title": "Max Cooling Current",
|
||||||
"type": "float",
|
"type": "float",
|
||||||
"value": 0,
|
"value": 0,
|
||||||
"step": 100,
|
"step": 0.1,
|
||||||
"decimals": 6,
|
"decimals": 6,
|
||||||
"limits": [
|
"limits": [
|
||||||
0,
|
0,
|
||||||
2000
|
2
|
||||||
],
|
],
|
||||||
"suffix": "mA",
|
"siPrefix": true,
|
||||||
|
"pinSiPrefix": "m",
|
||||||
|
"suffix": "A",
|
||||||
"thermostat:set_param": {
|
"thermostat:set_param": {
|
||||||
"topic": "pwm",
|
"topic": "pwm",
|
||||||
"field": "max_i_pos"
|
"field": "max_i_pos"
|
||||||
@ -110,13 +114,15 @@
|
|||||||
"title": "Max Heating Current",
|
"title": "Max Heating Current",
|
||||||
"type": "float",
|
"type": "float",
|
||||||
"value": 0,
|
"value": 0,
|
||||||
"step": 100,
|
"step": 0.1,
|
||||||
"decimals": 6,
|
"decimals": 6,
|
||||||
|
"siPrefix": true,
|
||||||
|
"pinSiPrefix": "m",
|
||||||
|
"suffix": "A",
|
||||||
"limits": [
|
"limits": [
|
||||||
0,
|
0,
|
||||||
2000
|
2
|
||||||
],
|
],
|
||||||
"suffix": "mA",
|
|
||||||
"thermostat:set_param": {
|
"thermostat:set_param": {
|
||||||
"topic": "pwm",
|
"topic": "pwm",
|
||||||
"field": "max_i_neg"
|
"field": "max_i_neg"
|
||||||
@ -280,13 +286,15 @@
|
|||||||
"name": "output_min",
|
"name": "output_min",
|
||||||
"title": "Minimum",
|
"title": "Minimum",
|
||||||
"type": "float",
|
"type": "float",
|
||||||
"step": 100,
|
"step": 0.1,
|
||||||
"limits": [
|
"limits": [
|
||||||
-2000,
|
-2,
|
||||||
2000
|
2
|
||||||
],
|
],
|
||||||
"decimals": 6,
|
"decimals": 6,
|
||||||
"suffix": "mA",
|
"siPrefix": true,
|
||||||
|
"pinSiPrefix": "m",
|
||||||
|
"suffix": "A",
|
||||||
"thermostat:set_param": {
|
"thermostat:set_param": {
|
||||||
"topic": "pid",
|
"topic": "pid",
|
||||||
"field": "output_min"
|
"field": "output_min"
|
||||||
@ -298,13 +306,15 @@
|
|||||||
"name": "output_max",
|
"name": "output_max",
|
||||||
"title": "Maximum",
|
"title": "Maximum",
|
||||||
"type": "float",
|
"type": "float",
|
||||||
"step": 100,
|
"step": 0.1,
|
||||||
"limits": [
|
"limits": [
|
||||||
-2000,
|
-2,
|
||||||
2000
|
2
|
||||||
],
|
],
|
||||||
"decimals": 6,
|
"decimals": 6,
|
||||||
"suffix": "mA",
|
"siPrefix": true,
|
||||||
|
"pinSiPrefix": "m",
|
||||||
|
"suffix": "A",
|
||||||
"thermostat:set_param": {
|
"thermostat:set_param": {
|
||||||
"topic": "pid",
|
"topic": "pid",
|
||||||
"field": "output_max"
|
"field": "output_max"
|
||||||
@ -337,12 +347,14 @@
|
|||||||
"type": "float",
|
"type": "float",
|
||||||
"value": 0,
|
"value": 0,
|
||||||
"decimals": 6,
|
"decimals": 6,
|
||||||
"step": 100,
|
"step": 0.1,
|
||||||
"limits": [
|
"limits": [
|
||||||
-2000,
|
-2,
|
||||||
2000
|
2
|
||||||
],
|
],
|
||||||
"suffix": "mA",
|
"siPrefix": true,
|
||||||
|
"pinSiPrefix": "m",
|
||||||
|
"suffix": "A",
|
||||||
"pid_autotune": "test_current",
|
"pid_autotune": "test_current",
|
||||||
"tip": "The testing current when autotuning"
|
"tip": "The testing current when autotuning"
|
||||||
},
|
},
|
||||||
|
95
pytec/pytec/gui/view/pin_si_prefix.py
Normal file
95
pytec/pytec/gui/view/pin_si_prefix.py
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
from pyqtgraph import SpinBox
|
||||||
|
import pyqtgraph.functions as fn
|
||||||
|
from pyqtgraph.parametertree import registerParameterItemType
|
||||||
|
from pyqtgraph.parametertree.parameterTypes import SimpleParameter, NumericParameterItem
|
||||||
|
|
||||||
|
|
||||||
|
class PinSIPrefixSpinBox(SpinBox):
|
||||||
|
"""
|
||||||
|
Extension of PyQtGraph's SpinBox widget.
|
||||||
|
Adds:
|
||||||
|
|
||||||
|
* The "pinSiPrefix" option, where the siPrefix could be fixed to a
|
||||||
|
particular scale instead of as determined by its value.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def setOpts(self, **opts):
|
||||||
|
if "pinSiPrefix" in opts:
|
||||||
|
self.opts["pinSiPrefix"] = opts.pop("pinSiPrefix")
|
||||||
|
|
||||||
|
super().setOpts(**opts)
|
||||||
|
|
||||||
|
def formatText(self, prev=None):
|
||||||
|
"""
|
||||||
|
In addition to pyqtgraph.SpinBox's formatting, incorporate the
|
||||||
|
'pinSiPrefix' mechanism, where SI prefixes could be fixed.
|
||||||
|
"""
|
||||||
|
# Code modified from the PyQtGraph source
|
||||||
|
|
||||||
|
# get the number of decimal places to print
|
||||||
|
decimals = self.opts['decimals']
|
||||||
|
suffix = self.opts['suffix']
|
||||||
|
prefix = self.opts['prefix']
|
||||||
|
pin_si_prefix = self.opts.get("pinSiPrefix")
|
||||||
|
|
||||||
|
# format the string
|
||||||
|
val = self.value()
|
||||||
|
if self.opts['siPrefix'] is True:
|
||||||
|
# SI prefix was requested, so scale the value accordingly
|
||||||
|
if pin_si_prefix is not None and pin_si_prefix in fn.SI_PREFIX_EXPONENTS:
|
||||||
|
# fixed scale
|
||||||
|
s = 10**-fn.SI_PREFIX_EXPONENTS[pin_si_prefix]
|
||||||
|
p = pin_si_prefix
|
||||||
|
elif self.val == 0 and prev is not None:
|
||||||
|
# special case: if it's zero use the previous prefix
|
||||||
|
(s, p) = fn.siScale(prev)
|
||||||
|
else:
|
||||||
|
(s, p) = fn.siScale(val)
|
||||||
|
parts = {'value': val, 'suffix': suffix, 'decimals': decimals, 'siPrefix': p, 'scaledValue': s*val, 'prefix':prefix}
|
||||||
|
|
||||||
|
else:
|
||||||
|
# no SI prefix /suffix requested; scale is 1
|
||||||
|
parts = {'value': val, 'suffix': suffix, 'decimals': decimals, 'siPrefix': '', 'scaledValue': val, 'prefix':prefix}
|
||||||
|
|
||||||
|
parts['prefixGap'] = '' if parts['prefix'] == '' else ' '
|
||||||
|
parts['suffixGap'] = '' if (parts['suffix'] == '' and parts['siPrefix'] == '') else ' '
|
||||||
|
|
||||||
|
return self.opts['format'].format(**parts)
|
||||||
|
|
||||||
|
|
||||||
|
class PinSIPrefixNumericParameterItem(NumericParameterItem):
|
||||||
|
"""
|
||||||
|
Subclasses PyQtGraph's `NumericParameterItem` and uses
|
||||||
|
PinSIPrefixSpinBox for editing.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def makeWidget(self):
|
||||||
|
opts = self.param.opts
|
||||||
|
t = opts['type']
|
||||||
|
defs = {
|
||||||
|
'value': 0, 'min': None, 'max': None,
|
||||||
|
'step': 1.0, 'dec': False,
|
||||||
|
'siPrefix': False, 'suffix': '', 'decimals': 3,
|
||||||
|
'pinSiPrefix': None,
|
||||||
|
}
|
||||||
|
if t == 'int':
|
||||||
|
defs['int'] = True
|
||||||
|
defs['minStep'] = 1.0
|
||||||
|
for k in defs:
|
||||||
|
if k in opts:
|
||||||
|
defs[k] = opts[k]
|
||||||
|
if 'limits' in opts:
|
||||||
|
defs['min'], defs['max'] = opts['limits']
|
||||||
|
w = PinSIPrefixSpinBox()
|
||||||
|
w.setOpts(**defs)
|
||||||
|
w.sigChanged = w.sigValueChanged
|
||||||
|
w.sigChanging = w.sigValueChanging
|
||||||
|
return w
|
||||||
|
|
||||||
|
|
||||||
|
registerParameterItemType(
|
||||||
|
"float", PinSIPrefixNumericParameterItem, SimpleParameter, override=True
|
||||||
|
)
|
||||||
|
registerParameterItemType(
|
||||||
|
"int", PinSIPrefixNumericParameterItem, SimpleParameter, override=True
|
||||||
|
)
|
@ -268,9 +268,6 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
if change == "value":
|
if change == "value":
|
||||||
new_value = data
|
new_value = data
|
||||||
if "thermostat:set_param" in inner_param.opts:
|
if "thermostat:set_param" in inner_param.opts:
|
||||||
atse marked this conversation as resolved
Outdated
|
|||||||
if inner_param.opts.get("suffix", None) == "mA":
|
|
||||||
new_value /= 1000 # Given in mA
|
|
||||||
|
|
||||||
thermostat_param = inner_param.opts["thermostat:set_param"]
|
thermostat_param = inner_param.opts["thermostat:set_param"]
|
||||||
|
|
||||||
# Handle thermostat command irregularities
|
# Handle thermostat command irregularities
|
||||||
|
Loading…
Reference in New Issue
Block a user
Looks like a hack. The unit conversion should not be affected by the title.
Removed the need for it in latest force-push with the
pinSiPrefix
option ofUnitfulSpinBox
.