Skip to content

Commit

Permalink
Merge pull request #938 from dkriegner/attocube_issue913
Browse files Browse the repository at this point in the history
Attocube ANC300: use method instead of property.
  • Loading branch information
BenediktBurger committed Jul 12, 2023
2 parents 6d54511 + 6b42a79 commit 9ed17d3
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 15 deletions.
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Upcoming version
================

Deprecated features
-------------------
- Attocube ANC300: The :code:`stepu` and :code:`stepd` properties are deprecated, use the new :code:`move_raw` method instead.

Version 0.12.0 (2023-07-05)
===========================
Main items of this new release:
Expand Down
68 changes: 54 additions & 14 deletions pymeasure/instruments/attocube/anc300.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import logging
import re
from math import inf
from math import inf, isfinite, isinf
from warnings import warn

from pymeasure.adapters import Adapter
Expand All @@ -38,6 +38,12 @@
log.addHandler(logging.NullHandler())


def deprecated_strict_range(value, values):
warn("This property is deprecated, use meth:`move_raw` instead.",
FutureWarning)
return strict_range(value, values)


def strict_length(value, values):
if len(value) != values:
raise ValueError(
Expand Down Expand Up @@ -132,14 +138,26 @@ class Axis(Channel):
stepu = Instrument.setting(
"stepu %d",
"""Set the steps upwards for N steps. Mode must be 'stp' and N must be
positive.""",
validator=strict_range, values=[0, inf], check_set_errors=True)
positive. 0 causes a continous movement until stop is called.
.. deprecated:: 0.13.0 Use meth:`move_raw` instead.
""",
validator=deprecated_strict_range,
values=[0, inf],
check_set_errors=True,
)

stepd = Instrument.setting(
"stepd %d",
"""Set the steps downwards for N steps. Mode must be 'stp' and N must be
positive.""",
validator=strict_range, values=[0, inf], check_set_errors=True)
positive. 0 causes a continous movement until stop is called.
.. deprecated:: 0.13.0 Use meth:`move_raw` instead.
""",
validator=deprecated_strict_range,
values=[0, inf],
check_set_errors=True,
)

def insert_id(self, command):
"""Insert the channel id in a command replacing `placeholder`.
Expand All @@ -156,26 +174,48 @@ def stop(self):
self.write('stop')
self.check_set_errors()

def move_raw(self, steps):
"""Move 'steps' steps in the direction given by the sign of the
argument. This method assumes the mode of the axis is set to 'stp' and
it is non-blocking, i.e. it will return immediately after sending the
command.
:param steps: integer value of steps to be performed. A positive
sign corresponds to upwards steps, a negative sign to downwards
steps. The values of +/-inf trigger a continuous movement. The axis
can be halted by the stop method.
"""
if isfinite(steps) and abs(steps) > 0:
if steps > 0:
self.write(f"stepu {steps:d}")
else:
self.write(f"stepd {abs(steps):d}")
elif isinf(steps):
if steps > 0:
self.write("stepu c")
else:
self.write("stepd c")
else: # ignore zero and nan values
return
self.check_set_errors()

def move(self, steps, gnd=True):
""" Move 'steps' steps in the direction given by the sign of the
"""Move 'steps' steps in the direction given by the sign of the
argument. This method will change the mode of the axis automatically
and ground the axis on the end if 'gnd' is True. The method returns
only when the movement is finished.
and ground the axis on the end if 'gnd' is True. The method is blocking
and returns only when the movement is finished.
:param steps: finite integer value of steps to be performed. A positive
sign corresponds to upwards steps, a negative sign to downwards
steps.
:param gnd: bool, flag to decide if the axis should be grounded after
completion of the movement
"""
if not isfinite(steps):
raise ValueError("Only finite number of steps are allowed.")
self.mode = 'stp'
# perform the movement
if steps > 0:
self.stepu = steps
elif steps < 0:
self.stepd = abs(steps)
else:
pass # do not set stepu/d to 0 since it triggers a continous move
self.move_raw(steps)
# wait for the move to finish
self.parent.wait_for(abs(steps) / self.frequency)
# ask if movement finished
Expand Down
30 changes: 29 additions & 1 deletion tests/instruments/attocube/test_anc300.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
# THE SOFTWARE.
#

import pytest

from pymeasure.test import expected_protocol

from pymeasure.instruments.attocube import ANC300Controller
Expand All @@ -46,7 +48,20 @@ def test_stepu():
passwd=passwd,
) as instr:
instr.a.mode = "stp"
instr.a.stepu = 15
with pytest.warns(FutureWarning):
instr.a.stepu = 15


def test_continuous_move():
"""Test a continous move setting."""
with expected_protocol(
ANC300Controller,
init_comm + [("setm 3 stp", "OK"), ("stepd 3 c", "OK"), ],
axisnames=["a", "b", "c"],
passwd=passwd,
) as instr:
instr.c.mode = "stp"
instr.c.move_raw(float('-inf'))


def test_capacity():
Expand Down Expand Up @@ -89,6 +104,19 @@ def test_measure_capacity():
assert instr.a.measure_capacity() == 1020.173401


def test_move_raw():
"""Test a raw movement."""
with expected_protocol(
ANC300Controller,
init_comm + [
("stepd 2 18", "OK"),
],
axisnames=["a", "b", "c"],
passwd=passwd,
) as instr:
instr.b.move_raw(-18)


def test_move():
"""Test a movement."""
with expected_protocol(
Expand Down

0 comments on commit 9ed17d3

Please sign in to comment.