コード例 #1
0
ファイル: 0B-99-pidgui.py プロジェクト: jckantor/CBE30338
    def action_start(self, w):
        if self.usemodel.value:
            self.lab = TCLabModel()
        else:
            self.lab = TCLab()

        self.historian = Historian([('T1', lambda: self.lab.T1),
                                    ('Q1', self.lab.Q1),
                                    ('setpoint', lambda: self.setpoint.value),
                                    ('error', lambda: self.pid.e),
                                    ('eint', lambda: self.pid.eint),
                                    ('dedt', lambda: self.pid.dedt),
                                    ('output', lambda: self.pid.output)
                                    ])
        if self.plotter:
            plt.close(self.plotter.fig)

        self.plotter = Plotter(self.historian, layout=(('T1', 'setpoint'),
                                                       ('error',),
                                                       ('eint',),
                                                       ('dedt',),
                                                       ('Q1', 'output') ))

        self.timer.start()
        self.t = 0


        self.start.disabled = True
        self.stop.disabled = False
        self.action_manual(w)
コード例 #2
0
    def action_start(self, w):
        if self.usemodel.value:
            self.lab = TCLabModel()
        else:
            self.lab = TCLab()

        self.historian = Historian([('T1', lambda: self.lab.T1),
                                    ('Q1', self.lab.Q1),
                                    ('setpoint', lambda: self.setpoint.value),
                                    ('error', lambda: self.pid.e),
                                    ('eint', lambda: self.pid.eint),
                                    ('dedt', lambda: self.pid.dedt),
                                    ('output', lambda: self.pid.output)])
        if self.plotter:
            plt.close(self.plotter.fig)

        self.plotter = Plotter(self.historian,
                               layout=(('T1', 'setpoint'), ('error', ),
                                       ('eint', ), ('dedt', ), ('Q1',
                                                                'output')))

        self.timer.start()
        self.t = 0

        self.start.disabled = True
        self.stop.disabled = False
        self.action_manual(w)
コード例 #3
0
import numpy as np
from tclab import TCLab
import time
import matplotlib.pyplot as plt

a = TCLab()

# total time points
n = 10 * 60 + 1  # min in sec

# turn on LED
a.LED(100)

# store temperatures for plotting
T1s = np.ones(n) * a.T2
T2s = np.ones(n) * a.T1
T1sp = np.ones(n) * 25.0
T2sp = np.ones(n) * 25.0
# store heater values
Q1s = np.ones(n)
Q2s = np.ones(n)
# store time
tm = np.zeros(n)

# set point changes
T1sp[5:] = 40.0
T1sp[300:] = 30.0
T2sp[150:] = 30.0
T2sp[450:] = 35.0

# Create plot
コード例 #4
0
import numpy as np
import time
import matplotlib.pyplot as plt
import random
# get gekko package with:
#   pip install gekko
from gekko import GEKKO
# get tclab package with:
#   pip install tclab
from tclab import TCLab

# Connect to Arduino
a = TCLab()

# Final time
tf = 10  # min
# number of data points (1 pt every 3 seconds)
n = tf * 20 + 1

# Configure heater levels
# Percent Heater (0-100%)
Q1s = np.zeros(n)
Q2s = np.zeros(n)
# Heater random steps every 50 sec
# Alternate steps by Q1 and Q2
Q1s[3:] = 100.0
Q1s[50:] = 0.0
Q1s[100:] = 80.0

Q2s[25:] = 60.0
Q2s[75:] = 100.0
コード例 #5
0
def test_lock_release():
    """Check that we release the lock"""
    with TCLab() as lab:
        _ = lab.T1
    lab = TCLab()
    lab.close()
コード例 #6
0
def test_already_connected():
    with pytest.raises(AlreadyConnectedError):
        lab = TCLab()
        _ = TCLab()
    lab.close()
コード例 #7
0
def test_context():
    with TCLab() as _:
        pass
コード例 #8
0
def test_constructor_port():
    """Raise RuntimeError for an unrecognized port."""
    print("TRAVIS" in os.environ)
    with pytest.raises(RuntimeError):
        with TCLab(port='nonsense') as a:
            pass
コード例 #9
0
ファイル: 0B-99-pidgui.py プロジェクト: jckantor/CBE30338
class PIDGUI:
    def __init__(self):
        self.t = 0
        self.plotter = None

        self.pid = PID()

        self.timer = tornado.ioloop.PeriodicCallback(self.update, 1000)
        self.mode = 'manual'

        self.usemodel = Checkbox(description="Use model")

        # buttons
        self.start = actionbutton('Start', self.action_start)
        self.start.disabled = False
        self.manual = actionbutton('Manual', self.action_manual)
        self.auto = actionbutton('Auto', self.action_auto)
        self.stop = actionbutton('Stop', self.action_stop)
        buttons = HBox([self.usemodel,
                        self.start,
                        self.auto,
                        self.manual,
                        self.stop])

        # Sliders for heaters
        self.gain = slider('Gain', self.action_gain, maxvalue=10)
        self.gain.value = 1
        self.tau_i = slider(r'$\tau_I$', self.action_tau_i, minvalue=0)
        self.tau_i.value = 100
        self.tau_d = slider(r'$\tau_D$', self.action_tau_d, maxvalue=10)

        parameters = VBox([self.gain, self.tau_i, self.tau_d])

        # Setpoint
        self.setpoint = slider('Setpoint', self.action_setpoint,
                               minvalue=20, maxvalue=70)
        self.setpoint.value = 30
        self.Q1 = slider('Q1', self.action_Q1, disabled=False)
        self.gui = VBox([buttons,
                         parameters,
                         self.setpoint,
                         self.Q1
                        ])


    def update(self):
        self.t += 1
        setnow(self.t)
        self.plotter.update(self.t)
        if self.mode == 'auto':
            Q1 = self.pid.update(self.setpoint.value, self.lab.T1)
        else:
            Q1 = self.Q1.value

        self.lab.Q1(Q1)

    def action_start(self, w):
        if self.usemodel.value:
            self.lab = TCLabModel()
        else:
            self.lab = TCLab()

        self.historian = Historian([('T1', lambda: self.lab.T1),
                                    ('Q1', self.lab.Q1),
                                    ('setpoint', lambda: self.setpoint.value),
                                    ('error', lambda: self.pid.e),
                                    ('eint', lambda: self.pid.eint),
                                    ('dedt', lambda: self.pid.dedt),
                                    ('output', lambda: self.pid.output)
                                    ])
        if self.plotter:
            plt.close(self.plotter.fig)

        self.plotter = Plotter(self.historian, layout=(('T1', 'setpoint'),
                                                       ('error',),
                                                       ('eint',),
                                                       ('dedt',),
                                                       ('Q1', 'output') ))

        self.timer.start()
        self.t = 0


        self.start.disabled = True
        self.stop.disabled = False
        self.action_manual(w)

    def action_stop(self, w):
        self.timer.stop()
        self.lab.close()

        # FIXME: At the moment restarting requires all the axes to be rebuilt
        # So we can't allow start again.
        self.start.disabled = True
        self.auto.disabled = True
        self.manual.disabled = True
        self.stop.disabled = True

    def action_auto(self, w):
        self.mode = 'auto'
        self.manual.disabled = False
        self.auto.disabled = True

        self.Q1.disabled = True
        self.setpoint.disabled = False
        self.gain.disabled = False
        self.tau_i.disabled = False
        self.tau_d.disabled = False

    def action_manual(self, w):
        self.mode = 'manual'
        self.manual.disabled = True
        self.auto.disabled = False

        self.Q1.disabled = False
        self.setpoint.disabled = True
        self.gain.disabled = True
        self.tau_i.disabled = True
        self.tau_d.disabled = True

    def action_gain(self, w):
        self.pid.K = self.gain.value

    def action_tau_i(self, w):
        self.pid.taui = self.tau_i.value

    def action_tau_d(self, w):
        self.pid.taud = self.tau_d.value

    def action_setpoint(self, w):
        pass

    def action_Q1(self, w):
        pass
コード例 #10
0
class PIDGUI:
    def __init__(self):
        self.t = 0
        self.plotter = None

        self.pid = PID()

        self.timer = tornado.ioloop.PeriodicCallback(self.update, 1000)
        self.mode = 'manual'

        self.usemodel = Checkbox(description="Use model")

        # buttons
        self.start = actionbutton('Start', self.action_start)
        self.start.disabled = False
        self.manual = actionbutton('Manual', self.action_manual)
        self.auto = actionbutton('Auto', self.action_auto)
        self.stop = actionbutton('Stop', self.action_stop)
        buttons = HBox(
            [self.usemodel, self.start, self.auto, self.manual, self.stop])

        # Sliders for heaters
        self.gain = slider('Gain', self.action_gain, maxvalue=10)
        self.gain.value = 1
        self.tau_i = slider(r'$\tau_I$', self.action_tau_i, minvalue=0)
        self.tau_i.value = 100
        self.tau_d = slider(r'$\tau_D$', self.action_tau_d, maxvalue=10)

        parameters = VBox([self.gain, self.tau_i, self.tau_d])

        # Setpoint
        self.setpoint = slider('Setpoint',
                               self.action_setpoint,
                               minvalue=20,
                               maxvalue=70)
        self.setpoint.value = 30
        self.Q1 = slider('Q1', self.action_Q1, disabled=False)
        self.gui = VBox([buttons, parameters, self.setpoint, self.Q1])

    def update(self):
        self.t += 1
        setnow(self.t)
        self.plotter.update(self.t)
        if self.mode == 'auto':
            Q1 = self.pid.update(self.setpoint.value, self.lab.T1)
        else:
            Q1 = self.Q1.value

        self.lab.Q1(Q1)

    def action_start(self, w):
        if self.usemodel.value:
            self.lab = TCLabModel()
        else:
            self.lab = TCLab()

        self.historian = Historian([('T1', lambda: self.lab.T1),
                                    ('Q1', self.lab.Q1),
                                    ('setpoint', lambda: self.setpoint.value),
                                    ('error', lambda: self.pid.e),
                                    ('eint', lambda: self.pid.eint),
                                    ('dedt', lambda: self.pid.dedt),
                                    ('output', lambda: self.pid.output)])
        if self.plotter:
            plt.close(self.plotter.fig)

        self.plotter = Plotter(self.historian,
                               layout=(('T1', 'setpoint'), ('error', ),
                                       ('eint', ), ('dedt', ), ('Q1',
                                                                'output')))

        self.timer.start()
        self.t = 0

        self.start.disabled = True
        self.stop.disabled = False
        self.action_manual(w)

    def action_stop(self, w):
        self.timer.stop()
        self.lab.close()

        # FIXME: At the moment restarting requires all the axes to be rebuilt
        # So we can't allow start again.
        self.start.disabled = True
        self.auto.disabled = True
        self.manual.disabled = True
        self.stop.disabled = True

    def action_auto(self, w):
        self.mode = 'auto'
        self.manual.disabled = False
        self.auto.disabled = True

        self.Q1.disabled = True
        self.setpoint.disabled = False
        self.gain.disabled = False
        self.tau_i.disabled = False
        self.tau_d.disabled = False

    def action_manual(self, w):
        self.mode = 'manual'
        self.manual.disabled = True
        self.auto.disabled = False

        self.Q1.disabled = False
        self.setpoint.disabled = True
        self.gain.disabled = True
        self.tau_i.disabled = True
        self.tau_d.disabled = True

    def action_gain(self, w):
        self.pid.K = self.gain.value

    def action_tau_i(self, w):
        self.pid.taui = self.tau_i.value

    def action_tau_d(self, w):
        self.pid.taud = self.tau_d.value

    def action_setpoint(self, w):
        pass

    def action_Q1(self, w):
        pass