Experiment Class¶
The Experiment
class provides an all-in-one interface for running simple experiments. It combines the effect of instantiating a TCLab
, a Historian
and optionally a Plotter
.
[3]:
%matplotlib notebook
[8]:
import tclab
with tclab.Experiment(connected=False, plot=True, speedup=10) as experiment:
for t in experiment.clock():
experiment.lab.Q1(0 if experiment.lab.T1 > 40 else 100)
Simulated TCLab
TCLab Model disconnected successfully.
Accessing results¶
experiment.historian
contains the historian instance which was created by Experiment
:
[14]:
experiment.historian.log[:5]
[14]:
[(0, 20.812700940382776, 20.788384634613717, 0, 0),
(1.0, 20.905995814379526, 20.978928790222188, 100, 0),
(2.0, 21.245346825807175, 21.23492347886724, 100, 0),
(3.0, 21.071910253650344, 21.17195991571187, 100, 0),
(4.0, 21.11707641600787, 20.841145497515168, 100, 0)]
Even simpler experiments¶
Sometimes you can use a simple function to describe the experiment you are running. In this case, it is simpler to use runexperiment
. Experiment
and runexperiment
share arguments.
[9]:
from tclab import runexperiment
[10]:
%matplotlib notebook
[11]:
def onoffcontroller(t, lab):
lab.Q1(0 if lab.T1 > 40 else 100)
[12]:
experiment = runexperiment(onoffcontroller, connected=False, time=100, speedup=10)
Simulated TCLab
TCLab Model disconnected successfully.
[ ]: