This VmExecutor controls the horizontal center position.
#!/bin/env python # # File name: /usr/local/experiment/Tango/VmCode/s1cx.py # import PyTango import math ## Detector Slit Horizontal Center ## ## This motor does the combined move of two motors ## to control the horizontal centering of the slits MOTOR_LEFT = "p99/motor/d1.03" MOTOR_RIGHT = "p99/motor/d1.04" class VM: # # init_device # def __init__( self): self.PositionSim = 0 self.ResultSim = [] self.ResultSim.append("Horizontal Centering: PositionSim not set") self.ResultSim.append("slit_left: PositionSim not set") self.ResultSim.append("slit_right: PositionSim not set") self.proxies = [] self.proxies.append( PyTango.DeviceProxy( MOTOR_LEFT)) self.proxies.append( PyTango.DeviceProxy( MOTOR_RIGHT)) 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_left = self.proxies[0].Position pos_right = self.proxies[1].Position delta = self.calc_delta(argin) self.proxies[0].Position = pos_left + delta self.proxies[1].Position = pos_right + delta return 1 # # UnitLimitMax # def read_UnitLimitMax( self): pos_left = self.proxies[0].Position pos_right = self.proxies[1].Position center=(pos_left+pos_right)/2. check_limit_left = self.proxies[0].UnitLimitMax - pos_left check_limit_right = self.proxies[1].UnitLimitMax - pos_right if check_limit_left < check_limit_right: limit_max = center + check_limit_left else: limit_max = center + check_limit_right 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_left = self.proxies[0].Position pos_right = self.proxies[1].Position center=(pos_left+pos_right)/2. check_limit_left = self.proxies[0].UnitLimitMin - pos_left check_limit_right = self.proxies[1].UnitLimitMin - pos_right if check_limit_left < check_limit_right: limit_min = center + check_limit_left else: limit_min = center + check_limit_right 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_left = self.proxies[0].Position pos_right = self.proxies[1].Position delta = self.calc_delta(self.PositionSim) self.ResultSim[0] = "Horizontal Centering: %g " % self.PositionSim self.ResultSim[1] = "slit_left: %g " % (pos_left + delta) self.ResultSim[2] = "slit_right: %g " % (pos_right + delta) return self.ResultSim def StopMove( self): for proxy in self.proxies: proxy.StopMove() return 1 def Calibrate(self, argin): pos_left = self.proxies[0].Position pos_right = self.proxies[1].Position delta=self.calc_delta(argin) newpos_left = pos_left + delta newpos_right = pos_right + delta self.proxies[0].Calibrate(newpos_left) self.proxies[1].Calibrate(newpos_right) return 1 def calc_pos(self): p1 = self.proxies[0].Position p2 = self.proxies[1].Position pos = (p1 + p2)/2. return pos def calc_delta(self, argin): pos = self.calc_pos() delta = argin - pos return delta