Commit a08005e9 authored by Perceval Guillou's avatar Perceval Guillou Committed by Matias Guijarro
Browse files

fix issue 2310

parent 87aa69d2
Pipeline #40381 passed with stages
in 99 minutes and 15 seconds
......@@ -1691,7 +1691,7 @@ class Axis(Scannable):
dial = self.dial
target_pos = dial_target_pos * self.steps_per_unit
delta = target_pos - dial * self.steps_per_unit
if abs(delta) < (self.controller.steps_position_precision(self) / 2):
if self.controller._is_already_on_position(self, delta):
return # Already in position => no motion
backlash = self.backlash / self.sign * self.steps_per_unit
backlash_str = " (with %f backlash)" % self.backlash if backlash else ""
......
......@@ -496,6 +496,14 @@ class Controller:
"""
raise NotImplementedError
def _is_already_on_position(self, axis, delta):
""" return True if the difference between current position
and new position (delta) is smaller than the positioning precision
"""
if abs(delta) < (self.steps_position_precision(axis) / 2):
return True # Already in position
return False
class CalcController(Controller):
def __init__(self, *args, **kwargs):
......@@ -929,6 +937,15 @@ class CalcController(Controller):
dep_real_axes, dep_real_position, final_real_axes_position
)
def _is_already_on_position(self, axis, delta):
""" With calculated axes, always return False to ensure it updates real axes that might
have been moved independently (i.e outside CalcMotor context).
"""
if axis not in self.reals:
return False
else:
return super()._is_already_on_position(axis, delta)
def get_real_axes(*axes):
"""Return real axes from given axis objects"""
......
......@@ -822,7 +822,8 @@ class FaultyCalc(CalcController):
def calc_to_real(self, positions_dict):
return {self._axis_tag(x): None for x in self.reals}
class CoupledMotionCalc(CalcController):
def calc_from_real(self, positions_dict):
return {"calc_mot": positions_dict["mot1"]}
......
......@@ -1141,23 +1141,84 @@ def test_change_velocity_limits(robz):
with pytest.raises(ValueError, match="is below"):
robz.velocity = old_min_velocity - 6
def test_coupled_calc(beacon):
roby = beacon.get("roby")
m0 = beacon.get("m0")
cc = beacon.get("coupled_calc1")
cc.move(1)
def test_coupled_calc(default_session):
roby = default_session.config.get("roby")
m0 = default_session.config.get("m0")
robu = default_session.config.get("robu")
bad = default_session.config.get("bad")
cc1 = default_session.config.get("coupled_calc1") # calc of 2 reals
cc2 = default_session.config.get("coupled_calc2") # calc of 2 reals
cc3 = default_session.config.get("coupled_calc3") # calc of 2 calcs
# === test CalcMotor with 2 real motors as reals ==========
cc1.move(1)
assert roby.position == 1
assert m0.position == 1
m0.move(2)
assert m0.position == 2
assert cc1.position == 1
cc1.move(1)
assert roby.position == 1
assert m0.position == 1
# === test CalcMotor with 2 calc_motors as CalcMotor.reals ==========
cc3.move(1)
assert cc1.position == 1
assert cc2.position == 1
assert roby.position == 1
assert m0.position == 1
assert robu.position == 1
assert bad.position == 1
m0.move(2)
assert m0.position == 2
assert cc.position == 1
assert cc3.position == 1
assert cc1.position == 1
assert cc2.position == 1
cc3.move(1)
assert roby.position == 1
assert m0.position == 1
assert robu.position == 1
assert bad.position == 1
# ==================
cc3.move(1)
assert cc1.position == 1
assert cc2.position == 1
assert roby.position == 1
assert m0.position == 1
assert robu.position == 1
assert bad.position == 1
cc2.move(2)
assert cc2.position == 2
assert robu.position == 2
assert bad.position == 2
assert cc3.position == 1
assert cc1.position == 1
cc.move(1)
cc3.move(1)
assert roby.position == 1
assert m0.position == 1
assert robu.position == 1
assert bad.position == 1
assert cc1.position == 1
assert cc2.position == 1
......@@ -356,6 +356,25 @@ hooks:
tags: real mot1
- name: $m0
tags: real mot2
- name: coupled_calc1
tags: calc_mot
- class: CoupledMotionCalc
module: mockup
axes:
- name: $robu
tags: real mot1
- name: $bad
tags: real mot2
- name: coupled_calc2
tags: calc_mot
- class: CoupledMotionCalc
module: mockup
axes:
- name: $coupled_calc1
tags: real mot1
- name: $coupled_calc2
tags: real mot2
- name: coupled_calc3
tags: calc_mot
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