Commit 8aaef0b9 authored by Jose Tiago Macara Coutinho's avatar Jose Tiago Macara Coutinho
Browse files

motion: add support for units

parent e78752f5
This diff is collapsed.
...@@ -33,6 +33,7 @@ from bliss.config.settings import QueueSetting ...@@ -33,6 +33,7 @@ from bliss.config.settings import QueueSetting
from bliss.controllers.motor_group import Group from bliss.controllers.motor_group import Group
from bliss.common.units import ureg as ur
_ERR = '!ERR' _ERR = '!ERR'
_MAX_COLS = 9 _MAX_COLS = 9
...@@ -302,7 +303,14 @@ def __row_positions(positions, motors, fmt, sep=' '): ...@@ -302,7 +303,14 @@ def __row_positions(positions, motors, fmt, sep=' '):
def __row(cols, fmt, sep=' '): def __row(cols, fmt, sep=' '):
return sep.join([format(col, fmt) for col in cols]) data = []
for col in cols:
if isinstance(col, ur.Quantity):
col = str(col)
else:
col = format(col, fmt)
data.append(col)
return sep.join(data)
def __umove(*args, **kwargs): def __umove(*args, **kwargs):
......
from pint import UnitRegistry
ureg = UnitRegistry()
# use short ASCII print format
ureg.default_format = '~'
...@@ -11,7 +11,7 @@ import random ...@@ -11,7 +11,7 @@ import random
from bliss.controllers.motor import Controller from bliss.controllers.motor import Controller
from bliss.common import log as elog from bliss.common import log as elog
from bliss.common.axis import AxisState from bliss.common.axis import AxisState, to_magnitude
from bliss.common import event from bliss.common import event
from bliss.common.utils import object_method from bliss.common.utils import object_method
...@@ -90,13 +90,13 @@ class Mockup(Controller): ...@@ -90,13 +90,13 @@ class Mockup(Controller):
if axis.config.get("persistent_position", bool, if axis.config.get("persistent_position", bool,
default=False, inherited=True): default=False, inherited=True):
try: try:
dial_pos = axis.settings.get("dial_position") dial_pos = axis.settings.get("dial_position") or 0
except: except:
pass pass
def set_pos(move_done, axis=axis): def set_pos(move_done, axis=axis):
if move_done: if move_done:
self.set_position(axis, axis.dial()*axis.steps_per_unit) dial = to_magnitude(axis.dial(), axis.unit)
self.set_position(axis, dial*axis.steps_per_unit)
self._axis_moves[axis] = { self._axis_moves[axis] = {
"measured_simul": False, "measured_simul": False,
......
...@@ -20,6 +20,7 @@ six >= 1.10 ...@@ -20,6 +20,7 @@ six >= 1.10
tabulate tabulate
sphinx >= 1.4 sphinx >= 1.4
pyserial >= 3.0 pyserial >= 3.0
pint
# --- optional dependencies -------------------------------- # --- optional dependencies --------------------------------
......
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