Skip to content

Commit 3e554ca

Browse files
committed
adding photdiode
1 parent 25cba9a commit 3e554ca

2 files changed

Lines changed: 152 additions & 48 deletions

File tree

src/pymodaq_plugins_teaching/daq_move_plugins/daq_move_Monochromator.py

Lines changed: 16 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,7 @@
66
from pymodaq_utils.utils import ThreadCommand # object used to send info back to the main thread
77
from pymodaq_gui.parameter import Parameter
88

9-
# TODO:
10-
# Replace the following fake import with the import of the real Python wrapper of your instrument. Here we suppose that
11-
# the wrapper is in the hardware directory, but it could come from an external librairy like pylablib or pymeasure.
12-
from pymodaq_plugins_template.hardware.python_wrapper_file_of_your_instrument import PythonWrapperObjectOfYourInstrument
13-
14-
# TODO:
15-
# (1) change the name of the following class to DAQ_Move_TheNameOfYourChoice
16-
# (2) change the name of this file to daq_move_TheNameOfYourChoice ("TheNameOfYourChoice" should be the SAME
17-
# for the class name and the file name.)
18-
# (3) this file should then be put into the right folder, namely IN THE FOLDER OF THE PLUGIN YOU ARE DEVELOPING:
19-
# pymodaq_plugins_my_plugin/daq_move_plugins
9+
from pymodaq_plugins_teaching.hardware.spectrometer import Spectrometer
2010

2111

2212
class DAQ_Move_Monochromator(DAQ_Move_base):
@@ -41,12 +31,10 @@ class DAQ_Move_Monochromator(DAQ_Move_base):
4131
# TODO add your particular attributes here if any
4232
4333
"""
44-
is_multiaxes = False # TODO for your plugin set to True if this plugin is controlled for a multiaxis controller
45-
_axis_names: Union[List[str], Dict[str, int]] = ['Axis1', 'Axis2'] # TODO for your plugin: complete the list
46-
_controller_units: Union[str, List[str]] = 'mm' # TODO for your plugin: put the correct unit here, it could be
47-
# TODO a single str (the same one is applied to all axes) or a list of str (as much as the number of axes)
48-
_epsilon: Union[float, List[float]] = 0.1 # TODO replace this by a value that is correct depending on your controller
49-
# TODO it could be a single float of a list of float (as much as the number of axes)
34+
is_multiaxes = False
35+
_axis_names: Union[List[str], Dict[str, int]] = ['']
36+
_controller_units: Union[str, List[str]] = 'nm'
37+
_epsilon: Union[float, List[float]] = 0.1
5038
data_actuator_type = DataActuatorType.DataActuator # wether you use the new data style for actuator otherwise set this
5139
# as DataActuatorType.float (or entirely remove the line)
5240

@@ -58,21 +46,19 @@ class DAQ_Move_Monochromator(DAQ_Move_base):
5846
def ini_attributes(self):
5947
# TODO declare the type of the wrapper (and assign it to self.controller) you're going to use for easy
6048
# autocompletion
61-
self.controller: PythonWrapperObjectOfYourInstrument = None
49+
self.controller: Spectrometer = None
6250

6351
#TODO declare here attributes you want/need to init with a default value
6452
pass
6553

66-
def get_actuator_value(self):
54+
def get_actuator_value(self) -> DataActuator:
6755
"""Get the current value from the hardware with scaling conversion.
6856
6957
Returns
7058
-------
71-
float: The position obtained after scaling conversion.
59+
DataActuator: The position as a DataActuator object obtained after scaling conversion.
7260
"""
73-
## TODO for your custom plugin
74-
raise NotImplementedError # when writing your own plugin remove this line
75-
pos = DataActuator(data=self.controller.your_method_to_get_the_actuator_value(), # when writing your own plugin replace this line
61+
pos = DataActuator(data=self.controller.get_wavelength(), # when writing your own plugin replace this line
7662
units=self.axis_unit)
7763
pos = self.get_position_with_scaling(pos)
7864
return pos
@@ -93,11 +79,8 @@ def user_condition_to_reach_target(self) -> bool:
9379

9480
def close(self):
9581
"""Terminate the communication protocol"""
96-
## TODO for your custom plugin
97-
raise NotImplementedError # when writing your own plugin remove this line
9882
if self.is_master:
99-
# self.controller.your_method_to_terminate_the_communication() # when writing your own plugin replace this line
100-
...
83+
self.controller.close_communication()
10184

10285
def commit_settings(self, param: Parameter):
10386
"""Apply the consequences of a change of value in the detector settings
@@ -133,10 +116,9 @@ def ini_stage(self, controller=None):
133116
initialized: bool
134117
False if initialization failed otherwise True
135118
"""
136-
raise NotImplementedError # TODO when writing your own plugin remove this line and modify the ones below
137119
if self.is_master: # is needed when controller is master
138-
self.controller = PythonWrapperObjectOfYourInstrument(arg1, arg2, ...) # arguments for instantiation!)
139-
initialized = self.controller.a_method_or_atttribute_to_check_if_init() # todo
120+
self.controller = Spectrometer()
121+
initialized = self.controller.open_communication() # todo
140122
# todo: enter here whatever is needed for your controller initialization and eventual
141123
# opening of the communication channel
142124
else:
@@ -153,13 +135,10 @@ def move_abs(self, value: DataActuator):
153135
----------
154136
value: (float) value of the absolute target positioning
155137
"""
156-
157138
value = self.check_bound(value) #if user checked bounds, the defined bounds are applied here
158139
self.target_value = value
159140
value = self.set_position_with_scaling(value) # apply scaling if the user specified one
160-
## TODO for your custom plugin
161-
raise NotImplementedError # when writing your own plugin remove this line
162-
self.controller.your_method_to_set_an_absolute_value(value.value(self.axis_unit)) # when writing your own plugin replace this line
141+
self.controller.set_wavelength(value.value(self.axis_unit)) # when writing your own plugin replace this line
163142
self.emit_status(ThreadCommand('Update_Status', ['Some info you want to log']))
164143

165144
def move_rel(self, value: DataActuator):
@@ -173,27 +152,16 @@ def move_rel(self, value: DataActuator):
173152
self.target_value = value + self.current_position
174153
value = self.set_position_relative_with_scaling(value)
175154

176-
## TODO for your custom plugin
177-
raise NotImplementedError # when writing your own plugin remove this line
178-
self.controller.your_method_to_set_a_relative_value(value.value(self.axis_unit)) # when writing your own plugin replace this line
155+
self.move_abs(self.target_value)# when writing your own plugin replace this line
179156
self.emit_status(ThreadCommand('Update_Status', ['Some info you want to log']))
180157

181158
def move_home(self):
182159
"""Call the reference method of the controller"""
183-
184-
## TODO for your custom plugin
185-
raise NotImplementedError # when writing your own plugin remove this line
186-
self.controller.your_method_to_get_to_a_known_reference() # when writing your own plugin replace this line
187-
self.emit_status(ThreadCommand('Update_Status', ['Some info you want to log']))
160+
self.controller.find_reference()
188161

189162
def stop_motion(self):
190163
"""Stop the actuator and emits move_done signal"""
191-
192-
## TODO for your custom plugin
193-
raise NotImplementedError # when writing your own plugin remove this line
194-
self.controller.your_method_to_stop_positioning() # when writing your own plugin replace this line
195-
self.emit_status(ThreadCommand('Update_Status', ['Some info you want to log']))
196-
164+
self.controller.stop()
197165

198166
if __name__ == '__main__':
199167
main(__file__)
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
import numpy as np
2+
from llvmlite.binding import initialize
3+
4+
from pymodaq_utils.utils import ThreadCommand
5+
from pymodaq_data.data import DataToExport
6+
from pymodaq_gui.parameter import Parameter
7+
8+
from pymodaq.control_modules.viewer_utility_classes import DAQ_Viewer_base, comon_parameters, main
9+
from pymodaq.utils.data import DataFromPlugins
10+
11+
from pymodaq_plugins_teaching.hardware.spectrometer import Spectrometer
12+
13+
14+
class DAQ_0DViewer_Photodiode(DAQ_Viewer_base):
15+
""" Instrument plugin class for a OD viewer.
16+
17+
This object inherits all functionalities to communicate with PyMoDAQ’s DAQ_Viewer module through inheritance via
18+
DAQ_Viewer_base. It makes a bridge between the DAQ_Viewer module and the Python wrapper of a particular instrument.
19+
20+
TODO Complete the docstring of your plugin with:
21+
* The set of instruments that should be compatible with this instrument plugin.
22+
* With which instrument it has actually been tested.
23+
* The version of PyMoDAQ during the test.
24+
* The version of the operating system.
25+
* Installation instructions: what manufacturer’s drivers should be installed to make it run?
26+
27+
Attributes:
28+
-----------
29+
controller: object
30+
The particular object that allow the communication with the hardware, in general a python wrapper around the
31+
hardware library.
32+
33+
# TODO add your particular attributes here if any
34+
35+
"""
36+
params = comon_parameters+[
37+
## TODO for your custom plugin: elements to be added here as dicts in order to control your custom stage
38+
]
39+
40+
def ini_attributes(self):
41+
# TODO declare the type of the wrapper (and assign it to self.controller) you're going to use for easy
42+
# autocompletion
43+
self.controller: Spectrometer = None
44+
45+
#TODO declare here attributes you want/need to init with a default value
46+
pass
47+
48+
def commit_settings(self, param: Parameter):
49+
"""Apply the consequences of a change of value in the detector settings
50+
51+
Parameters
52+
----------
53+
param: Parameter
54+
A given parameter (within detector_settings) whose value has been changed by the user
55+
"""
56+
## TODO for your custom plugin
57+
if param.name() == "a_parameter_you've_added_in_self.params":
58+
self.controller.your_method_to_apply_this_param_change() # when writing your own plugin replace this line
59+
# elif ...
60+
##
61+
62+
def ini_detector(self, controller=None):
63+
"""Detector communication initialization
64+
65+
Parameters
66+
----------
67+
controller: (object)
68+
custom object of a PyMoDAQ plugin (Slave case). None if only one actuator/detector by controller
69+
(Master case)
70+
71+
Returns
72+
-------
73+
info: str
74+
initialized: bool
75+
False if initialization failed otherwise True
76+
"""
77+
78+
if self.is_master:
79+
self.controller = Spectrometer() #instantiate you driver with whatever arguments are needed
80+
initialized = self.controller.open_communication() # call eventual methods
81+
else:
82+
self.controller = controller
83+
initialized = True
84+
85+
info = "Whatever info you want to log"
86+
return info, initialized
87+
88+
def close(self):
89+
"""Terminate the communication protocol"""
90+
## TODO for your custom plugin
91+
raise NotImplementedError # when writing your own plugin remove this line
92+
if self.is_master:
93+
# self.controller.your_method_to_terminate_the_communication() # when writing your own plugin replace this line
94+
...
95+
96+
def grab_data(self, Naverage=1, **kwargs):
97+
"""Start a grab from the detector
98+
99+
Parameters
100+
----------
101+
Naverage: int
102+
Number of hardware averaging (if hardware averaging is possible, self.hardware_averaging should be set to
103+
True in class preamble and you should code this implementation)
104+
kwargs: dict
105+
others optionals arguments
106+
"""
107+
## TODO for your custom plugin: you should choose EITHER the synchrone or the asynchrone version following
108+
109+
data_tot = self.controller.grab_monochromator()
110+
self.dte_signal.emit(
111+
DataToExport(name='Photodiode',
112+
data=[
113+
DataFromPlugins(name='Photodiode', data=[data_tot],
114+
labels=['Intensity'],
115+
units='V')]))
116+
117+
118+
def callback(self):
119+
"""optional asynchrone method called when the detector has finished its acquisition of data"""
120+
data_tot = self.controller.your_method_to_get_data_from_buffer()
121+
self.dte_signal.emit(DataToExport(name='myplugin',
122+
data=[DataFromPlugins(name='Mock1', data=data_tot,
123+
dim='Data0D', labels=['dat0', 'data1'])]))
124+
125+
def stop(self):
126+
"""Stop the current grab hardware wise if necessary"""
127+
## TODO for your custom plugin
128+
raise NotImplementedError # when writing your own plugin remove this line
129+
self.controller.your_method_to_stop_acquisition() # when writing your own plugin replace this line
130+
self.emit_status(ThreadCommand('Update_Status', ['Some info you want to log']))
131+
##############################
132+
return ''
133+
134+
135+
if __name__ == '__main__':
136+
main(__file__)

0 commit comments

Comments
 (0)