Commit a0733289 authored by Matias Guijarro's avatar Matias Guijarro
Browse files

fix issue #2463: initialize _set_position with controller value, even if read mode is "encoder"

parent 7579edd3
Pipeline #40158 passed with stages
in 94 minutes and 23 seconds
......@@ -930,7 +930,12 @@ class Axis(Scannable):
sp = self.settings.get("_set_position")
if sp is not None:
return sp
position = self.position
if self._read_position_mode == self.READ_POSITION_MODE.ENCODER:
# no setting, first time pos is read, init with controller hw pos.
# issue 2463
position = self._do_read_hw_position()
else:
position = self.position
self._set_position = position
return position
......@@ -1087,7 +1092,10 @@ class Axis(Scannable):
def _hw_position(self):
if self._read_position_mode == self.READ_POSITION_MODE.ENCODER:
return self.dial_measured_position
return self._do_read_hw_position()
@lazy_init
def _do_read_hw_position(self):
try:
curr_pos = self.__controller.read_position(self) / self.steps_per_unit
except NotImplementedError:
......
......@@ -63,6 +63,14 @@ def test_move(m1):
assert m1.position == pytest.approx(m1.encoder.read())
def test_issue_2463(default_session):
default_session.config.get_config("m1")["read_position"] = "encoder"
m1 = default_session.config.get("m1")
with mock.patch.object(m1.controller, "read_encoder", return_value=1000):
assert m1._set_position == 0
def test_encoder_counter(default_session, m1, m1enc):
s = scans.loopscan(3, 0.1, m1enc)
assert numpy.array_equal(s.get_data()["m1enc"], [m1enc.read()] * 3)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment