-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdummy_softioc.py
More file actions
57 lines (50 loc) · 2.38 KB
/
Copy pathdummy_softioc.py
File metadata and controls
57 lines (50 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import time
import threading
import numpy as np
from caproto.server import pvproperty, PVGroup, ioc_arg_parser, run
class MyIOC(PVGroup):
# Define detector PVs, only one
gaussian_noise = pvproperty(value=0.0, read_only=True)
# Define motor PVs, VAL and RBV
counting_index = pvproperty(value=0, dtype=int, name="time.VAL")
current_time = pvproperty(value="Initializing...", dtype=str, read_only=True, max_length=30, name="time.RBV")
# Define theta.VAL and theta.RBV
theta_VAL = pvproperty(value=0.0, dtype=float, name="theta.VAL")
theta_RBV = pvproperty(value=0.0, dtype=float, read_only=True, name="theta.RBV")
# Define z.VAL and z.RBV
z_VAL = pvproperty(value=0.0, dtype=float, name="z.VAL")
z_RBV = pvproperty(value=0.0, dtype=float, read_only=True, name="z.RBV")
@current_time.scan(period=1.0) # Update every second
async def current_time(self, instance, async_lib):
"""Update the current time PV."""
current_time = time.strftime("%Y-%m-%d %H:%M:%S")
await instance.write(current_time)
@gaussian_noise.scan(period=1.0) # Update every second
async def gaussian_noise(self, instance, async_lib):
"""Update the noise PV."""
noise_value = np.random.normal(0, 1) # Mean=0, Std=1
await instance.write(noise_value)
@theta_VAL.putter
async def theta_VAL(self, instance, value):
"""When sim:theta.VAL is updated, update sim:theta.RBV with noise."""
# Add noise to the VAL value to simulate RBV (simulated readback value)
noise = np.random.normal(0, 0.01) # Mean=0, Std=0.01 for small noise
rbv_value = value + noise
# Update the RBV PV
await self.theta_RBV.write(rbv_value)
@z_VAL.putter
async def z_VAL(self, instance, value):
"""When sim:z.VAL is updated, update sim:z.RBV with noise."""
# Add noise to the VAL value to simulate RBV (simulated readback value)
noise = np.random.normal(0, 0.01) # Mean=0, Std=0.01 for small noise
rbv_value = value + noise
# Update the RBV PV
await self.z_RBV.write(rbv_value)
if __name__ == "__main__":
# Parse arguments for running the IOC
ioc_options, run_options = ioc_arg_parser(
default_prefix="sim:",
desc="Dummy IOC with current time, Gaussian noise and theta."
)
ioc = MyIOC(**ioc_options)
run(ioc.pvdb, **run_options)