6b3fa0e0a23e0712396e495a61f431c33d011ff2
[pyafm.git] / pyafm / config.py
1 # Copyright (C) 2011-2012 W. Trevor King <wking@tremily.us>
2 #
3 # This file is part of pyafm.
4 #
5 # pyafm is free software: you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation, either version 3 of the License, or (at your option) any later
8 # version.
9 #
10 # pyafm is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # pyafm.  If not, see <http://www.gnu.org/licenses/>.
16
17 "AFM configuration"
18
19 import h5config.config as _config
20 import h5config.tools as _h5config_tools
21 import pycomedi.constant as _constant
22 import pypiezo.config as _pypiezo_config
23
24
25 class PackageConfig (_h5config_tools.PackageConfig):
26     "Configure `pyafm` module operation"
27     pass
28
29
30 class _TemperatureUnit (object):
31     pass
32
33
34 class Celsius (_TemperatureUnit):
35     pass
36
37
38 class Kelvin (_TemperatureUnit):
39     pass
40
41
42 class TemperatureConfig (_config.Config):
43     "Configure a temperature monitor"
44     settings = [
45         _config.Setting(
46             name='name',
47             help='Monitor name (so the user will know what is measured).',
48             default=None),
49         _config.ChoiceSetting(
50             name='units',
51             help='Units of raw temperature measurements.',
52             default=Celsius,
53             choices=[
54                 ('Celsius', Celsius),
55                 ('Kelvin', Kelvin),
56                 ]),
57         _config.IntegerSetting(
58             name='controller',
59             help='MTCA controller ID.',
60             default=1),
61         _config.Setting(
62             name='device',
63             help="Serial port you're using to connect to the controller.",
64             default='/dev/ttyS0'),
65         _config.IntegerSetting(
66             name='baudrate',
67             help="Baud rate for which you've configured your controller.",
68             default=9600),
69         _config.IntegerSetting(
70             name='max-current',
71             help="Maxium current (in amps) output by the controller.",
72             default=0),
73         ]
74
75
76 class DigitalPortConfig (_config.Config):
77     "Configure a digital input/output port."
78     settings = [
79         _config.Setting(
80             name='name',
81             help="Port name (so the user will know what it's used for).",
82             default=None),
83         _config.Setting(
84             name='device',
85             help='Comedi device.',
86             default='/dev/comedi0'),
87         _config.IntegerSetting(
88             name='subdevice',
89             help='Comedi subdevice index.  -1 for automatic detection.',
90             default=-1),
91         _config.ChoiceSetting(
92             name='subdevice-type',
93             help='Comedi subdevice type for autodetection.',
94             choices=[(x.name, x) for x in _constant.SUBDEVICE_TYPE],
95             default=_constant.SUBDEVICE_TYPE.dio),
96         _config.IntegerListSetting(
97             name='channels',
98             help='Subdevice channels to control by index.',
99             default=[0]),
100         _config.ChoiceSetting(
101             name='direction',
102             help='Port direction.',
103             choices=[(x.name, x) for x in _constant.IO_DIRECTION]),
104         ]
105
106
107 class StepperConfig (_config.Config):
108     "Configure a stepper motor."
109     settings = [
110         _config.Setting(
111             name='name',
112             help="Motor name (so the user will know what it's used for).",
113             default=None),
114         _config.BooleanSetting(
115             name='full-step',
116             help='Place the stepper in full-step mode (vs. half-step)',
117             default=True),
118         _config.BooleanSetting(
119             name='logic',
120             help='Place the stepper in active-high mode (vs. active-low)',
121             default=True),
122         _config.FloatSetting(
123             name='delay',
124             help=('Time delay between steps in seconds, in case the motor '
125                   'response is slower that the digital output driver.'),
126             default=1e-2),
127         _config.FloatSetting(
128             name='step-size',
129             help= 'Approximate step size in meters.' ,
130             default=170e-9),
131         _config.IntegerSetting(
132             name='backlash',
133             help= 'Generous estimate of the backlash length in half-steps.',
134             default=100),
135         _config.ConfigSetting(
136             name='port',
137             help=('Configure the digital port used to communicate with the '
138                   'stepper.'),
139             config_class=DigitalPortConfig,
140             default=None),
141         ]
142
143
144 class AFMConfig (_config.Config):
145     "Configure an Atomic Force Microscope (AFM)."
146     settings = [
147         _config.Setting(
148             name='name',
149             help="AFM name (so the user will know what it's used for).",
150             default=None),
151         _config.Setting(
152             name='main-axis',
153             help=("Name of the piezo axis controlling distance from the "
154                   "surface."),
155             default=None),
156         _config.ConfigSetting(
157             name='piezo',
158             help='Configure the underlying piezo (fine adjustment).',
159             config_class=_pypiezo_config.PiezoConfig,
160             default=None),
161         _config.ConfigSetting(
162             name='stepper',
163             help='Configure the underlying stepper motor (coarse adjustment).',
164             config_class=StepperConfig,
165             default=None),
166         _config.ConfigSetting(
167             name='temperature',
168             help='Configure the underlying temperature sensor.',
169             config_class=TemperatureConfig,
170             default=None),
171         _config.FloatSetting(
172             name='fallback-temperature',
173             help=('Temperature in Kelvin to use if no temperature sensor is '
174                   'configured.'),
175             default=295.15),
176         _config.FloatSetting(
177             name='far',
178             help=('Approximate distance in meters to move away to get "far" '
179                   'from the surface.  For possible stepper adjustments while '
180                   'initially locating the surface.'),
181             default=3e-5),
182         ]