|
| 1 | +# =============================================================================== |
| 2 | +# Copyright 2024 ross |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +# =============================================================================== |
| 16 | +from traits.api import Any |
| 17 | +from traitsui.api import UItem, TableEditor, InstanceEditor, HGroup |
| 18 | +from traitsui.table_column import ObjectColumn |
| 19 | +from traitsui.extras.checkbox_column import CheckboxColumn |
| 20 | + |
| 21 | +from pychron.graph.time_series_graph import TimeSeriesStreamStackedGraph |
| 22 | +from pychron.hardware.bakeout_plc import BakeoutPLC |
| 23 | +from pychron.loggable import Loggable |
| 24 | +from pychron.managers.stream_graph_manager import StreamGraphManager |
| 25 | + |
| 26 | + |
| 27 | +class BakeoutManager(StreamGraphManager): |
| 28 | + controller = Any |
| 29 | + settings_name = "bakeout_streaming" |
| 30 | + |
| 31 | + def _create_manager( |
| 32 | + self, klass, manager, params, port=None, host=None, remote=False |
| 33 | + ): |
| 34 | + return self.application.get_service(BakeoutManager) |
| 35 | + |
| 36 | + def _controller_default(self): |
| 37 | + return BakeoutPLC(name="controller", configuration_dir_name="bakeout") |
| 38 | + |
| 39 | + def prepare_destroy(self): |
| 40 | + self.set_streaming_active(False) |
| 41 | + self.stop_scan() |
| 42 | + self.controller.prepare_destroy() |
| 43 | + |
| 44 | + def activate(self): |
| 45 | + self.debug("asdfascasdcasdc") |
| 46 | + self.set_streaming_active(True) |
| 47 | + # self.bind_preferences() |
| 48 | + |
| 49 | + # self.load_event_marker_config() |
| 50 | + self.setup_scan() |
| 51 | + # self.readout_view.start() |
| 52 | + self.reset_scan_timer() |
| 53 | + |
| 54 | + def setup_scan(self): |
| 55 | + self._reset_graph() |
| 56 | + self.graph_scan_width = 10 |
| 57 | + self._graph_scan_width_changed() |
| 58 | + |
| 59 | + def _update_scan_graph(self): |
| 60 | + for ci in self.get_display_channels(): |
| 61 | + t = self.controller.read_temperature(ci.index) |
| 62 | + if t is None: |
| 63 | + continue |
| 64 | + |
| 65 | + sp = self.controller.read_setpoint(ci.index) |
| 66 | + dc = self.controller.read_duty_cycle(ci.index) |
| 67 | + self.controller.read_overtemp_ishighhigh(ci.index) |
| 68 | + |
| 69 | + self.graph.record(t, series=ci.index) |
| 70 | + self.graph.record(sp, series=ci.index + 1) |
| 71 | + self.graph.record(dc, plotid=1, series=ci.index) |
| 72 | + |
| 73 | + def _graph_factory(self, *args, **kw): |
| 74 | + g = TimeSeriesStreamStackedGraph() |
| 75 | + # g.plotcontainer.padding_top = 5 |
| 76 | + # g.plotcontainer.padding_right = 5 |
| 77 | + g.new_plot( |
| 78 | + xtitle="Time (s)", |
| 79 | + ytitle="Temp. (C)", |
| 80 | + padding_top=5, |
| 81 | + padding_left=75, |
| 82 | + padding_right=5, |
| 83 | + show_legend="ul", |
| 84 | + ) |
| 85 | + g.set_scan_width(600, plotid=0) |
| 86 | + g.set_data_limits(1.8 * 600, plotid=0) |
| 87 | + |
| 88 | + # Output/Duty Cycle |
| 89 | + g.new_plot( |
| 90 | + ytitle="Output/Duty Cycle (%)", |
| 91 | + padding_top=5, |
| 92 | + padding_left=75, |
| 93 | + padding_right=5, |
| 94 | + ) |
| 95 | + |
| 96 | + g.set_scan_width(600, plotid=1) |
| 97 | + g.set_data_limits(1.8 * 600, plotid=1) |
| 98 | + g.set_y_limits(min_=-2, max_=102, plotid=1) |
| 99 | + for channel in self.controller.channels: |
| 100 | + series, _ = g.new_series( |
| 101 | + plotid=0, color=channel.color, name=channel.shortname |
| 102 | + ) |
| 103 | + g.new_series( |
| 104 | + plotid=0, |
| 105 | + # render_style="connectedhold", |
| 106 | + line_style="dash", |
| 107 | + color=series.color, |
| 108 | + name=f"{channel.shortname}, Setpoint", |
| 109 | + ) |
| 110 | + |
| 111 | + g.new_series(plotid=1, name=channel.shortname, color=series.color) |
| 112 | + |
| 113 | + return g |
| 114 | + |
| 115 | + def get_display_channels(self): |
| 116 | + return [ci for ci in self.controller.channels if ci.display] |
| 117 | + |
| 118 | + |
| 119 | +if __name__ == "__main__": |
| 120 | + b = BakeoutManager() |
| 121 | + b.activate() |
| 122 | + b.setup_scan() |
| 123 | + |
| 124 | +# ============= EOF ============================================= |
0 commit comments