From 66082cf65f7bd87143423d31cfabf4a3fe87561f Mon Sep 17 00:00:00 2001 From: Carson Bantz <143952958+Cbantz@users.noreply.github.com> Date: Tue, 15 Jul 2025 11:40:28 -0500 Subject: [PATCH 1/6] Add 'direction' property for move_indefinitely with a negative velocity. Negative velocities would throw a MAXIMUM VELOCITY EXCEEDED error, and move_indefinitely only sent the "MV" command. This meant there was no was to move_indefinitely in the 'negative' direction. Now, when setting velocity, a direction will be set as well, allowing for indefinite movement in either direction using the "MV+" or "MV-" commands. This is the only area that direction currently applies. --- src/instruments/newport/newportesp301.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/instruments/newport/newportesp301.py b/src/instruments/newport/newportesp301.py index 0aa05f5d..c10d5b3e 100644 --- a/src/instruments/newport/newportesp301.py +++ b/src/instruments/newport/newportesp301.py @@ -42,6 +42,7 @@ def __init__(self, filelike): self._command_list = [] self._bulk_query_resp = "" self.terminator = "\r" + class Axis: """ @@ -83,7 +84,7 @@ def __init__(self, controller, axis_id): self._controller = controller self._axis_id = axis_id + 1 - + self.direction = "+" self._units = self.units # CONTEXT MANAGERS ## @@ -139,6 +140,19 @@ def is_motion_done(self): """ return bool(int(self._newport_cmd("MD?", target=self.axis_id))) + @property + def direction(self): + """ + Either '+' or '-' depending on last velocity sign. + """ + return self.direction + + @direction.setter + def direction(self, sign): + if sign not in ('+', '-'): + raise ValueError("Direction bust be '+' or '-'") + self.direction = sign + @property def acceleration(self): """ @@ -252,6 +266,8 @@ def velocity(self): @velocity.setter def velocity(self, velocity): + self.direction = '+' if velocity > 0 else '-' + velocity = abs(velocity) velocity = float( assume_units(velocity, self._units / (u.s)) .to(self._units / u.s) @@ -872,7 +888,7 @@ def move_indefinitely(self): """ Move until told to stop """ - self._newport_cmd("MV", target=self.axis_id) + self._newport_cmd(f"MV{self.direction}", target=self.axis_id) def abort_motion(self): """ @@ -955,6 +971,7 @@ def setup_axis(self, **kwargs): * 'voltage' = motor voltage (V) * 'units' = set units (see NewportESP301.Units)(U) * 'encoder_resolution' = value of encoder step in terms of (U) + * 'direction' = sign of velocity ('+' or '-') * 'max_velocity' = maximum velocity (U/s) * 'max_base_velocity' = maximum working velocity (U/s) * 'homing_velocity' = homing speed (U/s) @@ -992,6 +1009,7 @@ def setup_axis(self, **kwargs): self.voltage = kwargs.get("voltage") self.units = int(kwargs.get("units")) self.encoder_resolution = kwargs.get("encoder_resolution") + self.direction = kwargs.get("direction") self.max_acceleration = kwargs.get("max_acceleration") self.max_velocity = kwargs.get("max_velocity") self.max_base_velocity = kwargs.get("max_base_velocity") @@ -1080,6 +1098,7 @@ def read_setup(self): config["full_step_resolution"] = self.full_step_resolution config["position_display_resolution"] = self.position_display_resolution config["current"] = self.current + config["direction"] = self.direction config["max_velocity"] = self.max_velocity config["encoder_resolution"] = self.encoder_resolution config["acceleration"] = self.acceleration From 65a3cce2bdd03ad3c5b3cb16830687f500d6d8dd Mon Sep 17 00:00:00 2001 From: Cbantz Date: Tue, 15 Jul 2025 12:03:00 -0500 Subject: [PATCH 2/6] Fixed Recursion Error Used _direction when changing and returning value to fix recursion error. --- src/instruments/newport/newportesp301.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/instruments/newport/newportesp301.py b/src/instruments/newport/newportesp301.py index c10d5b3e..26f443e2 100644 --- a/src/instruments/newport/newportesp301.py +++ b/src/instruments/newport/newportesp301.py @@ -84,7 +84,7 @@ def __init__(self, controller, axis_id): self._controller = controller self._axis_id = axis_id + 1 - self.direction = "+" + self._direction = "+" self._units = self.units # CONTEXT MANAGERS ## @@ -145,13 +145,13 @@ def direction(self): """ Either '+' or '-' depending on last velocity sign. """ - return self.direction + return self._direction @direction.setter def direction(self, sign): if sign not in ('+', '-'): raise ValueError("Direction bust be '+' or '-'") - self.direction = sign + self._direction = sign @property def acceleration(self): @@ -266,7 +266,7 @@ def velocity(self): @velocity.setter def velocity(self, velocity): - self.direction = '+' if velocity > 0 else '-' + self._direction = '+' if velocity > 0 else '-' velocity = abs(velocity) velocity = float( assume_units(velocity, self._units / (u.s)) @@ -888,7 +888,7 @@ def move_indefinitely(self): """ Move until told to stop """ - self._newport_cmd(f"MV{self.direction}", target=self.axis_id) + self._newport_cmd(f"MV{self._direction}", target=self.axis_id) def abort_motion(self): """ From 2340ba6f81b96edc76bd1f9299ba818903b2f7bb Mon Sep 17 00:00:00 2001 From: Cbantz Date: Tue, 15 Jul 2025 12:22:30 -0500 Subject: [PATCH 3/6] Changed Direction Solution Commented out previous 'direction' code and simply added an argument to "move_indefinitely()" to specify direction. This will allow velocity to be adjusted during a move without problems of changing the sign. --- src/instruments/newport/newportesp301.py | 39 ++++++++++++------------ 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/instruments/newport/newportesp301.py b/src/instruments/newport/newportesp301.py index 26f443e2..f77ecfb5 100644 --- a/src/instruments/newport/newportesp301.py +++ b/src/instruments/newport/newportesp301.py @@ -84,7 +84,7 @@ def __init__(self, controller, axis_id): self._controller = controller self._axis_id = axis_id + 1 - self._direction = "+" + #self._direction = "+" self._units = self.units # CONTEXT MANAGERS ## @@ -140,18 +140,18 @@ def is_motion_done(self): """ return bool(int(self._newport_cmd("MD?", target=self.axis_id))) - @property - def direction(self): - """ - Either '+' or '-' depending on last velocity sign. - """ - return self._direction + # @property + # def direction(self): + # """ + # Either '+' or '-' depending on last velocity sign. + # """ + # return self._direction - @direction.setter - def direction(self, sign): - if sign not in ('+', '-'): - raise ValueError("Direction bust be '+' or '-'") - self._direction = sign + # @direction.setter + # def direction(self, sign): + # if sign not in ('+', '-'): + # raise ValueError("Direction must be '+' or '-'") + # self._direction = sign @property def acceleration(self): @@ -266,7 +266,7 @@ def velocity(self): @velocity.setter def velocity(self, velocity): - self._direction = '+' if velocity > 0 else '-' + #self._direction = '+' if velocity > 0 else '-' velocity = abs(velocity) velocity = float( assume_units(velocity, self._units / (u.s)) @@ -884,11 +884,13 @@ def move_to_hardware_limit(self): """ self._newport_cmd("MT", target=self.axis_id) - def move_indefinitely(self): + def move_indefinitely(self, direction: str = '+'): """ - Move until told to stop + Move until told to stop in the direction ("+" or "-") passed. """ - self._newport_cmd(f"MV{self._direction}", target=self.axis_id) + if direction is not in ("+", "-"): + raise ValueError("Direction must be '+' or '-'") + self._newport_cmd(f"MV{direction}", target=self.axis_id) def abort_motion(self): """ @@ -971,7 +973,6 @@ def setup_axis(self, **kwargs): * 'voltage' = motor voltage (V) * 'units' = set units (see NewportESP301.Units)(U) * 'encoder_resolution' = value of encoder step in terms of (U) - * 'direction' = sign of velocity ('+' or '-') * 'max_velocity' = maximum velocity (U/s) * 'max_base_velocity' = maximum working velocity (U/s) * 'homing_velocity' = homing speed (U/s) @@ -1009,7 +1010,7 @@ def setup_axis(self, **kwargs): self.voltage = kwargs.get("voltage") self.units = int(kwargs.get("units")) self.encoder_resolution = kwargs.get("encoder_resolution") - self.direction = kwargs.get("direction") + #self.direction = kwargs.get("direction") self.max_acceleration = kwargs.get("max_acceleration") self.max_velocity = kwargs.get("max_velocity") self.max_base_velocity = kwargs.get("max_base_velocity") @@ -1098,7 +1099,7 @@ def read_setup(self): config["full_step_resolution"] = self.full_step_resolution config["position_display_resolution"] = self.position_display_resolution config["current"] = self.current - config["direction"] = self.direction + #config["direction"] = self.direction config["max_velocity"] = self.max_velocity config["encoder_resolution"] = self.encoder_resolution config["acceleration"] = self.acceleration From 36295e404bf60bc8149c1ec26a1fc660c0618c8c Mon Sep 17 00:00:00 2001 From: Cbantz Date: Tue, 15 Jul 2025 12:27:12 -0500 Subject: [PATCH 4/6] Fix syntax error in direction check Corrected the syntax for checking if direction is '+' or '-' --- src/instruments/newport/newportesp301.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/instruments/newport/newportesp301.py b/src/instruments/newport/newportesp301.py index f77ecfb5..8f48b2f9 100644 --- a/src/instruments/newport/newportesp301.py +++ b/src/instruments/newport/newportesp301.py @@ -888,7 +888,7 @@ def move_indefinitely(self, direction: str = '+'): """ Move until told to stop in the direction ("+" or "-") passed. """ - if direction is not in ("+", "-"): + if direction not in ("+", "-"): raise ValueError("Direction must be '+' or '-'") self._newport_cmd(f"MV{direction}", target=self.axis_id) From 46f71914df616b029d8117d58f627abb5540fce2 Mon Sep 17 00:00:00 2001 From: Cbantz Date: Tue, 15 Jul 2025 14:57:55 -0500 Subject: [PATCH 5/6] Removed references to direction variable outside of move_indefinitely --- src/instruments/newport/newportesp301.py | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/src/instruments/newport/newportesp301.py b/src/instruments/newport/newportesp301.py index 8f48b2f9..f9059e86 100644 --- a/src/instruments/newport/newportesp301.py +++ b/src/instruments/newport/newportesp301.py @@ -84,7 +84,7 @@ def __init__(self, controller, axis_id): self._controller = controller self._axis_id = axis_id + 1 - #self._direction = "+" + self._units = self.units # CONTEXT MANAGERS ## @@ -140,19 +140,6 @@ def is_motion_done(self): """ return bool(int(self._newport_cmd("MD?", target=self.axis_id))) - # @property - # def direction(self): - # """ - # Either '+' or '-' depending on last velocity sign. - # """ - # return self._direction - - # @direction.setter - # def direction(self, sign): - # if sign not in ('+', '-'): - # raise ValueError("Direction must be '+' or '-'") - # self._direction = sign - @property def acceleration(self): """ @@ -266,7 +253,6 @@ def velocity(self): @velocity.setter def velocity(self, velocity): - #self._direction = '+' if velocity > 0 else '-' velocity = abs(velocity) velocity = float( assume_units(velocity, self._units / (u.s)) @@ -1010,7 +996,6 @@ def setup_axis(self, **kwargs): self.voltage = kwargs.get("voltage") self.units = int(kwargs.get("units")) self.encoder_resolution = kwargs.get("encoder_resolution") - #self.direction = kwargs.get("direction") self.max_acceleration = kwargs.get("max_acceleration") self.max_velocity = kwargs.get("max_velocity") self.max_base_velocity = kwargs.get("max_base_velocity") @@ -1099,7 +1084,6 @@ def read_setup(self): config["full_step_resolution"] = self.full_step_resolution config["position_display_resolution"] = self.position_display_resolution config["current"] = self.current - #config["direction"] = self.direction config["max_velocity"] = self.max_velocity config["encoder_resolution"] = self.encoder_resolution config["acceleration"] = self.acceleration From 058c886fe4dcd8f8a98ff85aa71ba719644ad627 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 15 Jul 2025 20:03:35 +0000 Subject: [PATCH 6/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/instruments/newport/newportesp301.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/instruments/newport/newportesp301.py b/src/instruments/newport/newportesp301.py index f9059e86..136d3860 100644 --- a/src/instruments/newport/newportesp301.py +++ b/src/instruments/newport/newportesp301.py @@ -42,7 +42,6 @@ def __init__(self, filelike): self._command_list = [] self._bulk_query_resp = "" self.terminator = "\r" - class Axis: """ @@ -870,7 +869,7 @@ def move_to_hardware_limit(self): """ self._newport_cmd("MT", target=self.axis_id) - def move_indefinitely(self, direction: str = '+'): + def move_indefinitely(self, direction: str = "+"): """ Move until told to stop in the direction ("+" or "-") passed. """