| 1 |
# |
| 2 |
# This file is part of the PyMeasure package. |
| 3 |
# |
| 4 |
# Copyright (c) 2013-2024 PyMeasure Developers |
| 5 |
# |
| 6 |
# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 |
# of this software and associated documentation files (the "Software"), to deal |
| 8 |
# in the Software without restriction, including without limitation the rights |
| 9 |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 |
# copies of the Software, and to permit persons to whom the Software is |
| 11 |
# furnished to do so, subject to the following conditions: |
| 12 |
# |
| 13 |
# The above copyright notice and this permission notice shall be included in |
| 14 |
# all copies or substantial portions of the Software. |
| 15 |
# |
| 16 |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 |
# THE SOFTWARE. |
| 23 |
# |
| 24 |
|
| 25 |
from pymeasure.instruments import Instrument, SCPIUnknownMixin |
| 26 |
from time import sleep |
| 27 |
import re |
| 28 |
|
| 29 |
|
| 30 |
class ParkerGV6(SCPIUnknownMixin, Instrument): |
| 31 |
""" Represents the Parker Gemini GV6 Servo Motor Controller |
| 32 |
and provides a high-level interface for interacting with |
| 33 |
the instrument |
| 34 |
""" |
| 35 |
|
| 36 |
degrees_per_count = 0.00045 # 90 deg per 200,000 count |
| 37 |
|
| 38 |
def __init__(self, adapter, name="Parker GV6 Motor Controller", **kwargs): |
| 39 |
super().__init__( |
| 40 |
adapter, |
| 41 |
name, |
| 42 |
asrl={'baud_rate': 9600, |
| 43 |
'timeout': 500, |
| 44 |
}, |
| 45 |
write_termination="\r", |
| 46 |
**kwargs |
| 47 |
) |
| 48 |
self.set_defaults() |
| 49 |
|
| 50 |
def read(self): |
| 51 |
""" Overwrites the Instrument.read command to provide the correct |
| 52 |
functionality |
| 53 |
""" |
| 54 |
# TODO seems to be broken as it does not make sense see issue #623 |
| 55 |
return re.sub(r'\r\n\n(>|\?)? ', '', "\n".join(self.readlines())) |
| 56 |
|
| 57 |
def set_defaults(self): |
| 58 |
""" Sets up the default values for the motor, which |
| 59 |
is run upon construction |
| 60 |
""" |
| 61 |
self.echo = False |
| 62 |
self.set_hardware_limits(False, False) |
| 63 |
self.use_absolute_position() |
| 64 |
self.average_acceleration = 1 |
| 65 |
self.acceleration = 1 |
| 66 |
self.velocity = 3 |
| 67 |
|
| 68 |
def reset(self): |
| 69 |
""" Resets the motor controller while blocking and |
| 70 |
(CAUTION) resets the absolute position value of the motor |
| 71 |
""" |
| 72 |
self.write("RESET") |
| 73 |
sleep(5) |
| 74 |
self.setDefault() |
| 75 |
self.enable() |
| 76 |
|
| 77 |
def enable(self): |
| 78 |
""" Enables the motor to move """ |
| 79 |
self.write("DRIVE1") |
| 80 |
|
| 81 |
def disable(self): |
| 82 |
""" Disables the motor from moving """ |
| 83 |
self.write("DRIVE0") |
| 84 |
|
| 85 |
@property |
| 86 |
def status(self): |
| 87 |
""" Returns a list of the motor status in readable format """ |
| 88 |
return self.ask("TASF").split("\r\n\n") |
| 89 |
|
| 90 |
def is_moving(self): |
| 91 |
""" Returns True if the motor is currently moving """ |
| 92 |
return self.position is None |
| 93 |
|
| 94 |
@property |
| 95 |
def angle(self): |
| 96 |
""" Returns the angle in degrees based on the position |
| 97 |
and whether relative or absolute positioning is enabled, |
| 98 |
returning None on error |
| 99 |
""" |
| 100 |
position = self.position |
| 101 |
if position is not None: |
| 102 |
return position * self.degrees_per_count |
| 103 |
else: |
| 104 |
return None |
| 105 |
|
| 106 |
@angle.setter |
| 107 |
def angle(self, angle): |
| 108 |
""" Gives the motor a setpoint in degrees based on an |
| 109 |
angle from a relative or absolution position |
| 110 |
""" |
| 111 |
self.position = int(angle * self.degrees_per_count**-1) |
| 112 |
|
| 113 |
@property |
| 114 |
def angle_error(self): |
| 115 |
""" Returns the angle error in degrees based on the |
| 116 |
position error, or returns None on error |
| 117 |
""" |
| 118 |
position_error = self.position_error |
| 119 |
if position_error is not None: |
| 120 |
return position_error * self.degrees_per_count |
| 121 |
else: |
| 122 |
return None |
| 123 |
|
| 124 |
@property |
| 125 |
def position(self): |
| 126 |
""" Returns an integer number of counts that correspond to |
| 127 |
the angular position where 1 revolution equals 4000 counts |
| 128 |
""" |
| 129 |
match = re.search(r'(?<=TPE)-?\d+', self.ask("TPE")) |
| 130 |
if match is None: |
| 131 |
return None |
| 132 |
else: |
| 133 |
return int(match.group(0)) |
| 134 |
|
| 135 |
@position.setter |
| 136 |
def position(self, counts): # in counts: 4000 count = 1 rev |
| 137 |
""" Gives the motor a setpoint in counts where 4000 counts |
| 138 |
equals 1 revolution |
| 139 |
""" |
| 140 |
self.write("D" + str(int(counts))) |
| 141 |
|
| 142 |
@property |
| 143 |
def position_error(self): |
| 144 |
""" Returns the error in the number of counts that corresponds |
| 145 |
to the error in the angular position where 1 revolution equals |
| 146 |
4000 counts |
| 147 |
""" |
| 148 |
match = re.search(r'(?<=TPER)-?\d+', self.ask("TPER")) |
| 149 |
if match is None: |
| 150 |
return None |
| 151 |
else: |
| 152 |
return int(match.group(0)) |
| 153 |
|
| 154 |
def move(self): |
| 155 |
""" Initiates the motor to move to the setpoint """ |
| 156 |
self.write("GO") |
| 157 |
|
| 158 |
def stop(self): |
| 159 |
""" Stops the motor during movement """ |
| 160 |
self.write("S") |
| 161 |
|
| 162 |
def kill(self): |
| 163 |
""" Stops the motor """ |
| 164 |
self.write("K") |
| 165 |
|
| 166 |
def use_absolute_position(self): |
| 167 |
""" Sets the motor to accept setpoints from an absolute |
| 168 |
zero position |
| 169 |
""" |
| 170 |
self.write("MA1") |
| 171 |
self.write("MC0") |
| 172 |
|
| 173 |
def use_relative_position(self): |
| 174 |
""" Sets the motor to accept setpoints that are relative |
| 175 |
to the last position |
| 176 |
""" |
| 177 |
self.write("MA0") |
| 178 |
self.write("MC0") |
| 179 |
|
| 180 |
def set_hardware_limits(self, positive=True, negative=True): |
| 181 |
""" Enables (True) or disables (False) the hardware |
| 182 |
limits for the motor |
| 183 |
""" |
| 184 |
if positive and negative: |
| 185 |
self.write("LH3") |
| 186 |
elif positive and not negative: |
| 187 |
self.write("LH2") |
| 188 |
elif not positive and negative: |
| 189 |
self.write("LH1") |
| 190 |
else: |
| 191 |
self.write("LH0") |
| 192 |
|
| 193 |
def set_software_limits(self, positive, negative): |
| 194 |
""" Sets the software limits for motion based on |
| 195 |
the count unit where 4000 counts is 1 revolution |
| 196 |
""" |
| 197 |
self.write("LSPOS%d" % int(positive)) |
| 198 |
self.write("LSNEG%d" % int(negative)) |
| 199 |
|
| 200 |
@property |
| 201 |
def echo(self): |
| 202 |
pass |
| 203 |
|
| 204 |
@echo.setter |
| 205 |
def echo(self, enable=False): |
| 206 |
""" Enables (True) or disables (False) the echoing |
| 207 |
of all commands that are sent to the instrument |
| 208 |
""" |
| 209 |
if enable: |
| 210 |
self.write("ECHO1") |
| 211 |
else: |
| 212 |
self.write("ECHO0") |
| 213 |
|
| 214 |
@property |
| 215 |
def acceleration(self): |
| 216 |
pass # TODO: Implement acceleration return value |
| 217 |
|
| 218 |
@acceleration.setter |
| 219 |
def acceleration(self, acceleration): |
| 220 |
""" Sets the acceleration setpoint in revolutions per second |
| 221 |
squared |
| 222 |
""" |
| 223 |
self.write("A" + str(float(acceleration))) |
| 224 |
|
| 225 |
@property |
| 226 |
def average_acceleration(self): |
| 227 |
pass # TODO: Implement average_acceleration return value |
| 228 |
|
| 229 |
@average_acceleration.setter |
| 230 |
def average_acceleration(self, acceleration): |
| 231 |
""" Sets the average acceleration setpoint in revolutions |
| 232 |
per second squared |
| 233 |
""" |
| 234 |
self.write("AA" + str(float(acceleration))) |
| 235 |
|
| 236 |
@property |
| 237 |
def velocity(self): |
| 238 |
pass # TODO: Implement velocity return value |
| 239 |
|
| 240 |
@velocity.setter |
| 241 |
def velocity(self, velocity): # in revs/s |
| 242 |
""" Sets the velocity setpoint in revolutions per second """ |
| 243 |
self.write("V" + str(float(velocity))) |