forked from lspestrip/striptease
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram_reference_test4.py
More file actions
executable file
·239 lines (209 loc) · 7.83 KB
/
program_reference_test4.py
File metadata and controls
executable file
·239 lines (209 loc) · 7.83 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
# Procedura 4: seguito di Procedura 2
import logging as log
from calibration import CalibrationTables
from reference_test import (
proc_1,
)
from striptease import (
STRIP_BOARD_NAMES,
PhswPinMode,
polarimeter_iterator,
StripTag,
StripProcedure,
wait_with_tag,
)
from turnon import TurnOnOffProcedure
DEFAULT_WAIT_TIME_S = 120.0
DEFAULT_LONG_WAIT_TIME_S = 7200.0
class ReferenceTestProcedure(StripProcedure):
def __init__(self, turn_on_polarimeters, wait_time_s, long_wait_time_s):
super().__init__()
self.calib = CalibrationTables()
self.turn_on_polarimeters = turn_on_polarimeters
self.wait_time_s = wait_time_s
self.long_wait_time_s = long_wait_time_s
def run(self):
if self.turn_on_polarimeters:
# turn on polarimeter
turnon_proc = TurnOnOffProcedure(waittime_s=1.0, turnon=True)
for cur_board, pol_idx, polname in polarimeter_iterator(args.board):
with StripTag(
conn=self.command_emitter, name=f"ref4_turnon_pol_{polname}"
):
turnon_proc.set_board_horn_polarimeter(
new_board=cur_board,
new_horn=polname,
new_pol=None,
)
turnon_proc.run()
self.command_emitter.command_list += turnon_proc.get_command_list()
turnon_proc.clear_command_list()
proc_1(self, polname, cur_board, 4)
self.conn.log(message="ref4_set phsw state to default bias")
# set phsw modulation to default bias
for h in range(4):
with StripTag(
conn=self.command_emitter,
name=f"ref4_set_pol{polname}_phsw_default_end",
):
self.conn.set_phsw_status(
polarimeter=polname,
phsw_index=h,
status=PhswPinMode.DEFAULT_STATE,
)
self.conn.set_hk_scan(boards=cur_board, allboards=False, time_ms=500)
wait_with_tag(
conn=self.conn,
seconds=self.wait_time_s,
name=f"ref4_acquisition_pol{polname}_phsw_default_end",
)
####################################################################################################################
# -------------------------------------------------------------------------------------------------------------------
# Procedura 4
# -------------------------------------------------------------------------------------------------------------------
# STATE 1
for cur_board, pol_idx, polname in polarimeter_iterator(args.board):
with StripTag(
conn=self.command_emitter,
name=f"ref4_set_pol{polname}_phsw_unsw0101",
):
for h, s in enumerate(
[
PhswPinMode.STILL_SIGNAL,
PhswPinMode.STILL_NO_SIGNAL,
PhswPinMode.STILL_SIGNAL,
PhswPinMode.STILL_NO_SIGNAL,
]
):
self.conn.set_phsw_status(
polarimeter=polname, phsw_index=h, status=s
)
wait_with_tag(
conn=self.conn,
seconds=self.long_wait_time_s,
name="ref4_acquisition_phsw_unsw0101",
)
# STATE 2
for cur_board, pol_idx, polname in polarimeter_iterator(args.board):
with StripTag(
conn=self.command_emitter,
name=f"ref4_set_pol{polname}_phsw_unsw1010",
):
for h, s in enumerate(
[
PhswPinMode.STILL_NO_SIGNAL,
PhswPinMode.STILL_SIGNAL,
PhswPinMode.STILL_NO_SIGNAL,
PhswPinMode.STILL_SIGNAL,
]
):
self.conn.set_phsw_status(
polarimeter=polname, phsw_index=h, status=s
)
wait_with_tag(
conn=self.conn,
seconds=self.long_wait_time_s,
name="ref4_acquisition_phsw_unsw1010",
)
# STATE 3
for cur_board, pol_idx, polname in polarimeter_iterator(args.board):
with StripTag(
conn=self.command_emitter,
name=f"ref4_set_pol{polname}_phsw_unsw1001",
):
for h, s in enumerate(
[
PhswPinMode.STILL_NO_SIGNAL,
PhswPinMode.STILL_SIGNAL,
PhswPinMode.STILL_SIGNAL,
PhswPinMode.STILL_NO_SIGNAL,
]
):
self.conn.set_phsw_status(
polarimeter=polname, phsw_index=h, status=s
)
wait_with_tag(
conn=self.conn,
seconds=self.long_wait_time_s,
name="ref4_acquisition_phsw_unsw1001",
)
# STATE 4
for cur_board, pol_idx, polname in polarimeter_iterator(args.board):
with StripTag(
conn=self.command_emitter,
name=f"ref4_set_pol_{polname}_phsw_unsw0110",
):
for h, s in enumerate(
[
PhswPinMode.STILL_SIGNAL,
PhswPinMode.STILL_NO_SIGNAL,
PhswPinMode.STILL_NO_SIGNAL,
PhswPinMode.STILL_SIGNAL,
]
):
self.conn.set_phsw_status(
polarimeter=polname, phsw_index=h, status=s
)
wait_with_tag(
conn=self.conn,
seconds=self.long_wait_time_s,
name="ref4_acquisition_phsw_unsw0110",
)
if __name__ == "__main__":
from argparse import ArgumentParser
parser = ArgumentParser(
description="Procedure a command sequence to turn on the boards",
)
parser.add_argument(
"--output",
"-o",
metavar="FILENAME",
type=str,
dest="output_filename",
default="",
help="Name of the file where to write the output (in JSON format)."
"If not provided, the output will be sent to stdout",
)
parser.add_argument(
"--turn-on",
action="store_true",
default=False,
help="Include the commands necessary to turn on the polarimeters",
)
parser.add_argument(
"--wait-time-s",
"-w",
metavar="SECONDS",
type=float,
dest="wait_time_s",
default=DEFAULT_WAIT_TIME_S,
help=f"""Short time to spend in each stable configuration
(default: {DEFAULT_WAIT_TIME_S})""",
)
parser.add_argument(
"--long-wait-time-s",
metavar="SECONDS",
type=float,
dest="long_wait_time_s",
default=DEFAULT_LONG_WAIT_TIME_S,
help=f"""Long time to spend in each stable configuration
(default: {DEFAULT_LONG_WAIT_TIME_S})""",
)
parser.add_argument(
"board",
type=str,
nargs="?",
default=STRIP_BOARD_NAMES,
help="ref_turn on one or more boards",
)
args = parser.parse_args()
log.basicConfig(level=log.INFO, format="[%(asctime)s %(levelname)s]%(message)s")
proc = ReferenceTestProcedure(
turn_on_polarimeters=args.turn_on,
wait_time_s=args.wait_time_s,
long_wait_time_s=args.long_wait_time_s,
)
proc.run()
proc.output_json(args.output_filename)