File: parkerGV6.py

package info (click to toggle)
python-pymeasure 0.14.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 8,788 kB
  • sloc: python: 47,201; makefile: 155
file content (243 lines) | stat: -rw-r--r-- 7,733 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#
# This file is part of the PyMeasure package.
#
# Copyright (c) 2013-2024 PyMeasure Developers
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#

from pymeasure.instruments import Instrument, SCPIUnknownMixin
from time import sleep
import re


class ParkerGV6(SCPIUnknownMixin, Instrument):
    """ Represents the Parker Gemini GV6 Servo Motor Controller
    and provides a high-level interface for interacting with
    the instrument
    """

    degrees_per_count = 0.00045  # 90 deg per 200,000 count

    def __init__(self, adapter, name="Parker GV6 Motor Controller", **kwargs):
        super().__init__(
            adapter,
            name,
            asrl={'baud_rate': 9600,
                  'timeout': 500,
                  },
            write_termination="\r",
            **kwargs
        )
        self.set_defaults()

    def read(self):
        """ Overwrites the Instrument.read command to provide the correct
        functionality
        """
        # TODO seems to be broken as it does not make sense see issue #623
        return re.sub(r'\r\n\n(>|\?)? ', '', "\n".join(self.readlines()))

    def set_defaults(self):
        """ Sets up the default values for the motor, which
        is run upon construction
        """
        self.echo = False
        self.set_hardware_limits(False, False)
        self.use_absolute_position()
        self.average_acceleration = 1
        self.acceleration = 1
        self.velocity = 3

    def reset(self):
        """ Resets the motor controller while blocking and
        (CAUTION) resets the absolute position value of the motor
        """
        self.write("RESET")
        sleep(5)
        self.setDefault()
        self.enable()

    def enable(self):
        """ Enables the motor to move """
        self.write("DRIVE1")

    def disable(self):
        """ Disables the motor from moving """
        self.write("DRIVE0")

    @property
    def status(self):
        """ Returns a list of the motor status in readable format """
        return self.ask("TASF").split("\r\n\n")

    def is_moving(self):
        """ Returns True if the motor is currently moving """
        return self.position is None

    @property
    def angle(self):
        """ Returns the angle in degrees based on the position
        and whether relative or absolute positioning is enabled,
        returning None on error
        """
        position = self.position
        if position is not None:
            return position * self.degrees_per_count
        else:
            return None

    @angle.setter
    def angle(self, angle):
        """ Gives the motor a setpoint in degrees based on an
        angle from a relative or absolution position
        """
        self.position = int(angle * self.degrees_per_count**-1)

    @property
    def angle_error(self):
        """ Returns the angle error in degrees based on the
        position error, or returns None on error
        """
        position_error = self.position_error
        if position_error is not None:
            return position_error * self.degrees_per_count
        else:
            return None

    @property
    def position(self):
        """ Returns an integer number of counts that correspond to
        the angular position where 1 revolution equals 4000 counts
        """
        match = re.search(r'(?<=TPE)-?\d+', self.ask("TPE"))
        if match is None:
            return None
        else:
            return int(match.group(0))

    @position.setter
    def position(self, counts):  # in counts: 4000 count = 1 rev
        """ Gives the motor a setpoint in counts where 4000 counts
        equals 1 revolution
        """
        self.write("D" + str(int(counts)))

    @property
    def position_error(self):
        """ Returns the error in the number of counts that corresponds
        to the error in the angular position where 1 revolution equals
        4000 counts
        """
        match = re.search(r'(?<=TPER)-?\d+', self.ask("TPER"))
        if match is None:
            return None
        else:
            return int(match.group(0))

    def move(self):
        """ Initiates the motor to move to the setpoint """
        self.write("GO")

    def stop(self):
        """ Stops the motor during movement """
        self.write("S")

    def kill(self):
        """ Stops the motor """
        self.write("K")

    def use_absolute_position(self):
        """ Sets the motor to accept setpoints from an absolute
        zero position
        """
        self.write("MA1")
        self.write("MC0")

    def use_relative_position(self):
        """ Sets the motor to accept setpoints that are relative
        to the last position
        """
        self.write("MA0")
        self.write("MC0")

    def set_hardware_limits(self, positive=True, negative=True):
        """ Enables (True) or disables (False) the hardware
        limits for the motor
        """
        if positive and negative:
            self.write("LH3")
        elif positive and not negative:
            self.write("LH2")
        elif not positive and negative:
            self.write("LH1")
        else:
            self.write("LH0")

    def set_software_limits(self, positive, negative):
        """ Sets the software limits for motion based on
        the count unit where 4000 counts is 1 revolution
        """
        self.write("LSPOS%d" % int(positive))
        self.write("LSNEG%d" % int(negative))

    @property
    def echo(self):
        pass

    @echo.setter
    def echo(self, enable=False):
        """ Enables (True) or disables (False) the echoing
        of all commands that are sent to the instrument
        """
        if enable:
            self.write("ECHO1")
        else:
            self.write("ECHO0")

    @property
    def acceleration(self):
        pass  # TODO: Implement acceleration return value

    @acceleration.setter
    def acceleration(self, acceleration):
        """ Sets the acceleration setpoint in revolutions per second
        squared
        """
        self.write("A" + str(float(acceleration)))

    @property
    def average_acceleration(self):
        pass  # TODO: Implement average_acceleration return value

    @average_acceleration.setter
    def average_acceleration(self, acceleration):
        """ Sets the average acceleration setpoint in revolutions
        per second squared
        """
        self.write("AA" + str(float(acceleration)))

    @property
    def velocity(self):
        pass  # TODO: Implement velocity return value

    @velocity.setter
    def velocity(self, velocity):  # in revs/s
        """ Sets the velocity setpoint in revolutions per second """
        self.write("V" + str(float(velocity)))