Commit 5fbcf2c5 authored by bliss administrator's avatar bliss administrator
Browse files

* added mot_findhome / mot_findlimit

* desc replace motordesc and should work on all objects
parent 459c66f4
from gevent import sleep
from bliss.controllers.motors.icepap import Icepap
from bliss.common.cleanup import error_cleanup
from bliss.shell.standard import wm
__all__ = ["mot_findref", "mot_showref", "mot_findrange"]
__all__ = ["mot_findref", "mot_showref", "mot_findrange", "mot_findhome", "mot_findlimit"]
def mot_findrange(axis, direction=+1):
......@@ -15,19 +16,19 @@ def mot_findrange(axis, direction=+1):
# --- first limit
print("Searching {0} hardware limit {1}".format(axis.name, lim_dir>0 and "positive" or "negative"))
axis.hw_limit(lim_dir)
mot_findlimit(axis, lim_dir)
lim_dial1 = axis.limit_found_dial()
lim_user1 = axis.dial2user(lim_dial1)
print(f"First limit found at = dial:{lim_dial1:g} user:{lim_user1:g}")
print(f"First limit found at dial={lim_dial1:g} user={lim_user1:g}")
print()
# --- second limit
lim_dir *= -1
print("Searching {0} hardware limit {1}".format(axis.name, lim_dir>0 and "positive" or "negative"))
axis.hw_limit(lim_dir)
mot_findlimit(axis, lim_dir)
lim_dial2 = axis.limit_found_dial()
lim_user2 = axis.dial2user(lim_dial2)
print(f"Second limit found at = dial:{lim_dial2:g} user:{lim_user2:g}")
print(f"Second limit found at dial={lim_dial2:g} user={lim_user2:g}")
print()
# --- motor travel range
......@@ -49,10 +50,10 @@ def mot_findref(axis):
# --- find reference
print("Start reference search [{0}] ...".format(refcfg["search"]))
if refcfg["search"] == "HOME+":
axis.home(1)
mot_findhome(axis, 1)
ref_pos = axis.home_found_dial()
elif refcfg["search"] == "HOME-":
axis.home(-1)
mot_findhome(axis, -1)
ref_pos = axis.home_found_dial()
elif refcfg["search"] == "HOME":
dial_pos = axis.dial
......@@ -60,13 +61,13 @@ def mot_findref(axis):
home_dir = -1
else:
home_dir = 1
axis.home(home_dir)
mot_findhome(axis, home_dir)
ref_pos = axis.home_found_dial()
elif refcfg["search"] == "LIM+":
axis.hw_limit(1)
mot_findlimit(axis, 1)
ref_pos = axis.limit_found_dial()
elif refcfg["search"] == "LIM-":
axis.hw_limit(-1)
mot_findlimit(axis, -1)
ref_pos = axis.limit_found_dial()
print("Reference found at : {0:g} [dial units]".format(ref_pos))
print("Reference configured : {0:g} [dial units]".format(refcfg["dial"]))
......@@ -76,11 +77,16 @@ def mot_findref(axis):
offset = axis.dial - ref_pos
# --- resets dial at reference
print()
ans = _yes_no("Do you want to set reference dial position to {0:g}".format(refcfg["dial"]), False)
if ans is True:
print("==> set dial position to {0:g}".format(refcfg["dial"]))
axis.dial = refcfg["dial"] + offset
else:
print(f"==> dial position unchanged.")
# --- set limits
print()
if refcfg["low_limit"] is None or refcfg["high_limit"] is None:
print("Reference dial limits not configured. No change.")
else:
......@@ -91,11 +97,17 @@ def mot_findref(axis):
False,
)
if ans is True:
print("==> set limits to ({0:g}, {1:g})".format(
refcfg["low_limit"], refcfg["high_limit"]
))
low_user = axis.dial2user(refcfg["low_limit"])
high_user = axis.dial2user(refcfg["high_limit"])
axis.limits = (low_user, high_user)
else:
print("==> motor limits unchanged.")
# --- user position
print()
if refcfg["user"] is None:
print("Reference user position not configured. No change.")
else:
......@@ -103,8 +115,11 @@ def mot_findref(axis):
"Do you want to set user position to {0:g}".format(refcfg["user"]), False
)
if ans is True:
print("==> user position set to {0:g}".format(refcfg["user"]))
user_pos = refcfg["user"] + axis.sign * offset
axis.position = user_pos
else:
print("==> user position unchanged.")
# --- show current config
wm(axis)
......@@ -122,7 +137,22 @@ def mot_showref(axis):
print("* user position at reference : {user}".format(**refcfg))
print()
def mot_findhome(axis, direction=1):
axis.home(direction, wait=False)
mot_move_poll(axis)
def mot_move_poll(axis):
with error_cleanup(axis.stop):
while axis.is_moving:
print(f"\r{axis.name}: dial={axis.dial:g} user={axis.position:g}", end="", flush=True)
sleep(0.1)
print(f"\r{axis.name}: dial={axis.dial:g} user={axis.position:g}", end="", flush=True)
print("")
def mot_findlimit(axis, direction=1):
axis.hw_limit(direction, wait=False)
mot_move_poll(axis)
def _yes_no(msg, flag):
defans = flag is True and "YES" or "NO"
ask = msg + f" [{defans}] ? "
......
def motordesc(*mots):
for mot in mots:
cfg = mot.config.config_dict
desc = cfg.get("description", "no description.")
print(f"{mot.name} : {desc}")
from bliss.config.static import get_config
def desc(*objs):
for obj in objs:
try:
config = get_config()
objcfg = config.get_config(obj.name)
desc = objcfg.get("description", "no description.")
print(f"{obj.name} : {desc}")
except:
print(f"Failed to get config for {obj}")
Markdown is supported
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