ChimeraTK-ApplicationCore 04.06.00
Loading...
Searching...
No Matches
oven_sim.py
Go to the documentation of this file.
1#!/usr/bin/python3
2
3# This is a simple simulator script for an oven.
4# It is meant to run in parallel to the demo_example server.
5#
6# Both are accessing the same device using the same DMAP file. Since the device is
7# backed by the SharedMemoryDummy, it is possible to react to the setpoint provided
8# by the demo_example server and provide values back to it. The SharedMemoryDummy
9# maps the register map on a shared memory segment, making it possible to access
10# the device from multiple applications simultaneously.
11#
12# Through special registers it also enables us to provide values for registers that
13# are declared read-only in the map file.
14
15# The script runs a simple heating simulation that generates the oven temperature from the
16# heating current and environment temperature.
17
18
19import deviceaccess as da
20import numpy as np
21import random
22import time
23
24da.setDMapFilePath('demo_example.dmap')
25
26dev = da.Device('device')
27dev.open()
28
29#cooling rate c
30c=0.001 #deg /(deg*s)
31
32#heating rate h
33h=0.0003 #deg/(A*s)
34
35ovenTemp = 25.
36environment = 25.
37
38# Our current setpoint
39currentSetpoint = dev.getScalarRegisterAccessor(np.double, "HEATER.CURRENT_SET")
40
41# The readback value of the actual current.
42currentReadback = dev.getScalarRegisterAccessor(np.double, "HEATER.CURRENT_READBACK.DUMMY_WRITEABLE")
43
44# The readback of various temperatures
45tempratureReadback = dev.getScalarRegisterAccessor(np.double, "SENSORS.TEMPERATURE1.DUMMY_WRITEABLE")
46temperatureTop = dev.getScalarRegisterAccessor(np.double, "SENSORS.TEMPERATURE2.DUMMY_WRITEABLE")
47temperatureBottom = dev.getScalarRegisterAccessor(np.double, "SENSORS.TEMPERATURE3.DUMMY_WRITEABLE")
48temperatureOutside = dev.getScalarRegisterAccessor(np.double, "SENSORS.TEMPERATURE4.DUMMY_WRITEABLE")
49
50
51while True:
52 currentSetpoint.read()
53 I = currentSetpoint[0];
54 tempChange = 1 * (I*h + (environment-ovenTemp)*c)
55 # 1s current*heating rate deltaT * cooling rate
56
57 ovenTemp = ovenTemp + tempChange
58 tempratureReadback.setAndWrite(ovenTemp)
59
60 # Just add some random jitter on the other read-out sensors
61 currentReadback.setAndWrite(I + random.gauss(0.0, 0.2))
62 temperatureTop.setAndWrite(ovenTemp + random.gauss(0.0, 0.2))
63 temperatureBottom.setAndWrite(ovenTemp + random.gauss(0.0, 0.2))
64 temperatureOutside.setAndWrite(environment + random.gauss(0.0, 0.2))
65 print('change ' + str(tempChange) +', new temp ' +str(ovenTemp))
66
67 time.sleep(1)