source: moxy/trunk/src/moxy/model/set.py @ 835

Last change on this file since 835 was 835, checked in by jemian, 11 years ago

refactoring

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Rev Url
File size: 3.1 KB
Line 
1#!/usr/bin/env python
2
3########### SVN repository information ###################
4# $Date: 2012-04-26 15:54:14 +0000 (Thu, 26 Apr 2012) $
5# $Author: jemian $
6# $Revision: 835 $
7# $URL$
8# $Id: set.py 835 2012-04-26 15:54:14Z jemian $
9########### SVN repository information ###################
10
11'''
12details about a model set of coordinated axes
13
14Copyright (c) 2009 - 2011, UChicago Argonne, LLC.
15See LICENSE file for details.
16'''
17
18
19# - - - - - - - - - - - - - - - - - - Imports
20
21
22from m_axis import SingleAxis
23
24
25# - - - - - - - - - - - - - - - - - - Global
26
27
28__svnid__ = "$Id: set.py 835 2012-04-26 15:54:14Z jemian $"
29
30
31# - - - - - - - - - - - - - - - - - - class
32
33
34class AxesSet:
35    '''
36    A set of axes that describe an instrument setting.
37   
38    :param str name: short name for this set of axes
39    :param [SingleAxis] axes: list of SingleAxis objects to be coordinated
40    :param [obj] user_positions: list of positions for this set of axes
41    '''
42   
43    def __init__(self, name = '', axes = [], user_positions = []):
44        self.name = name
45        self.axes = axes
46        self.user_positions = user_positions
47   
48    def stopMotion(self):
49        '''tell EPICS to stop moving these axes'''
50        for axis in self.axes:
51            axis.stopMotion()
52   
53    def move(self, values):
54        '''
55        send all axes to positions in values list
56       
57        :param [number] values: list with new positions for each axis
58        '''
59        if len(values) != len(self.axes):
60            raise RuntimeError, "number of positions must equal number of axes"
61        for axis, value in zip(self.axes, values):
62            axis.move(value)
63   
64    def connect(self, handler = None):
65        '''connect all axes with EPICS PVs'''
66        for axis in self.axes:
67            axis.connect(handler or self.callback)
68   
69    def disconnect(self):
70        '''disconnect all axes from EPICS PVs'''
71        for axis in self.axes:
72            axis.disconnect()
73           
74    def report(self):
75        print self.name
76        for axis in self.axes:
77            print "<%s> <%s> <%s> = %g" % (
78                axis.name, 
79                axis.axis.DESC, 
80                axis.axis.get_pv('RBV').pvname, 
81                axis.axis.RBV
82            )
83
84    def callback(self, *args, **kw):
85        '''trivial handling of PyEpics callback'''
86        if 'pvname' in kw:
87            #print "PyEpics callback handler:", kw['pvname'], kw['value']
88            pass
89
90
91# - - - - - - - - - - - - - - - - - - methods
92
93def _demo_():
94    '''demonstrate use of this module'''
95    aset = AxesSet( 
96        name = 'test motion axes set', 
97        axes = [
98            SingleAxis( "*X*", "prj:m1", isMotorRecord = True, ),
99            SingleAxis( "*Y*", "prj:m2", isMotorRecord = True, ),
100            SingleAxis( "*Z*", "prj:m3", isMotorRecord = True, ),
101            SingleAxis( "*U*", "prj:m4", isMotorRecord = True, ),
102            SingleAxis( "*V*", "prj:m5", isMotorRecord = True, ),
103            SingleAxis( "*W*", "prj:m6", isMotorRecord = True, ),
104            SingleAxis( "*S*", "prj:m7", isMotorRecord = True, ),
105            SingleAxis( "*T*", "prj:m8", isMotorRecord = True, ),
106        ] 
107    )
108    aset.connect()
109    aset.report()
110
111# - - - - - - - - - - - - - - - - - - main
112
113
114if __name__ == '__main__':
115    _demo_()
Note: See TracBrowser for help on using the repository browser.