129 lines
4.5 KiB
Python
129 lines
4.5 KiB
Python
import time
|
|
import ch.psi.pshell.device.PositionerConfig as PositionerConfig
|
|
|
|
class LinearAxisMotor(PositionerBase):
|
|
def __init__(self, robot, name = "z_lin"):
|
|
PositionerBase.__init__(self, name, PositionerConfig())
|
|
self.robot = robot
|
|
|
|
@property
|
|
def target_coordinates(self):
|
|
return {k: m.setpoint for k,m in robot.linear_axis_motors.items()}
|
|
|
|
#ATTENTION: Always initialize linear axis motors before scanning (or call robot.set_lin_axis_motor_enabled(True))
|
|
def doInitialize(self):
|
|
self.setpoint = self.doReadReadback()
|
|
self.setCache(self.doRead(), None)
|
|
|
|
def doRead(self):
|
|
return float("nan") if self.robot.linear_axis_destination is None else float(self.robot.linear_axis_destination[self.name])
|
|
|
|
def doWrite(self, value):
|
|
if self.robot.linear_axis_destination is not None:
|
|
self.setpoint = value
|
|
self.robot.linear_axis_destination.update({self.name: value})
|
|
self.setCache(float(value), None)
|
|
robot.evaluate("n_moveAbsPos = " + str(value))
|
|
robot.evaluate("setEcAo(ecao_posSet,n_moveAbsPos)")
|
|
|
|
def doReadReadback(self):
|
|
return float("nan") if len(self.robot.linear_axis_pos)==0 else float(self.robot.linear_axis_pos[self.name])
|
|
|
|
def stop(self):
|
|
robot.evaluate("setEcDo(ecdo_linMotStop,true)")
|
|
time.sleep(0.1)
|
|
robot.evaluate("setEcDo(ecdo_linMotStop,false)")
|
|
|
|
class RobotCartesianMotor(PositionerBase):
|
|
def __init__(self, robot, name):
|
|
PositionerBase.__init__(self, name, PositionerConfig())
|
|
self.robot = robot
|
|
|
|
@property
|
|
def target_coordinates(self):
|
|
return {k: m.setpoint for k,m in robot.cartesian_motors.items()}
|
|
|
|
#ATTENTION: Always initialize cartesian motors before scanning (or call robot.set_motors_enabled(True))
|
|
def doInitialize(self):
|
|
self.setpoint = self.doReadReadback()
|
|
self.setCache(self.doRead(), None)
|
|
|
|
def doRead(self):
|
|
return float("nan") if self.robot.cartesian_destination is None else float(self.robot.cartesian_destination[self.name])
|
|
|
|
def doWrite(self, value):
|
|
if self.robot.cartesian_destination is not None:
|
|
self.setpoint = value
|
|
self.setCache(float(value), None)
|
|
robot.move_cartesian(**{self.name:value})
|
|
|
|
def doReadReadback(self):
|
|
return float("nan") if len(self.robot.cartesian_pos)==0 else float(self.robot.cartesian_pos[self.name])
|
|
|
|
def stop(self):
|
|
robot.stop()
|
|
robot.reset_motion()
|
|
robot.resume()
|
|
|
|
def move_done(self):
|
|
"""once move done, do readback update and send event and readback"""
|
|
|
|
class RobotSphericalMotor (PositionerBase):
|
|
def __init__(self, robot, name):
|
|
PositionerBase.__init__(self, name, PositionerConfig())
|
|
self.robot = robot
|
|
|
|
@property
|
|
def target_coordinates(self):
|
|
return {k: m.setpoint for k,m in robot.spherical_motors.items()}
|
|
|
|
def doInitialize(self):
|
|
self.setpoint = self.doReadReadback()
|
|
self.setCache(self.doRead(), None)
|
|
|
|
def doRead(self):
|
|
return float("nan") if len(self.robot.spherical_pos)==0 else robot.spherical_pos[self.name]
|
|
|
|
def doWrite(self, value):
|
|
if self.robot.spherical_destination is not None:
|
|
self.setpoint = value
|
|
self.setCache(float(value), None)
|
|
robot.move_spherical(**{self.name:value})
|
|
|
|
def doReadReadback(self):
|
|
return float("nan") if len(self.robot.spherical_pos)==0 else robot.spherical_pos[self.name]
|
|
|
|
def stop(self):
|
|
robot.stop()
|
|
robot.reset_motion()
|
|
robot.resume()
|
|
|
|
|
|
class RobotJointMotor (PositionerBase):
|
|
def __init__(self, robot, name):
|
|
PositionerBase.__init__(self, name, PositionerConfig())
|
|
self.robot = robot
|
|
|
|
@property
|
|
def target_coordinates(self):
|
|
return {k: m.setpoint for k,m in robot.joint_motors.items()}
|
|
|
|
def doInitialize(self):
|
|
self.setpoint = self.doReadReadback()
|
|
self.setCache(self.doRead(), None)
|
|
|
|
def doRead(self):
|
|
return self.setpoint
|
|
|
|
def doWrite(self, value):
|
|
self.setpoint = value
|
|
self.robot.move_joint(**{self.name:value})
|
|
|
|
|
|
def doReadReadback(self):
|
|
return self.robot.get_joint_pos()[self.name] if len(self.robot.joint_pos)==0 else float(self.robot.joint_pos[self.name])
|
|
|
|
def stop(self):
|
|
robot.stop()
|
|
robot.reset_motion()
|
|
robot.resume() |