Commit 36dfab2a authored by Valentin Valls's avatar Valentin Valls
Browse files

Rework regulation to only send new data to the plot

parent e077d9d6
...@@ -759,9 +759,6 @@ class Loop(SamplingCounterController): ...@@ -759,9 +759,6 @@ class Loop(SamplingCounterController):
self._wait_mode = self.WaitMode.DEADBAND # RAMP self._wait_mode = self.WaitMode.DEADBAND # RAMP
self._history_size = 100
self.clear_history_data()
self.reg_plot = None self.reg_plot = None
self.max_sampling_frequency = config.get("max_sampling_frequency", 5) self.max_sampling_frequency = config.get("max_sampling_frequency", 5)
...@@ -942,29 +939,14 @@ class Loop(SamplingCounterController): ...@@ -942,29 +939,14 @@ class Loop(SamplingCounterController):
def is_in_idleband(self): def is_in_idleband(self):
return self._x_is_in_idleband(self.input.read()) return self._x_is_in_idleband(self.input.read())
##--- DATA HISTORY METHODS def get_last_data(self):
def clear_history_data(self): data = {
self._history_start_time = time.time() "time": time.time(),
self.history_data = {"input": [], "output": [], "setpoint": [], "time": []} "setpoint": self._get_working_setpoint(),
"input": self._get_last_input_value(),
self._history_counter = 0 "output": self._get_last_output_value(),
}
def _store_history_data(self): return data
xval = time.time() - self._history_start_time
# xval = self._history_counter
self._history_counter += 1
self.history_data["time"].append(xval)
self.history_data["setpoint"].append(self._get_working_setpoint())
self.history_data["input"].append(self._get_last_input_value())
self.history_data["output"].append(self._get_last_output_value())
for data in self.history_data.values():
dx = len(data) - self._history_size
if dx > 0:
for i in range(dx):
data.pop(0)
def _get_last_input_value(self): def _get_last_input_value(self):
return self.input.read() return self.input.read()
...@@ -972,24 +954,6 @@ class Loop(SamplingCounterController): ...@@ -972,24 +954,6 @@ class Loop(SamplingCounterController):
def _get_last_output_value(self): def _get_last_output_value(self):
return self.output.read() return self.output.read()
@property
def history_size(self):
"""
Get the size of the buffer that stores the latest data (input_value, output_value, working_setpoint)
"""
log_debug(self, "Loop:get_history_size")
return self._history_size
@history_size.setter
def history_size(self, value):
"""
Set the size of the buffer that stores the latest data (input_value, output_value, working_setpoint)
"""
log_debug(self, "Loop:set_history_size: %s" % (value,))
self._history_size = value
##--- CTRL METHODS ##--- CTRL METHODS
@property @property
def setpoint(self): def setpoint(self):
...@@ -2049,7 +2013,6 @@ class RegPlot: ...@@ -2049,7 +2013,6 @@ class RegPlot:
self.create_plot() self.create_plot()
if not self.task: if not self.task:
self.loop.clear_history_data()
self._stop_event.clear() self._stop_event.clear()
self.task = gevent.spawn(self.run) self.task = gevent.spawn(self.run)
...@@ -2068,25 +2031,19 @@ class RegPlot: ...@@ -2068,25 +2031,19 @@ class RegPlot:
except (gevent.timeout.Timeout, Exception) as e: except (gevent.timeout.Timeout, Exception) as e:
pass pass
# update data history
self.loop._store_history_data()
try: try:
dbp = [ data = self.loop.get_last_data()
x + self.loop.deadband for x in self.loop.history_data["setpoint"] dbp = data["setpoint"] + self.loop.deadband
] dbm = data["setpoint"] - self.loop.deadband
dbm = [
x - self.loop.deadband for x in self.loop.history_data["setpoint"]
]
# Update curves plot (refreshes the plot widget) # Update curves plot (refreshes the plot widget)
self.fig.set_data( self.fig.append_data(
time=self.loop.history_data["time"], time=[data["time"]],
input=self.loop.history_data["input"], input=[data["input"]],
output=self.loop.history_data["output"], output=[data["output"]],
setpoint=self.loop.history_data["setpoint"], setpoint=[data["setpoint"]],
deadband_high=dbp, deadband_high=[dbp],
deadband_low=dbm, deadband_low=[dbm],
) )
except (gevent.timeout.Timeout, Exception): except (gevent.timeout.Timeout, Exception):
......
...@@ -426,10 +426,6 @@ The plot can be stopped and restarted using the commands `plt.stop()` and `plot. ...@@ -426,10 +426,6 @@ The plot can be stopped and restarted using the commands `plt.stop()` and `plot.
The refresh time of the plot can be modified with `plt.sleep_time = 0.1`. The refresh time of the plot can be modified with `plt.sleep_time = 0.1`.
The size of stored data for the plot can be modified: `loop.history_size = 150`.
The stored data can be cleared with: `loop.clear_history_data()`
```python ```python
TEST_SESSION [4]: loop.plot() TEST_SESSION [4]: loop.plot()
......
...@@ -150,8 +150,6 @@ def test_soft_regulation_failure(temp_soft_tloop): ...@@ -150,8 +150,6 @@ def test_soft_regulation_failure(temp_soft_tloop):
def test_regulation_plot(temp_tloop, flint_session): def test_regulation_plot(temp_tloop, flint_session):
x = temp_tloop x = temp_tloop
x.setpoint = 0 x.setpoint = 0
x.history_size = 150
x.clear_history_data()
plt = x.plot() plt = x.plot()
plt.stop() plt.stop()
gevent.sleep(1.0) gevent.sleep(1.0)
......
Supports Markdown
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