forked from M-Labs/thermostat
Separate min and max current
This commit is contained in:
parent
b4504bcfaa
commit
da73f537b7
@ -84,13 +84,8 @@ class WrappedClient(QObject, Client):
|
||||
|
||||
async def _check_zero_limits(self):
|
||||
pwm_report = await self.get_pwm()
|
||||
for pwm_channel in pwm_report:
|
||||
ch = pwm_channel["channel"]
|
||||
if (neg := pwm_channel["max_i_neg"]["value"]) != (pos := pwm_channel["max_i_pos"]["value"]):
|
||||
# Set the minimum of the 2
|
||||
lowest = min(neg, pos)
|
||||
await self.set_param("pwm", ch, 'max_i_neg', lowest)
|
||||
await self.set_param("pwm", ch, 'max_i_pos', lowest)
|
||||
pid_report = await self.get_pid()
|
||||
# TODO: Get pid output_max and max_i_pos synced. Same for min and neg.
|
||||
|
||||
|
||||
class ClientWatcher(QObject):
|
||||
@ -233,8 +228,10 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
'suffix': '°C', 'param': [('pid', ch, 'target')]},
|
||||
]},
|
||||
{'name': 'Limits', 'expanded': False, 'type': 'group', 'children': [
|
||||
{'name': 'Max Absolute Current', 'type': 'float', 'value': 0, 'step': 0.1, 'limits': (0, 3), 'siPrefix': True,
|
||||
'suffix': 'A', 'param': [('pwm', ch, 'max_i_pos'), ('pid', ch, 'output_min', '-'), ('pwm', ch, 'max_i_neg'), ('pid', ch, 'output_max')]},
|
||||
{'name': 'Max Current', 'type': 'float', 'value': 0, 'step': 0.1, 'limits': (0, 3), 'siPrefix': True,
|
||||
'suffix': 'A', 'param': [('pwm', ch, 'max_i_pos'), ('pid', ch, 'output_max')]},
|
||||
{'name': 'Min Current', 'type': 'float', 'value': 0, 'step': 0.1, 'limits': (-3, 0), 'siPrefix': True,
|
||||
'suffix': 'A', 'param': [('pwm', ch, 'max_i_neg', '-'), ('pid', ch, 'output_min')]},
|
||||
{'name': 'Max Absolute Voltage', 'type': 'float', 'value': 0, 'step': 0.1, 'limits': (0, 5), 'siPrefix': True,
|
||||
'suffix': 'V', 'param': [('pwm', ch, 'max_v')]},
|
||||
]}
|
||||
@ -519,8 +516,8 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
|
||||
self.plot_settings.setMenu(self.plot_menu)
|
||||
|
||||
@pyqtSlot(list)
|
||||
def set_limits_warning(self, limits_zeroed: list):
|
||||
@pyqtSlot(set)
|
||||
def set_limits_warning(self, limits_zeroed: set):
|
||||
for channel in limits_zeroed:
|
||||
if len(channel) != 0:
|
||||
break
|
||||
@ -531,21 +528,18 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
|
||||
report_str = "The following output limits are set to zero:\n"
|
||||
for ch in range(2):
|
||||
had_zeros = False
|
||||
first = True
|
||||
for limit in "max_i_pos", "max_v":
|
||||
if limit in limits_zeroed[ch]:
|
||||
if not first:
|
||||
report_str += ", "
|
||||
if not had_zeros:
|
||||
report_str += f"Channel {ch}: "
|
||||
had_zeros = True
|
||||
report_str += '"Max Absolute Current"' if limit == "max_i_pos" else '"Max Absolute Voltage"'
|
||||
first = False
|
||||
if had_zeros:
|
||||
report_str += '\n'
|
||||
zeroed = False
|
||||
if 'max_i_pos' in limits_zeroed[ch] and 'max_i_neg' in limits_zeroed[ch]:
|
||||
report_str += "Max Current, Min Current"
|
||||
zeroed = True
|
||||
if 'max_v' in limits_zeroed[ch]:
|
||||
report_str += ", " if zeroed else ""
|
||||
report_str += "Max Absolute Voltage"
|
||||
zeroed = True
|
||||
if zeroed:
|
||||
report_str += f" for Channel {ch}\n"
|
||||
|
||||
report_str += "\nThere will be no overall output on channels with zeroed limits."
|
||||
report_str += "\nThese limit(s) are restricting the channel(s) from producing current."
|
||||
|
||||
pixmapi = getattr(QtWidgets.QStyle.StandardPixmap, "SP_MessageBoxWarning")
|
||||
icon = self.style().standardIcon(pixmapi)
|
||||
@ -677,8 +671,8 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
if inner_param.name() == 'Control Method' and not data:
|
||||
return
|
||||
for thermostat_param in inner_param.opts["param"]:
|
||||
if len(thermostat_param) == 4: # To tack on prefixes to the data
|
||||
set_param_args = (*thermostat_param[:3], f'{thermostat_param[3]}{data}')
|
||||
if len(thermostat_param) == 4: # The only instance is for negative data
|
||||
set_param_args = (*thermostat_param[:3], -data)
|
||||
elif inner_param.name() == 'Postfilter Rate':
|
||||
set_param_args = (*thermostat_param, *data)
|
||||
elif inner_param.name() == 'Control Method':
|
||||
@ -820,17 +814,18 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
|
||||
|
||||
@pyqtSlot(list)
|
||||
def update_pwm(self, pwm_data):
|
||||
channel_zeroed_limits = [[] for i in range(2)]
|
||||
channel_zeroed_limits = [set() for i in range(2)]
|
||||
|
||||
for pwm_params in pwm_data:
|
||||
channel = pwm_params["channel"]
|
||||
with QSignalBlocker(self.params[channel]):
|
||||
self.params[channel].child("Output Config", "Limits", "Max Absolute Voltage").setValue(pwm_params["max_v"]["value"])
|
||||
self.params[channel].child("Output Config", "Limits", "Max Absolute Current").setValue(pwm_params["max_i_pos"]["value"])
|
||||
self.params[channel].child("Output Config", "Limits", "Max Current").setValue(pwm_params["max_i_pos"]["value"])
|
||||
self.params[channel].child("Output Config", "Limits", "Min Current").setValue(-pwm_params["max_i_neg"]["value"])
|
||||
|
||||
for limit in "max_i_pos", "max_v":
|
||||
for limit in "max_i_pos", "max_i_neg", "max_v":
|
||||
if pwm_params[limit]["value"] == 0.0:
|
||||
channel_zeroed_limits[channel].append(limit)
|
||||
channel_zeroed_limits[channel].add(limit)
|
||||
|
||||
self.set_limits_warning(channel_zeroed_limits)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user