Commit 334cceef authored by Matias Guijarro's avatar Matias Guijarro
Browse files

axis: _set_position_and_offset: offset is 0 if it is very close to 0 (floating...

axis: _set_position_and_offset: offset is 0 if it is very close to 0 (floating point errors), always display message with sign and offset if position is changed
parent fb82fcd9
......@@ -35,7 +35,7 @@ from bliss.common import event
from bliss.common.greenlet_utils import protect_from_one_kill
from bliss.common.utils import with_custom_members
from bliss.config.channels import Channel
from bliss.common.logtools import log_debug, lprint
from bliss.common.logtools import log_debug, lprint, lprint_disable
from bliss.common.utils import rounder
import gevent
......@@ -788,7 +788,9 @@ class Axis:
# update user_pos or offset setting
if no_offset:
user_pos = dial_pos
self._set_position_and_offset(user_pos)
with lprint_disable():
self._set_position_and_offset(user_pos)
lprint(
f"Resetting '{self.name}` dial position from {old_dial} to {new_dial} (new offset: {self.offset})"
......@@ -871,19 +873,18 @@ class Axis:
curr_pos = 0
return curr_pos
def _calc_offset(self, new_pos, dial_pos):
return new_pos - self.sign * dial_pos
def _set_position_and_offset(self, new_pos):
curr_pos = self.position
dial_pos = self.dial
prev_offset = self.offset
self._set_position = new_pos
new_offset = self._calc_offset(new_pos, dial_pos)
if curr_pos != new_pos:
new_offset = new_pos - self.sign * dial_pos
if math.isclose(new_offset, 0):
new_offset = 0
if new_offset != prev_offset or curr_pos != new_pos:
lprint(
f"Resetting '{self.name}` position from {curr_pos} to {new_pos}{'' if numpy.isclose([new_offset], [0], self.tolerance) else f' (new offset: {new_offset})'}"
f"Resetting '{self.name}` position from {curr_pos} to {new_pos} (sign: {self.sign}, offset: {new_offset})"
)
self._set_position = new_pos
self.settings.set("offset", new_offset)
self.settings.set("position", new_pos)
return new_pos
......
......@@ -6,10 +6,14 @@
# Distributed under the GNU LGPLv3. See LICENSE for more info.
import pytest
from bliss.common.logtools import logbook_printer
from bliss.common.scans import loopscan, ct
from bliss.common.counter import SoftCounter, SamplingMode
from bliss.scanning.acquisition.counter import SamplingCounterAcquisitionSlave
@pytest.fixture
def log_shell_mode():
logbook_printer.add_stdout_handler()
yield
logbook_printer.remove_stdout_handler()
def test_axis_lprint(roby, capsys, log_shell_mode):
......@@ -23,19 +27,16 @@ def test_axis_lprint(roby, capsys, log_shell_mode):
assert (
capsys.readouterr().out
== "Resetting 'roby` position from 0.1 to 0.0 (new offset: -0.1)\n"
== "Resetting 'roby` position from 0.1 to 0.0 (sign: 1, offset: -0.1)\n"
)
roby.dial = 1
assert (
capsys.readouterr().out
== "Resetting 'roby` dial position from 0.1 to 1.0 (new offset: -1.0)\n"
)
assert capsys.readouterr().out == "Resetting 'roby` dial position from 0.1 to 1.0\n"
roby.position = roby.dial = 2
assert (
capsys.readouterr().out
== "Resetting 'roby` position from 0.0 to 2.0 (new offset: 1.0)\nResetting 'roby` dial position from 1.0 to 2.0 (new offset: 0.0)\n"
== "Resetting 'roby` position from 0.0 to 2.0 (sign: 1, offset: 1.0)\nResetting 'roby` dial position from 1.0 to 2.0\n"
)
......@@ -95,7 +95,7 @@ def test_wm_exception(default_session, capsys):
output += " High inf\n"
output += " Current !ERR\n"
output += " Low -inf\n"
output += "Offset 0\n"
output += "Offset 0.0\n"
output += "\n"
output += "Dial\n"
output += " High inf\n"
......
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