This VmExecutor controls the vertical opening.
#!/bin/env python
# File name: /usr/local/experiment/Tango/VmCode/s1dy.py
import PyTango
import math
## Detector Slit Vertical Gap
##
## This motor does the combined move of two motors
## to control the vertical opening of the slits
MOTOR_TOP = "p99/motor/d1.01"
MOTOR_BOTTOM = "p99/motor/d1.02"
class VM:
#
# init_device
#
def __init__( self):
self.PositionSim = 0
self.ResultSim = []
self.ResultSim.append("Vertical Gap: PositionSim not set")
self.ResultSim.append("slit_top: PositionSim not set")
self.ResultSim.append("slit_bottom: PositionSim not set")
self.proxies = []
self.proxies.append( PyTango.DeviceProxy( MOTOR_TOP))
self.proxies.append( PyTango.DeviceProxy( MOTOR_BOTTOM))
return
#
# dev_state
#
def dev_state( self):
argout = PyTango.DevState.ON
#
# if one device is in FAULT the VM is in FAULT too
#
for proxy in self.proxies:
if proxy.state() == PyTango.DevState.FAULT:
argout = PyTango.DevState.FAULT
break
if argout == PyTango.DevState.ON:
#
# if one device is MOVING the VM is MOVING too
#
for proxy in self.proxies:
if proxy.state() == PyTango.DevState.MOVING:
argout = PyTango.DevState.MOVING
break
return argout
#
# Position
#
def read_Position( self):
position = self.calc_pos()
return position
def write_Position( self, argin):
pos_top = self.proxies[0].Position
pos_bottom = self.proxies[1].Position
delta = self.calc_delta(argin)
self.proxies[0].Position = pos_top + delta/2.
self.proxies[1].Position = pos_bottom - delta/2.
return 1
#
# UnitLimitMax
#
def read_UnitLimitMax( self):
pos_top = self.proxies[0].Position
pos_down = self.proxies[1].Position
opening = pos_top - pos_down
check_limit_top = self.proxies[0].UnitLimitMax - pos_top
check_limit_down = pos_down - self.proxies[1].UnitLimitMin
if check_limit_top < check_limit_down:
limit_max = opening + 2*check_limit_top
elif check_limit_down < check_limit_top:
limit_max = opening + 2*check_limit_down
else:
limit_max = (self.proxies[0].UnitLimitMax - self.proxies[1].UnitLimitMin)
return limit_max
def write_UnitLimitMax( self, argin):
pass
#PyTango.Except.throw_exception( "vm", "UnitLimitMax can not be written", "VmExecutor")
#
# UnitLimitMin
#
def read_UnitLimitMin( self):
pos_top = self.proxies[0].Position
pos_down = self.proxies[1].Position
opening = pos_top - pos_down
check_limit_top = pos_top - self.proxies[0].UnitLimitMin
check_limit_down = self.proxies[1].UnitLimitMax - pos_down
if check_limit_top < check_limit_down:
limit_min = opening - 2*check_limit_top
elif check_limit_down < check_limit_top:
limit_min = opening - 2*check_limit_down
else:
limit_min = (self.proxies[0].UnitLimitMin - self.proxies[1].UnitLimitMax)
return limit_min
def write_UnitLimitMin( self, argin):
pass
#PyTango.Except.throw_exception( "vm", "UnitLimitMin can not be written", "VmExecutor")
#
# CwLimit, CcwLimit
#
def read_CwLimit( self):
argout = 0
#
# if one of the motors is in the limit return 1
#
for proxy in self.proxies:
if proxy.CwLimit == 1:
argout = 1
break
return argout
def read_CcwLimit( self):
argout = 0
#
# if one of the motors is in the limit return 1
#
for proxy in self.proxies:
if proxy.CcwLimit == 1:
argout = 1
break
return argout
#
# PositionSim
#
def read_PositionSim( self):
return self.PositionSim
def write_PositionSim( self, argin):
self.PositionSim = argin
def read_ResultSim( self):
pos_top = self.proxies[0].Position
pos_bottom = self.proxies[1].Position
delta = self.calc_delta(self.PositionSim)
self.ResultSim[0] = "Vertical Gap: %g " % self.PositionSim
self.ResultSim[1] = "slit_top: %g " % (pos_top + delta/2.)
self.ResultSim[2] = "slit_bottom: %g " % (pos_bottom - delta/2.)
return self.ResultSim
def StopMove( self):
for proxy in self.proxies:
proxy.StopMove()
return 1
def Calibrate(self, argin):
pos_top = self.proxies[0].Position
pos_bottom = self.proxies[1].Position
center = (pos_top + pos_bottom)/2.
newpos_top = center + argin/2.
newpos_bottom = center - argin/2.
self.proxies[0].Calibrate(newpos_top)
self.proxies[1].Calibrate(newpos_bottom)
return 1
def calc_pos(self):
p1 = self.proxies[0].Position
p2 = self.proxies[1].Position
pos = p1 - p2
return pos
def calc_delta(self, argin):
pos = self.calc_pos()
delta = argin - pos
return delta