Add matplotlib config option and stepper_approach plot.
[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     settings = _h5config_tools.PackageConfig.settings + [
28         _config.BooleanSetting(
29             name='matplotlib',
30             help='Plot pyafm actions using `matplotlib`.',
31             default=False),
32         ]
33
34
35 class _TemperatureUnit (object):
36     pass
37
38
39 class Celsius (_TemperatureUnit):
40     pass
41
42
43 class Kelvin (_TemperatureUnit):
44     pass
45
46
47 class TemperatureConfig (_config.Config):
48     "Configure a temperature monitor"
49     settings = [
50         _config.Setting(
51             name='name',
52             help='Monitor name (so the user will know what is measured).',
53             default=None),
54         _config.ChoiceSetting(
55             name='units',
56             help='Units of raw temperature measurements.',
57             default=Celsius,
58             choices=[
59                 ('Celsius', Celsius),
60                 ('Kelvin', Kelvin),
61                 ]),
62         _config.IntegerSetting(
63             name='controller',
64             help='MTCA controller ID.',
65             default=1),
66         _config.Setting(
67             name='device',
68             help="Serial port you're using to connect to the controller.",
69             default='/dev/ttyS0'),
70         _config.IntegerSetting(
71             name='baudrate',
72             help="Baud rate for which you've configured your controller.",
73             default=9600),
74         _config.IntegerSetting(
75             name='max-current',
76             help="Maxium current (in amps) output by the controller.",
77             default=0),
78         ]
79
80
81 class DigitalPortConfig (_config.Config):
82     "Configure a digital input/output port."
83     settings = [
84         _config.Setting(
85             name='name',
86             help="Port name (so the user will know what it's used for).",
87             default=None),
88         _config.Setting(
89             name='device',
90             help='Comedi device.',
91             default='/dev/comedi0'),
92         _config.IntegerSetting(
93             name='subdevice',
94             help='Comedi subdevice index.  -1 for automatic detection.',
95             default=-1),
96         _config.ChoiceSetting(
97             name='subdevice-type',
98             help='Comedi subdevice type for autodetection.',
99             choices=[(x.name, x) for x in _constant.SUBDEVICE_TYPE],
100             default=_constant.SUBDEVICE_TYPE.dio),
101         _config.IntegerListSetting(
102             name='channels',
103             help='Subdevice channels to control by index.',
104             default=[0]),
105         _config.ChoiceSetting(
106             name='direction',
107             help='Port direction.',
108             choices=[(x.name, x) for x in _constant.IO_DIRECTION]),
109         ]
110
111
112 class StepperConfig (_config.Config):
113     "Configure a stepper motor."
114     settings = [
115         _config.Setting(
116             name='name',
117             help="Motor name (so the user will know what it's used for).",
118             default=None),
119         _config.BooleanSetting(
120             name='full-step',
121             help='Place the stepper in full-step mode (vs. half-step)',
122             default=True),
123         _config.BooleanSetting(
124             name='logic',
125             help='Place the stepper in active-high mode (vs. active-low)',
126             default=True),
127         _config.FloatSetting(
128             name='delay',
129             help=('Time delay between steps in seconds, in case the motor '
130                   'response is slower that the digital output driver.'),
131             default=1e-2),
132         _config.FloatSetting(
133             name='step-size',
134             help= 'Approximate step size in meters.' ,
135             default=170e-9),
136         _config.IntegerSetting(
137             name='backlash',
138             help= 'Generous estimate of the backlash length in half-steps.',
139             default=100),
140         _config.ConfigSetting(
141             name='port',
142             help=('Configure the digital port used to communicate with the '
143                   'stepper.'),
144             config_class=DigitalPortConfig,
145             default=None),
146         ]
147
148
149 class AFMConfig (_config.Config):
150     "Configure an Atomic Force Microscope (AFM)."
151     settings = [
152         _config.Setting(
153             name='name',
154             help="AFM name (so the user will know what it's used for).",
155             default=None),
156         _config.Setting(
157             name='main-axis',
158             help=("Name of the piezo axis controlling distance from the "
159                   "surface."),
160             default=None),
161         _config.ConfigSetting(
162             name='piezo',
163             help='Configure the underlying piezo (fine adjustment).',
164             config_class=_pypiezo_config.PiezoConfig,
165             default=None),
166         _config.ConfigSetting(
167             name='stepper',
168             help='Configure the underlying stepper motor (coarse adjustment).',
169             config_class=StepperConfig,
170             default=None),
171         _config.ConfigSetting(
172             name='temperature',
173             help='Configure the underlying temperature sensor.',
174             config_class=TemperatureConfig,
175             default=None),
176         _config.FloatSetting(
177             name='fallback-temperature',
178             help=('Temperature in Kelvin to use if no temperature sensor is '
179                   'configured.'),
180             default=295.15),
181         _config.FloatSetting(
182             name='far',
183             help=('Approximate distance in meters to move away to get "far" '
184                   'from the surface.  For possible stepper adjustments while '
185                   'initially locating the surface.'),
186             default=3e-5),
187         ]