Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

State one read tango state #10

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 51 additions & 8 deletions sardana_tango/ctrl/TangoAttrMotorCtrl.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@

import math # noqa: F401
import time

from tango import AttrQuality, AttributeProxy, DevFailed
from tango import AttrQuality, AttributeProxy, DevFailed, DevState
from sardana import State, DataAccess
from sardana.pool.controller import MotorController
from sardana.pool.controller import Type, Access, Description


TANGO_ATTR = 'TangoAttribute'
TANGO_LIMIT_PLUS = 'TangoLimitPlus'
TANGO_LIMIT_MINUS = 'TangoLimitMinus'
FORMULA_READ = 'FormulaRead'
FORMULA_WRITE = 'FormulaWrite'
TANGO_ATTR_ENC = 'TangoAttributeEncoder'
Expand All @@ -16,6 +19,8 @@

TAU_ATTR = 'TauAttribute'
TAU_ATTR_ENC = 'TauAttributeEnc'
TAU_LIMIT_PLUS = 'TauLimitPlus'
TAU_LIMIT_MINUS = 'TauLimitMinus'
MOVE_TO = 'MoveTo'
MOVE_TIMEOUT = 'MoveTimeout'

Expand All @@ -39,6 +44,8 @@ class TangoAttrMotorController(MotorController):
ch2.FormulaWrite = 'math.pow(VALUE,2)'

Each motor could use the following optional extra attributes:
+) TangoLimitPlus/Minus - Used to set the boolean attributes for limit
switches.
+) TangoAttributeEncoder - Used in case you want to use another attribute
(different than the TangoAttribute) when the motor's position is to be
read.
Expand All @@ -63,6 +70,18 @@ class TangoAttrMotorController(MotorController):
' (e.g. my/tango/dev/attr)',
Access: DataAccess.ReadWrite
},
TANGO_LIMIT_PLUS: {
Type: str,
Description: 'The Tango Attribute indicating positive limit'\
' (e.g. my/tango/dev/limit_plus)',
Access: DataAccess.ReadWrite
},
TANGO_LIMIT_MINUS: {
Type: str,
Description: 'The Tango Attribute indicating negative limit'\
' (e.g. my/tango/dev/limit_minus)',
Access: DataAccess.ReadWrite
},
FORMULA_READ: {
Type: str,
Description: 'The Formula to get the desired position from'
Expand Down Expand Up @@ -101,6 +120,8 @@ def __init__(self, inst, props, *args, **kwargs):
def AddDevice(self, axis):
self.axisAttributes[axis] = {}
self.axisAttributes[axis][TAU_ATTR] = None
self.axisAttributes[axis][TAU_LIMIT_PLUS] = None
self.axisAttributes[axis][TAU_LIMIT_MINUS] = None
self.axisAttributes[axis][FORMULA_READ] = 'VALUE'
self.axisAttributes[axis][FORMULA_WRITE] = 'VALUE'
self.axisAttributes[axis][TAU_ATTR_ENC] = None
Expand All @@ -118,16 +139,17 @@ def StateOne(self, axis):
status = 'ok'
switch_state = 0
tau_attr = self.axisAttributes[axis][TAU_ATTR]
tau_limit_plus = self.axisAttributes[axis][TAU_LIMIT_PLUS]
tau_limit_minus = self.axisAttributes[axis][TAU_LIMIT_MINUS]
enc_threshold = self.axisAttributes[axis][TANGO_ATTR_ENC_THRESHOLD]
if tau_attr is None:
return (State.Alarm, "attribute proxy is None", 0)

if tau_attr.read().quality == AttrQuality.ATTR_CHANGING:
state = State.Moving

elif self.axisAttributes[axis][MOVE_TIMEOUT] is not None:
elif (self.axisAttributes[axis][MOVE_TIMEOUT] != None) and (enc_threshold > 0):
# tau_attr_enc = self.axisAttributes[axis][TAU_ATTR_ENC]
enc_threshold = self.axisAttributes[
axis][TANGO_ATTR_ENC_THRESHOLD]
move_to = self.axisAttributes[axis][MOVE_TO]
move_timeout = self.axisAttributes[axis][MOVE_TIMEOUT]

Expand All @@ -147,9 +169,25 @@ def StateOne(self, axis):
' in [%f,%f]' % (current_pos,
move_to - enc_threshold,
move_to + enc_threshold))

# SHOULD DEAL ALSO ABOUT LIMITS
switch_state = 0
else:
state = tau_attr.state()

limit_plus = 0
limit_minus = 0
switch_state = MotorController.NoLimitSwitch
if tau_limit_plus:
limit_plus = tau_limit_plus.read().value
if tau_limit_minus:
limit_minus = tau_limit_minus.read().value

if limit_plus:
switch_state |= MotorController.UpperLimitSwitch
state = State.Alarm
elif limit_minus:
switch_state |= MotorController.LowerLimitSwitch

if (state != State.Moving) & (limit_plus | limit_minus):
state = State.Alarm
return (state, status, switch_state)
except Exception as e:
self._log.error(" (%d) error getting state: %s" % (axis, str(e)))
Expand Down Expand Up @@ -240,10 +278,15 @@ def SetAxisExtraPar(self, axis, name, value):
self._log.debug(
"SetAxisExtraPar [%d] %s = %s" % (axis, name, value))
self.axisAttributes[axis][name] = value
if name in [TANGO_ATTR, TANGO_ATTR_ENC]:
if name in [TANGO_ATTR, TANGO_ATTR_ENC, TANGO_LIMIT_PLUS,
TANGO_LIMIT_MINUS]:
key = TAU_ATTR
if name == TANGO_ATTR_ENC:
key = TAU_ATTR_ENC
elif name == TANGO_LIMIT_PLUS:
key = TAU_LIMIT_PLUS
elif name == TANGO_LIMIT_MINUS:
key = TAU_LIMIT_MINUS
try:
self.axisAttributes[axis][key] = AttributeProxy(value)
except Exception as e:
Expand Down
1 change: 1 addition & 0 deletions sardana_tango/ctrl/TangoAttrZeroDCtrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def set_axis_extra_par(self, axis, name, value):
self.devsExtraAttributes[axis][DEVICE] = dev
self.devsExtraAttributes[axis][ATTRIBUTE] = attr
self.axis_by_tango_attribute[value] = axis



class TangoAttrZeroDController(ReadTangoAttributes, ZeroDController):
Expand Down