forked from Ulm-IQO/qudi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmagnet_dummy.py
607 lines (492 loc) · 24.9 KB
/
magnet_dummy.py
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
# -*- coding: utf-8 -*-
"""
This file contains the dummy for a magnet interface.
Qudi is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Qudi is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Qudi. If not, see <http://www.gnu.org/licenses/>.
Copyright (c) the Qudi Developers. See the COPYRIGHT.txt file at the
top-level directory of this distribution and at <https://github.com/Ulm-IQO/qudi/>
"""
from collections import OrderedDict
from core.module import Base
from interface.magnet_interface import MagnetInterface
class MagnetAxisDummy:
""" Generic dummy magnet representing one axis. """
def __init__(self, label):
self.label = label
self.pos = 0.0
self.status = 0, {0: 'MagnetDummy Idle'}
class MagnetDummy(Base, MagnetInterface):
""" This is the Interface class to define the controls for the simple
magnet hardware.
Example config for copy-paste:
magnet_dummy:
module.Class: 'magnet.magnet_dummy.MagnetDummy'
"""
def __init__(self, config, **kwargs):
super().__init__(config=config, **kwargs)
#these label should be actually set by the config.
self._x_axis = MagnetAxisDummy('x')
self._y_axis = MagnetAxisDummy('y')
self._z_axis = MagnetAxisDummy('z')
self._phi_axis = MagnetAxisDummy('phi')
#TODO: Checks if configuration is set and is reasonable
def on_activate(self):
""" Definition and initialisation of the GUI.
"""
pass
def on_deactivate(self):
""" Deactivate the module properly.
"""
pass
def get_constraints(self):
""" Retrieve the hardware constrains from the motor device.
@return dict: dict with constraints for the magnet hardware. These
constraints will be passed via the logic to the GUI so
that proper display elements with boundary conditions
could be made.
Provides all the constraints for each axis of a motorized stage
(like total travel distance, velocity, ...)
Each axis has its own dictionary, where the label is used as the
identifier throughout the whole module. The dictionaries for each axis
are again grouped together in a constraints dictionary in the form
{'<label_axis0>': axis0 }
where axis0 is again a dict with the possible values defined below. The
possible keys in the constraint are defined here in the interface file.
If the hardware does not support the values for the constraints, then
insert just None. If you are not sure about the meaning, look in other
hardware files to get an impression.
"""
constraints = OrderedDict()
axis0 = {'label': self._x_axis.label,
'unit': 'm',
'ramp': ['Sinus', 'Linear'],
'pos_min': 0,
'pos_max': 100e-3,
'pos_step': 0.001e-3,
'vel_min': 0,
'vel_max': 100e-3,
'vel_step': 0.01e-3,
'acc_min': 0.1e-3,
'acc_max': 0.0,
'acc_step': 0.0}
axis1 = {'label': self._y_axis.label,
'unit': 'm',
'ramp': ['Sinus', 'Linear'],
'pos_min': 0,
'pos_max': 100e-3,
'pos_step': 0.001e-3,
'vel_min': 0,
'vel_max': 100e-3,
'vel_step': 0.01e-3,
'acc_min': 0.1e-3,
'acc_max': 0.0,
'acc_step': 0.0}
axis2 = {'label': self._z_axis.label,
'unit': 'm',
'ramp': ['Sinus', 'Linear'],
'pos_min': 0,
'pos_max': 100e-3,
'pos_step': 0.001e-3,
'vel_min': 0,
'vel_max': 100e-3,
'vel_step': 0.01e-3,
'acc_min': 0.1e-3,
'acc_max': 0.0,
'acc_step': 0.0}
axis3 = {'label': self._phi_axis.label,
'unit': '°',
'ramp': ['Sinus', 'Trapez'],
'pos_min': 0,
'pos_max': 360,
'pos_step': 0.1,
'vel_min': 1,
'vel_max': 20,
'vel_step': 0.1,
'acc_min': None,
'acc_max': None,
'acc_step': None}
# assign the parameter container for x to a name which will identify it
constraints[axis0['label']] = axis0
constraints[axis1['label']] = axis1
constraints[axis2['label']] = axis2
constraints[axis3['label']] = axis3
return constraints
def move_rel(self, param_dict):
""" Moves magnet in given direction (relative movement)
@param dict param_dict: dictionary, which passes all the relevant
parameters, which should be changed.
With get_constraints() you can obtain all
possible parameters of that stage. According to
this parameter set you have to pass a dictionary
with keys that are called like the parameters
from get_constraints() and assign a SI value to
that. For a movement in x the dict should e.g.
have the form:
dict = { 'x' : 23 }
where the label 'x' corresponds to the chosen
axis label.
A smart idea would be to ask the position after the movement.
"""
curr_pos_dict = self.get_pos()
constraints = self.get_constraints()
if param_dict.get(self._x_axis.label) is not None:
move_x = param_dict[self._x_axis.label]
curr_pos_x = curr_pos_dict[self._x_axis.label]
if (curr_pos_x + move_x > constraints[self._x_axis.label]['pos_max'] ) or\
(curr_pos_x + move_x < constraints[self._x_axis.label]['pos_min']):
self.log.warning('Cannot make further movement of the axis '
'"{0}" with the step {1}, since the border [{2},{3}] '
' of the magnet was reached! Ignore '
'command!'.format(
self._x_axis.label,
move_x,
constraints[self._x_axis.label]['pos_min'],
constraints[self._x_axis.label]['pos_max']))
else:
self._x_axis.pos = self._x_axis.pos + move_x
if param_dict.get(self._y_axis.label) is not None:
move_y = param_dict[self._y_axis.label]
curr_pos_y = curr_pos_dict[self._y_axis.label]
if (curr_pos_y + move_y > constraints[self._y_axis.label]['pos_max'] ) or\
(curr_pos_y + move_y < constraints[self._y_axis.label]['pos_min']):
self.log.warning('Cannot make further movement of the axis '
'"{0}" with the step {1}, since the border [{2},{3}] '
' of the magnet was reached! Ignore '
'command!'.format(
self._y_axis.label,
move_y,
constraints[self._y_axis.label]['pos_min'],
constraints[self._y_axis.label]['pos_max']))
else:
self._y_axis.pos = self._y_axis.pos + move_y
if param_dict.get(self._z_axis.label) is not None:
move_z = param_dict[self._z_axis.label]
curr_pos_z = curr_pos_dict[self._z_axis.label]
if (curr_pos_z + move_z > constraints[self._z_axis.label]['pos_max'] ) or\
(curr_pos_z + move_z < constraints[self._z_axis.label]['pos_min']):
self.log.warning('Cannot make further movement of the axis '
'"{0}" with the step {1}, since the border [{2},{3}] '
' of the magnet was reached! Ignore '
'command!'.format(
self._z_axis.label,
move_z,
constraints[self._z_axis.label]['pos_min'],
constraints[self._z_axis.label]['pos_max']))
else:
self._z_axis.pos = self._z_axis.pos + move_z
if param_dict.get(self._phi_axis.label) is not None:
move_phi = param_dict[self._phi_axis.label]
curr_pos_phi = curr_pos_dict[self._phi_axis.label]
if (curr_pos_phi + move_phi > constraints[self._phi_axis.label]['pos_max'] ) or\
(curr_pos_phi + move_phi < constraints[self._phi_axis.label]['pos_min']):
self.log.warning('Cannot make further movement of the axis '
'"{0}" with the step {1}, since the border [{2},{3}] '
' of the magnet was reached! Ignore '
'command!'.format(
self._phi_axis.label,
move_phi,
constraints[self._phi_axis.label]['pos_min'],
constraints[self._phi_axis.label]['pos_max']))
else:
self._phi_axis.pos = self._phi_axis.pos + move_phi
def move_abs(self, param_dict):
""" Moves magnet to absolute position (absolute movement)
@param dict param_dict: dictionary, which passes all the relevant
parameters, which should be changed. Usage:
{'axis_label': <a-value>}.
'axis_label' must correspond to a label given
to one of the axis.
A smart idea would be to ask the position after the movement.
"""
constraints = self.get_constraints()
if param_dict.get(self._x_axis.label) is not None:
desired_pos = param_dict[self._x_axis.label]
constr = constraints[self._x_axis.label]
if not(constr['pos_min'] <= desired_pos <= constr['pos_max']):
self.log.warning('Cannot make absolute movement of the axis '
'"{0}" to possition {1}, since it exceeds the limits '
'[{2},{3}] of the magnet! Command is '
'ignored!'.format(
self._x_axis.label,
desired_pos,
constr['pos_min'],
constr['pos_max']))
else:
self._x_axis.pos = desired_pos
if param_dict.get(self._y_axis.label) is not None:
desired_pos = param_dict[self._y_axis.label]
constr = constraints[self._y_axis.label]
if not(constr['pos_min'] <= desired_pos <= constr['pos_max']):
self.log.warning('Cannot make absolute movement of the axis '
'"{0}" to possition {1}, since it exceeds the limits '
'[{2},{3}] of the magnet! Command is '
'ignored!'.format(
self._y_axis.label,
desired_pos,
constr['pos_min'],
constr['pos_max']))
else:
self._y_axis.pos = desired_pos
if param_dict.get(self._z_axis.label) is not None:
desired_pos = param_dict[self._z_axis.label]
constr = constraints[self._z_axis.label]
if not(constr['pos_min'] <= desired_pos <= constr['pos_max']):
self.log.warning('Cannot make absolute movement of the axis '
'"{0}" to possition {1}, since it exceeds the limits '
'[{2},{3}] of the magnet! Command is '
'ignored!'.format(
self._z_axis.label,
desired_pos,
constr['pos_min'],
constr['pos_max']))
else:
self._z_axis.pos = desired_pos
if param_dict.get(self._phi_axis.label) is not None:
desired_pos = param_dict[self._phi_axis.label]
constr = constraints[self._phi_axis.label]
if not(constr['pos_min'] <= desired_pos <= constr['pos_max']):
self.log.warning('Cannot make absolute movement of the axis '
'"{0}" to possition {1}, since it exceeds the limits '
'[{2},{3}] of the magnet! Command is ignored!'.format(
self._phi_axis.label,
desired_pos,
constr['pos_min'],
constr['pos_max']))
else:
self._phi_axis.pos = desired_pos
def abort(self):
""" Stops movement of the stage
@return int: error code (0:OK, -1:error)
"""
self.log.info('MagnetDummy: Movement stopped!')
return 0
def get_pos(self, param_list=None):
""" Gets current position of the magnet stage arms
@param list param_list: optional, if a specific position of an axis
is desired, then the labels of the needed
axis should be passed as the param_list.
If nothing is passed, then from each axis the
position is asked.
@return dict: with keys being the axis labels and item the current
position.
"""
pos = {}
if param_list is not None:
if self._x_axis.label in param_list:
pos[self._x_axis.label] = self._x_axis.pos
if self._y_axis.label in param_list:
pos[self._y_axis.label] = self._y_axis.pos
if self._z_axis.label in param_list:
pos[self._z_axis.label] = self._z_axis.pos
if self._phi_axis.label in param_list:
pos[self._phi_axis.label] = self._phi_axis.pos
else:
pos[self._x_axis.label] = self._x_axis.pos
pos[self._y_axis.label] = self._y_axis.pos
pos[self._z_axis.label] = self._z_axis.pos
pos[self._phi_axis.label] = self._phi_axis.pos
return pos
def get_status(self, param_list=None):
""" Get the status of the position
@param list param_list: optional, if a specific status of an axis
is desired, then the labels of the needed
axis should be passed in the param_list.
If nothing is passed, then from each axis the
status is asked.
@return dict: with the axis label as key and the status number as item.
"""
status = {}
if param_list is not None:
if self._x_axis.label in param_list:
status[self._x_axis.label] = self._x_axis.status
if self._y_axis.label in param_list:
status[self._y_axis.label] = self._y_axis.status
if self._z_axis.label in param_list:
status[self._z_axis.label] = self._z_axis.status
if self._phi_axis.label in param_list:
status[self._phi_axis.label] = self._phi_axis.status
else:
status[self._x_axis.label] = self._x_axis.status
status[self._y_axis.label] = self._y_axis.status
status[self._z_axis.label] = self._z_axis.status
status[self._phi_axis.label] = self._phi_axis.status
return status
def calibrate(self, param_list=None):
""" Calibrates the magnet stage.
@param dict param_list: param_list: optional, if a specific calibration
of an axis is desired, then the labels of the
needed axis should be passed in the param_list.
If nothing is passed, then all connected axis
will be calibrated.
@return int: error code (0:OK, -1:error)
After calibration the stage moves to home position which will be the
zero point for the passed axis. The calibration procedure will be
different for each stage.
"""
if param_list is not None:
if self._x_axis.label in param_list:
self._x_axis.pos = 0.0
if self._y_axis.label in param_list:
self._y_axis.pos = 0.0
if self._z_axis.label in param_list:
self._z_axis.pos = 0.0
if self._phi_axis.label in param_list:
self._phi_axis.pos = 0.0
else:
self._x_axis.pos = 0.0
self._y_axis.pos = 0.0
self._z_axis.pos = 0.0
self._phi_axis.pos = 0.0
return 0
def get_velocity(self, param_list=None):
""" Gets the current velocity for all connected axes.
@param dict param_list: optional, if a specific velocity of an axis
is desired, then the labels of the needed
axis should be passed as the param_list.
If nothing is passed, then from each axis the
velocity is asked.
@return dict : with the axis label as key and the velocity as item.
"""
vel = {}
if param_list is not None:
if self._x_axis.label in param_list:
vel[self._x_axis.label] = self._x_axis.vel
if self._y_axis.label in param_list:
vel[self._x_axis.label] = self._y_axis.vel
if self._z_axis.label in param_list:
vel[self._x_axis.label] = self._z_axis.vel
if self._phi_axis.label in param_list:
vel[self._phi_axis.label] = self._phi_axis.vel
else:
vel[self._x_axis.label] = self._x_axis.get_vel
vel[self._y_axis.label] = self._y_axis.get_vel
vel[self._z_axis.label] = self._z_axis.get_vel
vel[self._phi_axis.label] = self._phi_axis.vel
return vel
def set_velocity(self, param_dict=None):
""" Write new value for velocity.
@param dict param_dict: dictionary, which passes all the relevant
parameters, which should be changed. Usage:
{'axis_label': <the-velocity-value>}.
'axis_label' must correspond to a label given
to one of the axis.
"""
constraints = self.get_constraints()
if param_dict.get(self._x_axis.label) is not None:
desired_vel = param_dict[self._x_axis.label]
constr = constraints[self._x_axis.label]
if not(constr['vel_min'] <= desired_vel <= constr['vel_max']):
self.log.warning('Cannot make absolute movement of the axis '
'"{0}" to possition {1}, since it exceeds the limits '
'[{2},{3}] ! Command is ignored!'.format(
self._x_axis.label,
desired_vel,
constr['vel_min'],
constr['vel_max']))
else:
self._x_axis.vel = desired_vel
if param_dict.get(self._y_axis.label) is not None:
desired_vel = param_dict[self._y_axis.label]
constr = constraints[self._y_axis.label]
if not(constr['vel_min'] <= desired_vel <= constr['vel_max']):
self.log.warning('Cannot make absolute movement of the axis '
'"{0}" to possition {1}, since it exceeds the limits '
'[{2},{3}] ! Command is ignored!'.format(
self._y_axis.label,
desired_vel,
constr['vel_min'],
constr['vel_max']))
else:
self._y_axis.vel = desired_vel
if param_dict.get(self._z_axis.label) is not None:
desired_vel = param_dict[self._z_axis.label]
constr = constraints[self._z_axis.label]
if not(constr['vel_min'] <= desired_vel <= constr['vel_max']):
self.log.warning('Cannot make absolute movement of the axis '
'"{0}" to possition {1}, since it exceeds the limits '
'[{2},{3}] ! Command is ignored!'.format(
self._z_axis.label,
desired_vel,
constr['vel_min'],
constr['vel_max']))
else:
self._z_axis.vel = desired_vel
if param_dict.get(self._phi_axis.label) is not None:
desired_vel = param_dict[self._phi_axis.label]
constr = constraints[self._phi_axis.label]
if not(constr['vel_min'] <= desired_vel <= constr['vel_max']):
self.log.warning('Cannot make absolute movement of the axis '
'"{0}" to possition {1}, since it exceeds the limits '
'[{2},{3}] ! Command is ignored!'.format(
self._phi_axis.label,
desired_vel,
constr['vel_min'],
constr['vel_max']))
else:
self._phi_axis.vel = desired_vel
def tell(self, param_dict=None):
""" Send a command to the magnet.
@param dict param_dict: dictionary, which passes all the relevant
parameters, which should be changed. Usage:
{'axis_label': <the command string>}.
'axis_label' must correspond to a label given
to one of the axis.
@return int: error code (0:OK, -1:error)
"""
self.log.info('You can tell the magnet dummy as much as you want, it '
'has always an open ear for you. But do not expect an '
'answer, it is very shy!')
return 0
def ask(self, param_dict=None):
""" Ask the magnet a question.
@param dict param_dict: dictionary, which passes all the relevant
parameters, which should be changed. Usage:
{'axis_label': <the question string>}.
'axis_label' must correspond to a label given
to one of the axis.
@return string: contains the answer coming from the magnet
"""
self.log.info('Dude, I am a dummy! Your question(s) "{0}" to the '
'axis "{1}" is/are way to complicated for me :D ! If you '
'want to talk to someone, ask Siri, maybe she will listen to '
'you and answer your questions :P.'.format(
list(param_dict.values()), list(param_dict)))
return_val = {}
for entry in param_dict:
return_val[entry] = 'Nothing to say, Motor is quite.'
return return_val
def set_magnet_idle_state(self, magnet_idle=True):
""" Set the magnet to couple/decouple to/from the control.
@param bool magnet_idle: if True then magnet will be set to idle and
each movement command will be ignored from the
hardware file. If False the magnet will react
on movement changes of any kind.
@return bool: the actual state which was set in the magnet hardware.
True = idle, decoupled from control
False = Not Idle, coupled to control
"""
self._idle_state = magnet_idle
return self._idle_state
def get_magnet_idle_state(self):
""" Retrieve the current state of the magnet, whether it is idle or not.
@return bool: the actual state which was set in the magnet hardware.
True = idle, decoupled from control
False = Not Idle, coupled to control
"""
return self._idle_state
def initialize(self):
"""
Acts as a switch. When all coils of the superconducting magnet are
heated it cools them, else the coils get heated.
@return int: (0: Ok, -1:error)
"""
raise InterfaceImplementationError('magnet_interface>initialize')
return -1