root/trunk/papywizard/plugins/gigaPanBotPlugins.py

Revision 2498, 6.4 KB (checked in by fma, 13 months ago)

Updated copyright date

  • Property svn:keywords set to Id
Line 
1# -*- coding: utf-8 -*-
2
3""" Panohead remote control.
4
5License
6=======
7
8 - B{Papywizard} (U{http://www.papywizard.org}) is Copyright:
9  - (C) 2007-2011 Frédéric Mantegazza
10
11This software is governed by the B{CeCILL} license under French law and
12abiding by the rules of distribution of free software.  You can  use,
13modify and/or redistribute the software under the terms of the CeCILL
14license as circulated by CEA, CNRS and INRIA at the following URL
15U{http://www.cecill.info}.
16
17As a counterpart to the access to the source code and  rights to copy,
18modify and redistribute granted by the license, users are provided only
19with a limited warranty  and the software's author,  the holder of the
20economic rights,  and the successive licensors  have only  limited
21liability.
22
23In this respect, the user's attention is drawn to the risks associated
24with loading,  using,  modifying and/or developing or reproducing the
25software by the user in light of its specific status of free software,
26that may mean  that it is complicated to manipulate,  and  that  also
27therefore means  that it is reserved for developers  and  experienced
28professionals having in-depth computer knowledge. Users are therefore
29encouraged to load and test the software's suitability as regards their
30requirements in conditions enabling the security of their systems and/or
31data to be ensured and,  more generally, to use and operate it in the
32same conditions as regards security.
33
34The fact that you are presently reading this means that you have had
35knowledge of the CeCILL license and that you accept its terms.
36
37Module purpose
38==============
39
40Hardware
41
42Implements
43==========
44
45 - GigaPanBotAxis
46 - GigaPanBotAxisController
47 - GigaPanBotShutter
48 - GigaPanBotShutterController
49
50@author: Frédéric Mantegazza
51@copyright: (C) 2007-2011 Frédéric Mantegazza
52@license: CeCILL
53"""
54
55__revision__ = "$Id$"
56
57import time
58
59from papywizard.common import config
60from papywizard.common.configManager import ConfigManager
61from papywizard.common.loggingServices import Logger
62from papywizard.hardware.gigaPanBotHardware import GigaPanBotHardware
63from papywizard.plugins.pluginsManager  import PluginsManager
64from papywizard.plugins.abstractAxisPlugin import AbstractAxisPlugin
65from papywizard.plugins.shutterPlugin import ShutterPlugin
66from papywizard.plugins.abstractHardwarePlugin import AbstractHardwarePlugin
67from papywizard.plugins.axisPluginController import AxisPluginController
68from papywizard.plugins.hardwarePluginController import HardwarePluginController
69from papywizard.plugins.shutterPluginController import ShutterPluginController
70
71NAME = "GigaPanBot"
72
73AXIS_ACCURACY = 0.1 # °
74AXIS_TABLE = {'yawAxis': 1,
75              'pitchAxis': 2,
76              'shutter': 1
77              }
78MANUAL_SPEED_TABLE = {'slow': 4,
79                      'normal': 2,
80                      'fast': 0
81                      }
82
83
84class GigaPanBotAxis(AbstractHardwarePlugin, AbstractAxisPlugin):
85    def _init(self):
86        Logger().trace("GigaPanBotAxis._init()")
87        AbstractHardwarePlugin._init(self)
88        AbstractAxisPlugin._init(self)
89        self._hardware = GigaPanBotHardware()
90
91    def _defineConfig(self):
92        AbstractAxisPlugin._defineConfig(self)
93        AbstractHardwarePlugin._defineConfig(self)
94
95    def init(self):
96        Logger().trace("GigaPanBotAxis.init()")
97        self._hardware.setAxis(AXIS_TABLE[self.capacity]),
98        AbstractHardwarePlugin.init(self)
99
100    def shutdown(self):
101        Logger().trace("GigaPanBotAxis.shutdown()")
102        self.stop()
103        AbstractHardwarePlugin.shutdown(self)
104        AbstractAxisPlugin.shutdown(self)
105
106    def read(self):
107        pos = self._hardware.read() - self._offset
108        return pos
109
110    def drive(self, pos, useOffset=True, wait=True):
111        Logger().debug("GigaPanBotAxis.drive(): '%s' drive to %.1f" % (self.capacity, pos))
112        currentPos = self.read()
113
114        self._checkLimits(pos)
115
116        if useOffset:
117            pos += self._offset
118
119        # Only move if needed
120        if abs(pos - currentPos) > AXIS_ACCURACY or not useOffset:
121            self._hardware.drive(pos)
122
123            # Wait end of movement
124            if wait:
125                self.waitEndOfDrive()
126
127    def waitEndOfDrive(self):
128        while self.isMoving():
129            time.sleep(config.SPY_REFRESH_DELAY / 1000.)
130        self.waitStop()
131
132    def startJog(self, dir_):
133        self._hardware.startJog(dir_, MANUAL_SPEED_TABLE[self._manualSpeed])
134
135    def stop(self):
136        self.__driveFlag = False
137        self._hardware.stop()
138        self.waitStop()
139
140    def waitStop(self):
141        pass
142
143    def isMoving(self):
144        status = self._hardware.getStatus()
145        if status != '0':
146            return True
147        else:
148            return False
149
150
151class GigaPanBotAxisController(AxisPluginController, HardwarePluginController):
152    def _defineGui(self):
153        AxisPluginController._defineGui(self)
154        HardwarePluginController._defineGui(self)
155
156
157class GigaPanBotShutter(AbstractHardwarePlugin, ShutterPlugin):
158    def _init(self):
159        Logger().trace("GigaPanBotShutter._init()")
160        AbstractHardwarePlugin._init(self)
161        ShutterPlugin._init(self)
162        self._hardware = GigaPanBotHardware()
163
164    def _defineConfig(self):
165        AbstractHardwarePlugin._defineConfig(self)
166        ShutterPlugin._defineConfig(self)
167
168    def _triggerOnShutter(self):
169        """ Set the shutter on.
170        """
171        self._hardware.setOutput(True)
172
173    def _triggerOffShutter(self):
174        """ Set the shutter off.
175        """
176        self._hardware.setOutput(False)
177
178    def init(self):
179        Logger().trace("GigaPanBotShutter.init()")
180        self._hardware.setAxis(AXIS_TABLE[self.capacity]),
181        AbstractHardwarePlugin.init(self)
182
183    def shutdown(self):
184        Logger().trace("GigaPanBotShutter.shutdown()")
185        self._triggerOffShutter()
186        AbstractHardwarePlugin.shutdown(self)
187        ShutterPlugin.shutdown(self)
188
189
190class GigaPanBotShutterController(ShutterPluginController, HardwarePluginController):
191    def _defineGui(self):
192        ShutterPluginController._defineGui(self)
193        HardwarePluginController._defineGui(self)
194
195
196def register():
197    """ Register plugins.
198    """
199    PluginsManager().register(GigaPanBotAxis, GigaPanBotAxisController, capacity='yawAxis', name=NAME)
200    PluginsManager().register(GigaPanBotAxis, GigaPanBotAxisController, capacity='pitchAxis', name=NAME)
201    PluginsManager().register(GigaPanBotShutter, GigaPanBotShutterController, capacity='shutter', name=NAME)
Note: See TracBrowser for help on using the browser.