| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | |
|---|
| 3 | """ Panohead remote control. |
|---|
| 4 | |
|---|
| 5 | License |
|---|
| 6 | ======= |
|---|
| 7 | |
|---|
| 8 | - B{Papywizard} (U{http://www.papywizard.org}) is Copyright: |
|---|
| 9 | - (C) 2007-2011 Frédéric Mantegazza |
|---|
| 10 | |
|---|
| 11 | This software is governed by the B{CeCILL} license under French law and |
|---|
| 12 | abiding by the rules of distribution of free software. You can use, |
|---|
| 13 | modify and/or redistribute the software under the terms of the CeCILL |
|---|
| 14 | license as circulated by CEA, CNRS and INRIA at the following URL |
|---|
| 15 | U{http://www.cecill.info}. |
|---|
| 16 | |
|---|
| 17 | As a counterpart to the access to the source code and rights to copy, |
|---|
| 18 | modify and redistribute granted by the license, users are provided only |
|---|
| 19 | with a limited warranty and the software's author, the holder of the |
|---|
| 20 | economic rights, and the successive licensors have only limited |
|---|
| 21 | liability. |
|---|
| 22 | |
|---|
| 23 | In this respect, the user's attention is drawn to the risks associated |
|---|
| 24 | with loading, using, modifying and/or developing or reproducing the |
|---|
| 25 | software by the user in light of its specific status of free software, |
|---|
| 26 | that may mean that it is complicated to manipulate, and that also |
|---|
| 27 | therefore means that it is reserved for developers and experienced |
|---|
| 28 | professionals having in-depth computer knowledge. Users are therefore |
|---|
| 29 | encouraged to load and test the software's suitability as regards their |
|---|
| 30 | requirements in conditions enabling the security of their systems and/or |
|---|
| 31 | data to be ensured and, more generally, to use and operate it in the |
|---|
| 32 | same conditions as regards security. |
|---|
| 33 | |
|---|
| 34 | The fact that you are presently reading this means that you have had |
|---|
| 35 | knowledge of the CeCILL license and that you accept its terms. |
|---|
| 36 | |
|---|
| 37 | Module purpose |
|---|
| 38 | ============== |
|---|
| 39 | |
|---|
| 40 | Hardware |
|---|
| 41 | |
|---|
| 42 | Implements |
|---|
| 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 | |
|---|
| 57 | import time |
|---|
| 58 | |
|---|
| 59 | from papywizard.common import config |
|---|
| 60 | from papywizard.common.configManager import ConfigManager |
|---|
| 61 | from papywizard.common.loggingServices import Logger |
|---|
| 62 | from papywizard.hardware.gigaPanBotHardware import GigaPanBotHardware |
|---|
| 63 | from papywizard.plugins.pluginsManager import PluginsManager |
|---|
| 64 | from papywizard.plugins.abstractAxisPlugin import AbstractAxisPlugin |
|---|
| 65 | from papywizard.plugins.shutterPlugin import ShutterPlugin |
|---|
| 66 | from papywizard.plugins.abstractHardwarePlugin import AbstractHardwarePlugin |
|---|
| 67 | from papywizard.plugins.axisPluginController import AxisPluginController |
|---|
| 68 | from papywizard.plugins.hardwarePluginController import HardwarePluginController |
|---|
| 69 | from papywizard.plugins.shutterPluginController import ShutterPluginController |
|---|
| 70 | |
|---|
| 71 | NAME = "GigaPanBot" |
|---|
| 72 | |
|---|
| 73 | AXIS_ACCURACY = 0.1 # ° |
|---|
| 74 | AXIS_TABLE = {'yawAxis': 1, |
|---|
| 75 | 'pitchAxis': 2, |
|---|
| 76 | 'shutter': 1 |
|---|
| 77 | } |
|---|
| 78 | MANUAL_SPEED_TABLE = {'slow': 4, |
|---|
| 79 | 'normal': 2, |
|---|
| 80 | 'fast': 0 |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | class 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 | |
|---|
| 151 | class GigaPanBotAxisController(AxisPluginController, HardwarePluginController): |
|---|
| 152 | def _defineGui(self): |
|---|
| 153 | AxisPluginController._defineGui(self) |
|---|
| 154 | HardwarePluginController._defineGui(self) |
|---|
| 155 | |
|---|
| 156 | |
|---|
| 157 | class 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 | |
|---|
| 190 | class GigaPanBotShutterController(ShutterPluginController, HardwarePluginController): |
|---|
| 191 | def _defineGui(self): |
|---|
| 192 | ShutterPluginController._defineGui(self) |
|---|
| 193 | HardwarePluginController._defineGui(self) |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | def 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) |
|---|