New ScreenPanel
This commit is contained in:
15
script/test/BugSetCache.py
Executable file
15
script/test/BugSetCache.py
Executable file
@@ -0,0 +1,15 @@
|
||||
|
||||
class ScalarDevice(RegisterBase):
|
||||
def doRead(self):
|
||||
return self.val if hasattr(self, 'val') else 0.0
|
||||
|
||||
def doWrite(self, val):
|
||||
self.val = val
|
||||
|
||||
def test(self):
|
||||
self.setCache(1.0, None)
|
||||
|
||||
|
||||
add_device(ScalarDevice("scan_start"), True)
|
||||
|
||||
scan_start.test()
|
||||
22
script/test/CamtoolCheckProfile.py
Executable file
22
script/test/CamtoolCheckProfile.py
Executable file
@@ -0,0 +1,22 @@
|
||||
import ch.psi.pshell.imaging.Data as Data
|
||||
|
||||
path = "2017_06/20170619/20170619_153743_snapshot.h5|/data"
|
||||
|
||||
d = load_data(path)
|
||||
atts = get_attributes(path)
|
||||
data = Data(d)
|
||||
iv = data.integrateVertically(False)
|
||||
ih = data.integrateHorizontally(False)
|
||||
xp = atts["x_profile"]
|
||||
yp = atts["y_profile"]
|
||||
p1, p2 = plot([xp, yp], ["X profile", "Y profile"])
|
||||
p1.addSeries(LinePlotSeries("data X"))
|
||||
p2.addSeries(LinePlotSeries("data Y"))
|
||||
p1.getSeries(1).setData(iv)
|
||||
p2.getSeries(1).setData(ih)
|
||||
|
||||
|
||||
p1.addSeries(LinePlotSeries("error X", None, 2))
|
||||
p2.addSeries(LinePlotSeries("error Y", None, 2))
|
||||
p1.getSeries(2).setData(arrsub(xp,iv))
|
||||
p2.getSeries(2).setData(arrsub(yp,ih))
|
||||
119
script/test/DeviceChannel.py
Executable file
119
script/test/DeviceChannel.py
Executable file
@@ -0,0 +1,119 @@
|
||||
class Channel(java.beans.PropertyChangeListener, Writable, Readable, DeviceBase):
|
||||
def __init__(self, channel_name, type = None, size = None, callback=None, alias = None):
|
||||
""" Create an object that encapsulates an Epics PV connection.
|
||||
Args:
|
||||
name(str): value to be written
|
||||
type(str, optional): type of PV. By default gets the PV standard field type.
|
||||
Scalar values: 'b', 'i', 'l', 'd', 's'.
|
||||
Array: values: '[b', '[i,', '[l', '[d', '[s'.
|
||||
size(int, optional): the size of the channel
|
||||
callback(function, optional): The monitor callback.
|
||||
alias(str): name to be used on scans.
|
||||
"""
|
||||
DeviceBase.__init__(self, channel_name if (alias is None) else alias)
|
||||
self.channel = create_channel(channel_name, type, size)
|
||||
self.callback = callback
|
||||
if alias is not None:
|
||||
set_device_alias(self, alias)
|
||||
else:
|
||||
set_device_alias(self, channel_name)
|
||||
self.initialize()
|
||||
|
||||
def get_name(self):
|
||||
"""Return the name of the channel.
|
||||
"""
|
||||
return self.channel.name
|
||||
|
||||
def get_size(self):
|
||||
"""Return the size of the channel.
|
||||
"""
|
||||
return self.channel.size
|
||||
|
||||
def set_size(self, size):
|
||||
"""Set the size of the channel.
|
||||
"""
|
||||
self.channel.size = size
|
||||
|
||||
def is_connected(self):
|
||||
"""Return True if channel is connected.
|
||||
"""
|
||||
return self.channel.connected
|
||||
|
||||
def is_monitored(self):
|
||||
"""Return True if channel is monitored
|
||||
"""
|
||||
return self.channel.monitored
|
||||
|
||||
def set_monitored(self, value):
|
||||
"""Set a channel monitor to trigger the callback function defined in the constructor.
|
||||
"""
|
||||
self.monitored = value
|
||||
|
||||
def doSetMonitored(self, value):
|
||||
self.channel.monitored = value
|
||||
if (value):
|
||||
self.channel.addPropertyChangeListener(self)
|
||||
else:
|
||||
self.channel.removePropertyChangeListener(self)
|
||||
|
||||
def propertyChange(self, pce):
|
||||
if pce.getPropertyName() == "value":
|
||||
val = pce.getNewValue()
|
||||
self.setCache(val, None)
|
||||
if self.callback is not None:
|
||||
self.callback(val)
|
||||
|
||||
def put(self, value, timeout=None):
|
||||
"""Write to channel and wait value change. In the case of a timeout throws a TimeoutException.
|
||||
Args:
|
||||
value(obj): value to be written
|
||||
timeout(float, optional): timeout in seconds. If none waits forever.
|
||||
"""
|
||||
if (timeout==None):
|
||||
self.channel.setValue(value)
|
||||
else:
|
||||
self.channel.setValueAsync(value).get(int(timeout*1000), java.util.concurrent.TimeUnit.MILLISECONDS);
|
||||
|
||||
def putq(self, value):
|
||||
"""Write to channel and don't wait.
|
||||
"""
|
||||
self.channel.setValueNoWait(value)
|
||||
|
||||
def get(self, force = False):
|
||||
"""Get channel value.
|
||||
"""
|
||||
val = self.channel.getValue(force)
|
||||
self.setCache(val, None)
|
||||
return val
|
||||
|
||||
def wait_for_value(self, value, timeout=None, comparator=None):
|
||||
"""Wait channel to reach a value, using a given comparator. In the case of a timeout throws a TimeoutException.
|
||||
Args:
|
||||
value(obj): value to be verified.
|
||||
timeout(float, optional): timeout in seconds. If None waits forever.
|
||||
comparator (java.util.Comparator, optional). If None, uses Object.equals.
|
||||
"""
|
||||
if comparator is None:
|
||||
if timeout is None:
|
||||
self.channel.waitForValue(value)
|
||||
else:
|
||||
self.channel.waitForValue(value, int(timeout*1000))
|
||||
else:
|
||||
if timeout is None:
|
||||
self.channel.waitForValue(value, comparator)
|
||||
else:
|
||||
self.channel.waitForValue(value, comparator, int(timeout*1000))
|
||||
|
||||
def close(self):
|
||||
"""Close the channel.
|
||||
"""
|
||||
self.channel.destroy()
|
||||
DeviceBase.close(self)
|
||||
|
||||
#Writable interface
|
||||
def write(self, value):
|
||||
self.put(value)
|
||||
|
||||
#Readable interface
|
||||
def read(self):
|
||||
return self.get()
|
||||
716
script/test/Robot.py
Executable file
716
script/test/Robot.py
Executable file
@@ -0,0 +1,716 @@
|
||||
from ch.psi.pshell.serial import TcpDevice
|
||||
|
||||
import threading
|
||||
|
||||
FRAME_DEFAULT = "world"
|
||||
|
||||
|
||||
|
||||
import ch.psi.pshell.device.PositionerConfig as PositionerConfig
|
||||
|
||||
|
||||
|
||||
ROBOT_MOTORS = ["x" , "y", "z", "rx", "ry", "rz"]
|
||||
|
||||
|
||||
class RobotCartesianMotor (PositionerBase):
|
||||
def __init__(self, robot, index):
|
||||
PositionerBase.__init__(self, robot.name + "_" + ROBOT_MOTORS[index], PositionerConfig())
|
||||
self.index = index
|
||||
self.robot = robot
|
||||
|
||||
#ATTENTION: Always initialize cartesian motors before scanning (or call robot.set_motors_enabled(True))
|
||||
def doInitialize(self):
|
||||
self.setCache(None, None)
|
||||
self.setCache(self.doRead(), None)
|
||||
|
||||
def doRead(self):
|
||||
return float("nan") if self.robot.cartesian_destination is None else float(robot.cartesian_destination[self.index])
|
||||
|
||||
def doWrite(self, value):
|
||||
if self.robot.cartesian_destination is not None:
|
||||
print "Move " + ROBOT_MOTORS[self.index] + " to " + str(value)
|
||||
self.robot.updating = True
|
||||
try:
|
||||
robot.cartesian_destination[self.index] = float(value)
|
||||
self.robot.set_pnt(robot.cartesian_destination , "tcp_p")
|
||||
self.robot.movel("tcp_p", self.robot.tool , DESC_SCAN)
|
||||
except:
|
||||
self.robot.updating = False
|
||||
|
||||
def doReadReadback(self):
|
||||
#return float(self.robot.get_cartesian_pos(self._get_tool(),self.frame)[self.index])
|
||||
return float("nan") if self.robot.cartesian_pos is None else float(self.robot.cartesian_pos[self.index])
|
||||
|
||||
|
||||
|
||||
|
||||
ROBOT_JOINT_MOTORS = ["j1" , "j2", "j3", "j4", "j5", "j6"]
|
||||
|
||||
|
||||
class RobotJointMotor (PositionerBase):
|
||||
def __init__(self, robot, index):
|
||||
PositionerBase.__init__(self, robot.name + "_" + ROBOT_JOINT_MOTORS[index], PositionerConfig())
|
||||
self.index = index
|
||||
self.robot = robot
|
||||
|
||||
def doInitialize(self):
|
||||
self.setpoint = self.doReadReadback()
|
||||
self.setCache(self.doRead(), None)
|
||||
|
||||
def doRead(self):
|
||||
return self.setpoint
|
||||
|
||||
def doWrite(self, value):
|
||||
print "Move " + ROBOT_JOINT_MOTORS[self.index] + " to " + str(value)
|
||||
self.setpoint = value
|
||||
joint = self.robot.herej()
|
||||
joint[self.index] = value
|
||||
self.robot.updating = True
|
||||
try:
|
||||
self.robot.set_jnt(joint, name="tcp_j")
|
||||
self.robot.movej("tcp_j", self.robot.tool , DESC_SCAN)
|
||||
finally:
|
||||
self.robot.updating = False
|
||||
|
||||
|
||||
def doReadReadback(self):
|
||||
return self.robot.herej()[self.index] if self.robot.joint_pos is None else float(self.robot.joint_pos[self.index])
|
||||
|
||||
|
||||
|
||||
class RobotTCP(TcpDevice, Stoppable):
|
||||
def __init__(self, name, server, timeout = 1000, retries = 1):
|
||||
TcpDevice.__init__(self, name, server)
|
||||
self.timeout = timeout
|
||||
self.retries = retries
|
||||
self.header = None
|
||||
self.trailer = "\n"
|
||||
self.array_separator = '|'
|
||||
self.cmd_separator = ' '
|
||||
self.msg_id = 0
|
||||
self.working_mode = "invalid"
|
||||
self.status = "invalid"
|
||||
self.powered = None
|
||||
self.settled = None
|
||||
self.empty = None
|
||||
self.working_mode = None
|
||||
self.status = None
|
||||
self.lock = threading.Lock()
|
||||
self.joint_forces = None
|
||||
self.current_task = None
|
||||
self.high_level_tasks = []
|
||||
self.cartesian_destination = None
|
||||
self.cartesian_pos = None
|
||||
self.joint_pos = None
|
||||
self.cartesian_motors_enabled = False
|
||||
self.cartesian_motors = []
|
||||
self.joint_motors_enabled = False
|
||||
self.joint_motors = []
|
||||
self.tool = None
|
||||
self.frame = FRAME_DEFAULT
|
||||
self.updating = False
|
||||
|
||||
|
||||
def doInitialize(self):
|
||||
super(RobotTCP, self).doInitialize()
|
||||
self.reset = True
|
||||
|
||||
|
||||
def set_tool(self,tool):
|
||||
self.tool = tool
|
||||
if self.cartesian_motors_enabled:
|
||||
self.cartesian_pos = self.get_cartesian_pos()
|
||||
for m in self.cartesian_motors:
|
||||
m.initialize()
|
||||
m.update()
|
||||
|
||||
|
||||
def get_tool(self):
|
||||
return self.tool
|
||||
|
||||
|
||||
def _sendReceive(self, msg_id, msg = "", timeout = None):
|
||||
tx = self.header if (self.header != None) else ""
|
||||
tx = tx + msg_id + " " + msg
|
||||
if (len(tx)>127):
|
||||
raise Exception("Exceeded maximum message size")
|
||||
self.getLogger().finer("TX = '" + str(tx)+ "'")
|
||||
if (self.trailer != None): tx = tx + self.trailer
|
||||
rx = self.sendReceive(tx, msg_id, self.trailer , 0, self.timeout if timeout is None else timeout, self.retries)
|
||||
rx=rx[:-1] #Remove 0A
|
||||
self.getLogger().finer("RX = '" + str(rx) + "'")
|
||||
if rx[:3] != msg_id:
|
||||
if (time.time()-start) >= timeout:
|
||||
raise Exception("Received invalid message id: " + str(rx[:3]) + " - expecting:" + msg_id )
|
||||
if len(rx)<4:
|
||||
raise Exception("Invalid message size: " + str(len(rx)) )
|
||||
if rx[3] == "*":
|
||||
raise Exception(rx[4:])
|
||||
return rx[4:]
|
||||
|
||||
def call(self, msg, timeout = None):
|
||||
self.lock.acquire()
|
||||
try:
|
||||
id = "%03d" % self.msg_id
|
||||
self.msg_id = (self.msg_id+1)%1000
|
||||
return self._sendReceive(id, msg, timeout)
|
||||
finally:
|
||||
self.lock.release()
|
||||
|
||||
def execute(self, command, *args, **kwargs):
|
||||
timeout = None if (kwargs is None) or (not kwargs.has_key("timeout")) else kwargs["timeout"]
|
||||
msg = str(command)
|
||||
if len(args)>10:
|
||||
raise Exception("Exceeded maximum number of parameters")
|
||||
for i in range(len(args)):
|
||||
msg += (self.cmd_separator if (i==0) else self.array_separator) + str(args[i])
|
||||
rx = self.call(msg, timeout)
|
||||
if rx.count(self.array_separator)>0:
|
||||
return rx.split(self.array_separator)
|
||||
return rx
|
||||
|
||||
def evaluate(self, cmd, timeout=None):
|
||||
ret = self.execute('eval', cmd, timeout=timeout)
|
||||
if type(ret) is str:
|
||||
if ret.strip() != "": raise Exception(ret)
|
||||
|
||||
def get_var(self, name):
|
||||
return self.execute('get_var', name)
|
||||
|
||||
#Makes app crash
|
||||
#def get_str(self, name='s'):
|
||||
# return self.execute('get_str', name)
|
||||
|
||||
def get_arr(self, name, size):
|
||||
return self.execute('get_arr', name, size)
|
||||
|
||||
def get_bool(self, name = "tcp_b"):
|
||||
return True if (self.execute('get_bool', name).strip() == '1') else False
|
||||
|
||||
def get_int(self, name ="tcp_n"):
|
||||
return int(self.get_var(name))
|
||||
|
||||
def get_float(self, name ="tcp_n"):
|
||||
return float(self.get_var(name))
|
||||
|
||||
def get_int_arr(self, size, name="tcp_a"):
|
||||
# not working. A Jython bug in PyUnicaode?
|
||||
#return [int(x) for x in self.get_arr("tcp_a", size)]
|
||||
ret = []
|
||||
a=self.get_arr(name, size)
|
||||
for i in range(size):
|
||||
ret.append(int(a[i]))
|
||||
return ret
|
||||
|
||||
def get_float_arr(self, size, name="tcp_a"):
|
||||
#return [float(x) for x in self.get_arr("tcp_a", size)]
|
||||
a=self.get_arr(name, size)
|
||||
ret = [];
|
||||
for i in range(size): ret.append(float(a[i]));
|
||||
return ret
|
||||
|
||||
def get_trsf(self, name="tcp_t"):
|
||||
a = self.execute('get_trf', name)
|
||||
ret = []
|
||||
for i in range(6): ret.append(float(a[i]))
|
||||
return ret
|
||||
|
||||
def set_trsf(self, l, name="tcp_t"):
|
||||
self.evaluate(name + "={" + str(l[0]) + ","+ str(l[1]) + ","+ str(l[2]) + ","+ str(l[3]) + ","+ str(l[4]) + ","+ str(l[5]) + "}")
|
||||
|
||||
def get_jnt(self, name="tcp_j"):
|
||||
a = self.execute('get_jnt', name)
|
||||
ret = []
|
||||
for i in range(6): ret.append(float(a[i]))
|
||||
return ret
|
||||
|
||||
def set_jnt(self, l, name="tcp_j"):
|
||||
self.evaluate(name + "={" + str(l[0]) + ","+ str(l[1]) + ","+ str(l[2]) + ","+ str(l[3]) + ","+ str(l[4]) + ","+ str(l[5]) + "}")
|
||||
|
||||
def get_pnt(self, name="tcp_p"):
|
||||
#a = self.execute('get_pnt', name)
|
||||
#ret = []
|
||||
#for i in range(6): ret.append(float(a[i]))
|
||||
#return ret
|
||||
return self.get_trsf(name+".trsf")
|
||||
|
||||
#trsf = (x,y,z,rx,ry,rz)
|
||||
#TODO: config = (shoulder, elbow, wrist)
|
||||
def set_pnt(self, trsf, name="tcp_p", config=None):
|
||||
self.set_trsf(trsf, name+".trsf")
|
||||
|
||||
def get_tool_trsf(self, name=None):
|
||||
if name is None:
|
||||
name = self.tool
|
||||
return self.get_trsf(name+".trsf")
|
||||
|
||||
def set_tool_trsf(self, trsf, name=None):
|
||||
if name is None:
|
||||
name = self.tool
|
||||
self.set_trsf(trsf, name+".trsf")
|
||||
|
||||
def eval_int(self, cmd):
|
||||
self.evaluate("tcp_n=" + cmd)
|
||||
return self.get_int()
|
||||
|
||||
def eval_float(self, cmd):
|
||||
self.evaluate("tcp_n=" + cmd)
|
||||
return self.get_float()
|
||||
|
||||
def eval_bool(self, cmd):
|
||||
self.evaluate("tcp_b=" + cmd)
|
||||
return self.get_bool()
|
||||
|
||||
#def eval_str(self, cmd):
|
||||
# self.evaluate("s=" + cmd)
|
||||
# return self.get_str()
|
||||
|
||||
def eval_jnt(self, cmd):
|
||||
self.evaluate("tcp_j=" + cmd)
|
||||
return self.get_jnt()
|
||||
|
||||
def eval_trf(self, cmd):
|
||||
self.evaluate("tcp_t=" + cmd)
|
||||
return self.get_trsf()
|
||||
|
||||
def eval_pnt(self, cmd):
|
||||
self.evaluate("tcp_p=" + cmd)
|
||||
return self.get_pnt()
|
||||
|
||||
|
||||
#Robot control
|
||||
def is_powered(self):
|
||||
self.powered = self.eval_bool("isPowered()")
|
||||
return self.powered
|
||||
|
||||
def enable(self):
|
||||
if not self.is_powered():
|
||||
self.evaluate("enablePower()")
|
||||
time.sleep(1.0)
|
||||
if not self.is_powered():
|
||||
raise Exception("Cannot enable power")
|
||||
|
||||
#waits for power to be actually cut off
|
||||
def disable(self):
|
||||
self.evaluate("disablePower()", timeout=5000)
|
||||
|
||||
def get_monitor_speed(self):
|
||||
self.speed = self.eval_int("getMonitorSpeed()")
|
||||
return self.speed
|
||||
|
||||
def set_monitor_speed(self, speed):
|
||||
ret = self.eval_int("setMonitorSpeed(" + str(speed) + ")")
|
||||
if (ret==-1): raise Exception("The robot is not in remote working mode")
|
||||
if (ret==-2): raise Exception("The monitor speed is under the control of the operator")
|
||||
if (ret==-3): raise Exception("The specified speed is not supported")
|
||||
|
||||
def is_calibrated(self):
|
||||
return self.eval_bool("isCalibrated()")
|
||||
|
||||
def save_program(self):
|
||||
ret = self.execute('save', timeout=5000)
|
||||
if str(ret) != "0": raise Exception("Error saving program: " + str(ret))
|
||||
|
||||
def _update_working_mode(self, mode, status):
|
||||
if mode==1:
|
||||
self.working_mode = "manual"
|
||||
self.status = "hold" if status==6 else "move"
|
||||
elif mode==2:
|
||||
self.working_mode = "test"
|
||||
self.status = "hold" if status==3 else "move"
|
||||
elif mode==3:
|
||||
self.working_mode = "local"
|
||||
self.status = "hold" if status==2 else "move"
|
||||
elif mode==4:
|
||||
self.working_mode = "remote"
|
||||
self.status = "hold" if status==2 else "move"
|
||||
else:
|
||||
self.working_mode = "invalid"
|
||||
self.status = "invalid"
|
||||
|
||||
def read_working_mode(self):
|
||||
try:
|
||||
mode = self.eval_int("workingMode(tcp_a)")
|
||||
status = int(self.get_var("tcp_a[0]"))
|
||||
self._update_working_mode(mode, status)
|
||||
self._update_state()
|
||||
except:
|
||||
self.working_mode = "invalid"
|
||||
self.status = "invalid"
|
||||
return self.working_mode
|
||||
|
||||
def get_emergency_stop_sts(self):
|
||||
st = self.eval_int("esStatus()")
|
||||
if (st== 1): return "active"
|
||||
if (st== 2): return "activated"
|
||||
return "off"
|
||||
|
||||
def get_safety_fault_signal(self):
|
||||
fault = self.eval_bool("safetyFault(s)")
|
||||
#if (fault):
|
||||
# return get_str()
|
||||
return fault
|
||||
|
||||
#Motion control
|
||||
def stop(self):
|
||||
self.evaluate("stopMove()")
|
||||
|
||||
def resume(self):
|
||||
self.evaluate("restartMove()")
|
||||
|
||||
def reset_motion(self, joint=None):
|
||||
self.evaluate("resetMotion()" if (joint is None) else ("resetMotion(" + joint + ")"))
|
||||
|
||||
def is_empty(self):
|
||||
self.empty = self.eval_bool("isEmpty()")
|
||||
self._update_state()
|
||||
return self.empty
|
||||
|
||||
def is_settled(self):
|
||||
self.settled = self.eval_bool("isSettled()")
|
||||
self._update_state()
|
||||
return self.settled
|
||||
|
||||
def get_move_id(self):
|
||||
return self.eval_int("getMoveId()")
|
||||
|
||||
def set_move_id(self, id):
|
||||
return self.evaluate("setMoveId(" + str(id) + " )")
|
||||
|
||||
def get_joint_forces(self):
|
||||
try:
|
||||
self.evaluate("getJointForce(tcp_a)")
|
||||
self.joint_forces = self.get_float_arr(6)
|
||||
return self.joint_forces
|
||||
except:
|
||||
self.joint_forces = None
|
||||
raise
|
||||
|
||||
def movej(self, joint_or_point, tool, desc):
|
||||
return self.eval_int("movej(" + joint_or_point + ", " + tool + ", " + desc +")")
|
||||
|
||||
def movel(self, point, tool, desc):
|
||||
return self.eval_int("movel(" + point + ", " + tool + ", " + desc +")")
|
||||
|
||||
def movec(self, point_interm, point_target, tool, desc):
|
||||
return self.eval_int("movec(" + point_interm + ", " + point_target + ", " + tool + ", " + desc +")")
|
||||
|
||||
|
||||
#Tool
|
||||
#This function can timeout since it synchronizes move.
|
||||
#Better check state before otherwise it can freeze the communication
|
||||
def open_tool(self, tool):
|
||||
return self.evaluate("open(" + tool + " )", timeout=3000)
|
||||
|
||||
#This function can timeout since it synchronizes move. Better check state before
|
||||
#Better check state before otherwise it can freeze the communication
|
||||
def close_tool(self, tool):
|
||||
return self.evaluate("close(" + tool + " )", timeout=3000)
|
||||
|
||||
#Arm position
|
||||
def herej(self):
|
||||
return self.eval_jnt("herej()")
|
||||
|
||||
def distance_t(self, trsf1, trsf2):
|
||||
return self.eval_float("distance(" + trsf1 + ", " + trsf2 + ")")
|
||||
|
||||
def distance_p(self, pnt1, pnt2):
|
||||
return self.eval_float("distance(" + pnt1 + ", " + pnt2 + ")")
|
||||
|
||||
def compose(self, pnt, frame, trsf):
|
||||
return self.eval_pnt("compose(" + pnt + ", " + frame + ", " + trsf + ")")
|
||||
|
||||
def here(self, tool, frame):
|
||||
return self.eval_pnt("here(" + tool + ", " + frame + ")")
|
||||
|
||||
def joint_to_point(self, tool, frame, joint="tcp_j"):
|
||||
return self.eval_pnt("jointToPoint(" + tool + ", " + frame + ", " + joint +")")
|
||||
|
||||
def point_to_joint(self, tool, initial_joint="tcp_j", point="tcp_p"):
|
||||
if self.eval_bool("pointToJoint(" + tool + ", " + initial_joint + ", " + point +", j)"):
|
||||
return self.get_jnt()
|
||||
|
||||
def position(self, point, frame):
|
||||
return self.eval_trf("position(" + point + ", " + frame + ")")
|
||||
|
||||
#Profile
|
||||
def get_profile(self):
|
||||
return self.execute('get_profile', timeout=2000)
|
||||
|
||||
def set_profile(self, name, pwd = ""):
|
||||
self.execute('set_profile', str(name), str(pwd), timeout=5000)
|
||||
|
||||
|
||||
#Task control
|
||||
def task_create(self, program, *args, **kwargs):
|
||||
program = str(program)
|
||||
priority = 10 if (kwargs is None) or (not kwargs.has_key("priority")) else kwargs["priority"]
|
||||
name = str(program if (kwargs is None) or (not kwargs.has_key("name")) else kwargs["name"])
|
||||
|
||||
if self.get_task_status(name)[0] != -1:
|
||||
raise Exception("Task already exists: " + name)
|
||||
|
||||
#taskCreate "t1", 10, read(sMessage)
|
||||
cmd = 'taskCreate "' + name + '", ' + str(priority) + ', ' + program + '('
|
||||
for i in range(len(args)):
|
||||
cmd += str(args[i]) + (',' if (i<(len(args)-1)) else '')
|
||||
cmd+=')'
|
||||
self.evaluate(cmd)
|
||||
|
||||
def task_suspend(self, name):
|
||||
self.evaluate('taskSuspend("' + str(name)+ '")')
|
||||
|
||||
#waits until the task is ready for restart
|
||||
def task_resume(self, name):
|
||||
self.evaluate('taskResume("' + str(name)+ '",0)', timeout = 2000)
|
||||
|
||||
#waits for the task to be actually killed
|
||||
def task_kill(self, name):
|
||||
#self.evaluate('taskKill("' + str(name)+ '")', timeout = 5000)
|
||||
self.execute('kill', str(name), timeout=5000)
|
||||
|
||||
def get_task_status(self, name):
|
||||
code = self.eval_int('taskStatus("' + str(name)+ '")')
|
||||
#TODO: String assignments in $exec causes application to freeze
|
||||
#status = self
|
||||
if code== -1: status = "Stopped"
|
||||
elif code== 0: status = "Paused"
|
||||
elif code== 1: status = "Running"
|
||||
#else: status = self.execute('get_help', code)
|
||||
else: status = "Error"
|
||||
return (code,status)
|
||||
|
||||
def _update_state(self):
|
||||
#self.setState(State.Busy if self.status=="move" else State.Ready)
|
||||
if self.state==State.Offline:
|
||||
print "Communication resumed"
|
||||
if self.reset or (self.state==State.Offline):
|
||||
self.get_task()
|
||||
if self.current_task is not None:
|
||||
print "Ongoing task: " + self.current_task
|
||||
|
||||
if (not self.settled) or (self.current_task is not None): self.setState(State.Busy)
|
||||
elif not self.empty: self.setState(State.Paused)
|
||||
else: self.setState(State.Ready)
|
||||
|
||||
def doUpdate(self):
|
||||
try:
|
||||
start = time.time()
|
||||
#sts = self._sendReceive("EVT").strip().split(self.array_separator)
|
||||
sts = self.execute("get_status", self.current_task)
|
||||
self._update_working_mode(int(sts[0]), int(sts[1]))
|
||||
self.powered = sts[2] == "1"
|
||||
self.speed = int(sts[3])
|
||||
self.empty = sts[4] == "1"
|
||||
self.settled = sts[5] == "1"
|
||||
ev = sts[7] if len(sts)>7 else ""
|
||||
if len(ev.strip()) >0:
|
||||
self.getLogger().info(ev)
|
||||
self.on_event(ev)
|
||||
#if (self.current_task is not None) and (self.get_task_status(self.current_task)[0]<0):
|
||||
if int(sts[6]) < 0:
|
||||
self.current_task = None
|
||||
self._update_state()
|
||||
self.reset = False
|
||||
self.setCache({"powered": self.powered,
|
||||
"speed": self.speed,
|
||||
"empty": self.empty,
|
||||
"settled": self.settled,
|
||||
"task": self.current_task,
|
||||
"mode": self.working_mode,
|
||||
"status": self.status
|
||||
}, None)
|
||||
if not self.updating:
|
||||
if self.cartesian_motors_enabled:
|
||||
self.cartesian_pos = self.get_cartesian_pos()
|
||||
for m in self.cartesian_motors:
|
||||
#m.update()
|
||||
m.readback.update()
|
||||
else:
|
||||
self.cartesian_pos = None
|
||||
if self.joint_motors_enabled:
|
||||
self.joint_pos = self.herej()
|
||||
for m in self.joint_motors:
|
||||
m.readback.update()
|
||||
except:
|
||||
if self.state != State.Offline:
|
||||
print >> sys.stderr, "Update error: " + str(sys.exc_info()[1])
|
||||
self.setState(State.Offline)
|
||||
|
||||
#Cartesian space
|
||||
|
||||
def get_cartesian_pos(self):
|
||||
return self.eval_pnt("jointToPoint(" + self.tool + ", " + self.frame + ", herej())")
|
||||
#self.set_jnt(self.herej())
|
||||
#return self.joint_to_point(tool, frame)
|
||||
|
||||
def get_cartesian_destination(self):
|
||||
return self.here(self.tool, self.frame)
|
||||
|
||||
def get_distance_to_pnt(self, name):
|
||||
#self.here(self.tool, self.frame) #???
|
||||
self.get_cartesian_pos()
|
||||
return self.distance_p("tcp_p", name)
|
||||
|
||||
#Cartesian peudo-motors
|
||||
def set_motors_enabled(self, value):
|
||||
if value !=self.cartesian_motors_enabled:
|
||||
self.cartesian_motors_enabled = value
|
||||
if value:
|
||||
for i in range(6):
|
||||
self.cartesian_motors.append(RobotCartesianMotor(self, i))
|
||||
add_device(self.cartesian_motors[i], True)
|
||||
self.cartesian_destination = self.get_cartesian_destination()
|
||||
else:
|
||||
for m in self.cartesian_motors:
|
||||
remove_device(m)
|
||||
self.cartesian_motors = []
|
||||
self.cartesian_destination = None
|
||||
else:
|
||||
if value:
|
||||
self.cartesian_destination = self.get_cartesian_destination()
|
||||
for m in self.cartesian_motors:
|
||||
m.initialize()
|
||||
|
||||
|
||||
#Cartesian peudo-motors
|
||||
def set_joint_motors_enabled(self, value):
|
||||
if value !=self.joint_motors_enabled:
|
||||
self.joint_motors_enabled = value
|
||||
if value:
|
||||
for i in range(6):
|
||||
self.joint_motors.append(RobotJointMotor(self, i))
|
||||
add_device(self.joint_motors[i], True)
|
||||
else:
|
||||
for m in self.joint_motors:
|
||||
remove_device(m)
|
||||
self.joint_motors = []
|
||||
self.joint_destination = None
|
||||
else:
|
||||
if value:
|
||||
self.joint_destination = self.get_joint_destination()
|
||||
for m in self.joint_motors:
|
||||
m.initialize()
|
||||
|
||||
|
||||
#High-level, exclusive motion task.
|
||||
def start_task(self, program, *args, **kwargs):
|
||||
tasks = [t for t in self.high_level_tasks]
|
||||
if (self.current_task is not None) and (not self.current_task in tasks):
|
||||
tasks.append(pro)
|
||||
if not program in tasks:
|
||||
tasks.append(pro)
|
||||
for task in tasks:
|
||||
if self.get_task_status(task)[0]>=0:
|
||||
raise Exception("Ongoing high-level task: " + task)
|
||||
self.task_create(program, *args, **kwargs)
|
||||
start = time.time()
|
||||
while self.get_task_status(program)[0] < 0:
|
||||
if time.time() - start > 5000:
|
||||
raise Exception("Cannot start task " + task)
|
||||
time.sleep(0.1)
|
||||
self.update()
|
||||
self.current_task = program
|
||||
self._update_state()
|
||||
|
||||
def stop_task(self):
|
||||
tasks = [t for t in self.high_level_tasks]
|
||||
if (self.current_task is not None) and (not self.current_task in tasks):
|
||||
tasks.append(self.current_task)
|
||||
for task in tasks:
|
||||
#if self.get_task_status(task)[0]>=0:
|
||||
self.task_kill(task)
|
||||
|
||||
def get_task(self):
|
||||
if self.current_task is not None:
|
||||
return self.current_task
|
||||
for task in self.high_level_tasks:
|
||||
if self.get_task_status(task)[0]>=0:
|
||||
self.current_task = task
|
||||
return task
|
||||
return None
|
||||
|
||||
|
||||
def on_event(self,ev):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
TOOL_CALIBRATION = "tCalib"
|
||||
TOOL_SUNA= "tSuna"
|
||||
TOOL_DEFAULT= TOOL_SUNA
|
||||
|
||||
DESC_FAST = "mFast"
|
||||
DESC_SLOW = "mSlow"
|
||||
DESC_SCAN = "mScan"
|
||||
DESC_DEFAULT = DESC_FAST
|
||||
|
||||
|
||||
|
||||
|
||||
simulation = True
|
||||
joint_forces = False
|
||||
|
||||
|
||||
class RobotSC(RobotTCP):
|
||||
def __init__(self, name, server, timeout = 1000, retries = 1):
|
||||
RobotTCP.__init__(self, name, server, timeout, retries)
|
||||
self.tool = TOOL_CALIBRATION
|
||||
|
||||
def mount(self, puck, sample):
|
||||
return self.execute('mount',segment, puck, sample)
|
||||
|
||||
def firstmount(self, puck, sample):
|
||||
return self.execute('firstmount', segment, puck, sample)
|
||||
|
||||
def unmount(self, puck, sample):
|
||||
return self.execute('unmount',segment, puck, sample)
|
||||
|
||||
def on_event(self,ev):
|
||||
#print "EVT: " + ev
|
||||
pass
|
||||
|
||||
def doUpdate(self):
|
||||
#start = time.time()
|
||||
RobotTCP.doUpdate(self)
|
||||
global simulation
|
||||
if not simulation:
|
||||
if joint_forces:
|
||||
if self.state != State.Offline:
|
||||
self.get_joint_forces()
|
||||
for dev in [jf1, jf2, jf3, jf4,jf5, jf6, jfc]:
|
||||
dev.update()
|
||||
#print time.time() -start
|
||||
|
||||
def start_task(self, program, *args, **kwargs):
|
||||
#TODO: Check safe position
|
||||
RobotTCP.start_task(self, program, *args, **kwargs)
|
||||
|
||||
def stop_task(self):
|
||||
RobotTCP.stop_task(self)
|
||||
#TODO: Restore safe position
|
||||
|
||||
def set_remote_mode(self):
|
||||
robot.set_profile("remote")
|
||||
|
||||
def set_local(self):
|
||||
robot.set_profile("default")
|
||||
|
||||
def set_tool(self,tool):
|
||||
if tool != self.tool:
|
||||
self.tool = tool
|
||||
for dev in (robot_x, robot_y, robot_z, robot_rx, robot_ry, robot_rz):
|
||||
dev.initialize()
|
||||
dev.update()
|
||||
|
||||
|
||||
|
||||
if simulation:
|
||||
#add_device(RobotSC("robot","129.129.126.92:1000"),force = True)
|
||||
add_device(RobotSC("robot","129.129.110.99:1000"),force = True)
|
||||
else:
|
||||
add_device(RobotSC("robot", "129.129.110.100:1000"), force = True)
|
||||
|
||||
robot.high_level_tasks = ["mount", "firstmount"]
|
||||
robot.setPolling(500)
|
||||
15
script/test/Save3d.py
Executable file
15
script/test/Save3d.py
Executable file
@@ -0,0 +1,15 @@
|
||||
|
||||
#Creating a 3D dataset from an array
|
||||
data3d = [ [ [1,2,3,4,5], [2,3,4,5,6], [3,4,5,6,7]], [ [3,2,3,4,5], [4,3,4,5,6], [5,4,5,6,7]]]
|
||||
path="group/data1"
|
||||
save_dataset(path, data3d)
|
||||
#Reading it back
|
||||
read =load_data(path,0)
|
||||
print read.tolist()
|
||||
read =load_data(path,1)
|
||||
print read.tolist()
|
||||
|
||||
|
||||
set_exec_pars(depth_dim=2)
|
||||
|
||||
save_dataset("group/data2", data3d)
|
||||
5
script/test/TEstPars.py
Executable file
5
script/test/TEstPars.py
Executable file
@@ -0,0 +1,5 @@
|
||||
#set_exec_pars(persist=False, plot_disabled=True, table_disabled=True)
|
||||
#set_exec_pars(persist=False, plot_disabled=True, table_disabled=True)
|
||||
|
||||
tscan((sin,arr), 10, 0.100, enabled_plots= [arr,], persist=False, table_disabled=False, status = "Status")
|
||||
tscan(sin, 10, 0.100)
|
||||
15
script/test/Test3dDataset.py
Executable file
15
script/test/Test3dDataset.py
Executable file
@@ -0,0 +1,15 @@
|
||||
width = cam_server.data.width
|
||||
height = cam_server.data.height
|
||||
|
||||
print
|
||||
|
||||
print width, height
|
||||
images = 4
|
||||
|
||||
path = "/image"
|
||||
|
||||
create_dataset(path, 'd', dimensions = [height, width, images])
|
||||
|
||||
|
||||
for i in range(images):
|
||||
append_dataset(path, cam_server.data.matrix)
|
||||
8
script/test/TestBack.py
Executable file
8
script/test/TestBack.py
Executable file
@@ -0,0 +1,8 @@
|
||||
camtool.setBackgroundEnabled(False)
|
||||
|
||||
camtool.start("simulation")
|
||||
camtool.setBackground(camtool.getData())
|
||||
camtool.setBackgroundEnabled(True)
|
||||
camtool.saveBackground(None)
|
||||
camtool.setBackground(None)
|
||||
camtool.loadBackground(None)
|
||||
8
script/test/TestBack2.py
Executable file
8
script/test/TestBack2.py
Executable file
@@ -0,0 +1,8 @@
|
||||
tst2.setBackgroundEnabled(False)
|
||||
|
||||
tst2.setBackground(tst2.getImage())
|
||||
tst2.setBackgroundEnabled(True)
|
||||
tst2.refresh()
|
||||
tst2.saveBackground(None)
|
||||
tst2.setBackground(None)
|
||||
tst2.loadBackground(None)
|
||||
24
script/test/TestBsget.py
Executable file
24
script/test/TestBsget.py
Executable file
@@ -0,0 +1,24 @@
|
||||
def bsget(channel):
|
||||
"""Reads an values a bsread stream, using the default provider.
|
||||
|
||||
Args:
|
||||
channel(str or list of str): channel name(s)
|
||||
Returns:
|
||||
PV value
|
||||
|
||||
"""
|
||||
channels = to_list(channel)
|
||||
st = Stream(None, None)
|
||||
try:
|
||||
for c in channels:
|
||||
st.addScalar(c, c, 1,0)
|
||||
st.initialize()
|
||||
st.start()
|
||||
st.waitValueNot(None, 5000)
|
||||
if type(channel) is str:
|
||||
return st.getValue(channel)
|
||||
return st.values
|
||||
finally:
|
||||
st.close()
|
||||
|
||||
bsget("Int32Scalar")
|
||||
17
script/test/TestCom.py
Executable file
17
script/test/TestCom.py
Executable file
@@ -0,0 +1,17 @@
|
||||
|
||||
data = camtool.getValue("x_profile")
|
||||
x = camtool.getValue("x_axis")
|
||||
y=data
|
||||
|
||||
back = [3160000 if i>3340000 else i for i in y]
|
||||
|
||||
y = arroff(y, "min")
|
||||
#y=arrsub(y, back)
|
||||
|
||||
p=plot(y, xdata = x)[0]
|
||||
#print y
|
||||
com,rms = center_of_mass(y, x)
|
||||
print com,rms
|
||||
p.addMarker(com, None, str(com), Color.GREEN)
|
||||
p.addMarker(com-rms, None, "", Color.GREEN)
|
||||
p.addMarker(com+rms, None, "", Color.GREEN)
|
||||
9
script/test/TestErrorAxis2.py
Executable file
9
script/test/TestErrorAxis2.py
Executable file
@@ -0,0 +1,9 @@
|
||||
plt = plot(None)[0]
|
||||
plt.clear()
|
||||
plt.getAxis(plt.AxisId.Y).setLabel("Axis 1")
|
||||
plt.getAxis(plt.AxisId.Y2).setLabel("Axis 2")
|
||||
plt.setStyle(plt.Style.ErrorY)
|
||||
plt.addSeries(LinePlotErrorSeries("S1"))
|
||||
plt.addSeries(LinePlotErrorSeries("S2", None, 2))
|
||||
plt.getSeries(0).appendData(1.0, 3.0 , 1.0)
|
||||
plt.getSeries(1).appendData(3.0, 2.0 , 2.0)
|
||||
16
script/test/TestGaussFit.py
Executable file
16
script/test/TestGaussFit.py
Executable file
@@ -0,0 +1,16 @@
|
||||
run("cpython/GaussFit_wrapper")
|
||||
|
||||
|
||||
x=[-200.30429237268825, -200.2650700434188, -200.22115208318002, -199.9457671375377, -199.86345548879072, -199.85213073174933, -199.35687977133284, -199.13811861090275, -197.97304970346386, -197.2952215624348, -195.09076092936948, -192.92276048970703, -191.96871876227698, -189.49577852322938, -187.9652790409825, -183.63756456925222, -180.04899765472996, -178.43839623242422, -174.07311671294445, -172.0410133577918, -165.90824309893102, -160.99771795989466, -159.30176653939253, -154.27688897558514, -152.0854103810786, -145.75652847587313, -140.80843828908465, -139.23982133191495, -134.27073891256106, -132.12649284133064, -125.95947209775511, -121.00309550337462, -119.26736932643232, -114.2706655484383, -112.07393889578914, -105.72295990367157, -100.8088439880125, -99.2034906238494, -94.30042325164636, -92.15010048151461, -85.92203653534293, -81.03913275494665, -79.27412793784428, -74.33487658582118, -72.06274362408762, -65.76562628131825, -60.91255356825276, -59.20334389560392, -54.33286972659312, -52.19387171350535, -45.94978737932291, -41.03014719193582, -39.301602568238906, -34.35572209014114, -32.04464301272608, -25.8221033382824, -20.922074315528747, -19.21590299233186, -14.31090212502093, -12.217203140101386, -5.9283722049240435, -0.9863587170369246, 0.7408048387279834, 5.71126832601389, 7.972628957879352, 14.204559894256546, 19.11839959633025, 20.8218087836657, 25.678748486941828, 27.822718344586864, 34.062659474970715, 38.9745656819391, 40.77409719734158, 45.72080631619803, 47.974156754056835, 54.23453768983539, 59.12020360609568, 60.77306570712026, 65.70734521458867, 67.8344660434617, 74.03187028154134, 78.96532114824849, 80.76070945985495, 85.74802197591286, 87.9140889204674, 94.18082276873524, 99.25790470037091, 100.68454787413205, 105.7213026221542, 107.79483801526698, 113.99555681638138, 119.0707052529143, 120.72715813056156, 125.77551384921307, 127.91257836719551, 134.2011330887875, 139.23043006997628, 140.71673537840158, 145.76288138835983, 147.80216629676042, 154.06420451405637, 159.0846626604798, 160.76183155710717, 165.73699067536242, 167.9265357747636, 173.96705069576544, 178.2522282751915, 179.9042617354548, 183.54586165856657, 185.23269803071796, 189.41678143751972, 191.87149157986588, 192.8741468985015, 195.0241934550453, 195.966634211846, 197.9821647518146, 198.99006812859284, 199.33202054855676, 199.91897441965887, 200.11536227958896, 200.22280936469997, 200.25181179127208]
|
||||
y=[11.0, 6.0, 8.0, 5.0, 11.0, 7.0, 18.0, 11.0, 12.0, 10.0, 8.0, 6.0, 16.0, 4.0, 12.0, 9.0, 15.0, 14.0, 8.0, 20.0, 15.0, 8.0, 9.0, 11.0, 13.0, 12.0, 13.0, 15.0, 13.0, 20.0, 10.0, 7.0, 17.0, 11.0, 20.0, 13.0, 13.0, 23.0, 14.0, 10.0, 17.0, 15.0, 20.0, 16.0, 14.0, 13.0, 18.0, 22.0, 9.0, 20.0, 12.0, 14.0, 17.0, 19.0, 14.0, 14.0, 23.0, 19.0, 15.0, 20.0, 20.0, 21.0, 20.0, 23.0, 22.0, 15.0, 10.0, 17.0, 21.0, 15.0, 23.0, 23.0, 25.0, 18.0, 16.0, 21.0, 22.0, 16.0, 16.0, 14.0, 19.0, 20.0, 18.0, 20.0, 23.0, 13.0, 16.0, 20.0, 25.0, 15.0, 15.0, 17.0, 22.0, 26.0, 19.0, 30.0, 25.0, 17.0, 17.0, 23.0, 16.0, 27.0, 21.0, 21.0, 26.0, 27.0, 21.0, 17.0, 20.0, 20.0, 21.0, 19.0, 25.0, 19.0, 13.0, 23.0, 20.0, 20.0, 18.0, 20.0, 19.0, 25.0]
|
||||
|
||||
[off, amp, com, sigma] = profile_gauss_stats(x, y, off=None, amp=None, com=None, sigma=None)
|
||||
print "Gauss: ", [off, amp, com, sigma]
|
||||
from mathutils import Gaussian
|
||||
|
||||
#Plotting results
|
||||
from mathutils import Gaussian
|
||||
g = Gaussian(amp, com, sigma)
|
||||
fit = [g.value(i)+off for i in x]
|
||||
|
||||
plot([y, fit], ["data", "fit"], xdata = x)
|
||||
25
script/test/TestJson.py
Executable file
25
script/test/TestJson.py
Executable file
@@ -0,0 +1,25 @@
|
||||
import requests
|
||||
import json
|
||||
|
||||
|
||||
url = 'http://MPC1900:8080/run'
|
||||
|
||||
|
||||
#Text mode
|
||||
#resp = requests.get(url=url+"/test5(steps_x=3, steps_y=5)&")
|
||||
#if resp.status_code != 200: raise Exception(resp.text)
|
||||
#print resp.text
|
||||
|
||||
|
||||
resp = requests.put(url=url, json={"script":'test5', "pars":{"steps_x":3, "steps_y":5}, "background":True })
|
||||
#resp = requests.put(url=url, json={"script":'test5', "pars":[8,10], "background":True })
|
||||
if resp.status_code != 200: raise Exception(resp.text)
|
||||
data = json.loads(resp.text)
|
||||
print data
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
39
script/test/TestLayout.py
Executable file
39
script/test/TestLayout.py
Executable file
@@ -0,0 +1,39 @@
|
||||
tutorial_path = "src/main/assembly/help/Tutorial_py/"
|
||||
run(tutorial_path+"SimulatedDevices")
|
||||
|
||||
|
||||
import ch.psi.pshell.data.LayoutDefault
|
||||
class LayoutParallelScan(ch.psi.pshell.data.LayoutDefault):
|
||||
def getDefaultGroup(self, scan):
|
||||
return scan.readables[0].name
|
||||
|
||||
|
||||
#get_context().pluginManager.addDynamicClass(LayoutParallel().getClass())
|
||||
|
||||
|
||||
#Does not work
|
||||
#lay = LayoutParallelScan().getClass()
|
||||
##print lay
|
||||
#cls = Class.forName(lay.getCanonicalName(), True, lay.getClassLoader())
|
||||
#3print cls
|
||||
#set_exec_pars(layout = "org.python.proxies.__main__$LayoutParallelScan$25")
|
||||
|
||||
|
||||
|
||||
#Must restore the layout
|
||||
#get_context().dataManager.setLayout(LayoutParallelScan())
|
||||
|
||||
set_exec_pars(layout = "Table")
|
||||
|
||||
|
||||
|
||||
def scan1():
|
||||
print "scan1"
|
||||
return lscan(ao1, ai1, 0, 40, 20, 0.1, title = "scan1")
|
||||
|
||||
def scan2():
|
||||
print "scan2"
|
||||
return lscan(ao2, ai2, 0, 40, 20, 0.1, title = "scan2")
|
||||
|
||||
|
||||
parallelize(scan1, scan2)
|
||||
3
script/test/TestPlot.py
Executable file
3
script/test/TestPlot.py
Executable file
@@ -0,0 +1,3 @@
|
||||
plot([1,2,3,4,5,4,3,2,1], "test")
|
||||
attachments = get_plot_snapshots()
|
||||
print attachments
|
||||
7
script/test/TestProsilica.py
Executable file
7
script/test/TestProsilica.py
Executable file
@@ -0,0 +1,7 @@
|
||||
|
||||
|
||||
while (True):
|
||||
prosilica.stop()
|
||||
time.sleep(0.1)
|
||||
prosilica.start()
|
||||
time.sleep(0.5)
|
||||
55
script/test/TestPyArray.py
Executable file
55
script/test/TestPyArray.py
Executable file
@@ -0,0 +1,55 @@
|
||||
def lscan(writables, readables, start, end, steps, latency=0.0, relative=False, passes=1, zigzag=False, before_read=None, after_read=None, title=None):
|
||||
"""Line Scan: positioners change together, linearly from start to end positions.
|
||||
|
||||
Args:
|
||||
writables(list of Writable): Positioners set on each step.
|
||||
readables(list of Readable): Sensors to be sampled on each step.
|
||||
start(list of float): start positions of writables.
|
||||
end(list of float): final positions of writables.
|
||||
steps(int or float or list of float): number of scan steps (int) or step size (float).
|
||||
relative (bool, optional): if true, start and end positions are relative to
|
||||
current at start of the scan
|
||||
latency(float, optional): settling time for each step before readout, defaults to 0.0.
|
||||
passes(int, optional): number of passes
|
||||
zigzag(bool, optional): if true writables invert direction on each pass.
|
||||
before_read (function, optional): callback on each step, before each readout. Callback may have as
|
||||
optional parameters list of positions.
|
||||
after_read (function, optional): callback on each step, after each readout. Callback may have as
|
||||
optional parameters a ScanRecord object.
|
||||
title(str, optional): plotting window name.
|
||||
|
||||
Returns:
|
||||
ScanResult object.
|
||||
|
||||
"""
|
||||
latency_ms=int(latency*1000)
|
||||
writables=to_list(string_to_obj(writables))
|
||||
readables=to_list(string_to_obj(readables))
|
||||
start=to_list(start)
|
||||
end=to_list(end)
|
||||
if type(steps) is float or is_list(steps):
|
||||
steps = to_list(steps)
|
||||
scan = LineScan(writables,readables, start, end , steps, relative, latency_ms, passes, zigzag)
|
||||
scan.before_read=before_read
|
||||
scan.after_read=after_read
|
||||
scan.setPlotTitle(title)
|
||||
scan.start()
|
||||
ret = scan.getResult()
|
||||
return ret
|
||||
|
||||
|
||||
a= lscan(inp, (sin,out), 0, 4, 10, 0.1)
|
||||
|
||||
x = a.getPositions(0)
|
||||
y= a.getReadable(0)
|
||||
|
||||
|
||||
|
||||
plt = plot(None,name="data")[0]
|
||||
plt.addSeries(LinePlotSeries("1"))
|
||||
plt.addSeries(LinePlotSeries("2"))
|
||||
plt.getSeries(0).setData(x,y)
|
||||
plt.getSeries(1).setData(list(x), list(y))
|
||||
plt.getSeries(2).setData(to_array(x,'d'), to_array(y,'d'))
|
||||
|
||||
|
||||
67
script/test/TestPyObj.py
Executable file
67
script/test/TestPyObj.py
Executable file
@@ -0,0 +1,67 @@
|
||||
class TestClass:
|
||||
def __init__(self):
|
||||
self.data = 10
|
||||
|
||||
def f1(self, p1 = 3, p2 = 4.0, p3 = False):
|
||||
pass
|
||||
|
||||
def f2(self, p1 = "asd", *argv, **kw):
|
||||
pass
|
||||
|
||||
def f3(self, p1 = [1,2,3], **kw):
|
||||
pass
|
||||
|
||||
def f4(self, p1 = {"v1":2.3}, *argv):
|
||||
pass
|
||||
|
||||
obj = TestClass()
|
||||
print obj.data
|
||||
|
||||
|
||||
|
||||
class TestClassDev (DeviceBase):
|
||||
def __init__(self):
|
||||
self.data = 10
|
||||
|
||||
def doInitialize(self):
|
||||
pass
|
||||
|
||||
def update(self):
|
||||
pass
|
||||
|
||||
def f1(self, p1 = 3, p2 = 4.0, p3 = False):
|
||||
pass
|
||||
|
||||
def f2(self, p1 = "asd", *argv, **kw):
|
||||
pass
|
||||
|
||||
def f3(self, p1 = [1,2,3], **kw):
|
||||
pass
|
||||
|
||||
def f4(self, p1 = {"v1":2.3}, *argv):
|
||||
pass
|
||||
|
||||
o2 = TestClassDev()
|
||||
|
||||
|
||||
|
||||
class TestClassRead (Readable):
|
||||
def __init__(self):
|
||||
self.data = 10
|
||||
|
||||
def f1(self, p1 = 3, p2 = 4.0, p3 = False):
|
||||
pass
|
||||
|
||||
def f2(self, p1 = "asd", *argv, **kw):
|
||||
pass
|
||||
|
||||
def f3(self, p1 = [1,2,3], **kw):
|
||||
pass
|
||||
|
||||
def f4(self, p1 = {"v1":2.3}, *argv):
|
||||
pass
|
||||
|
||||
def read(self):
|
||||
return 1
|
||||
|
||||
o3 = TestClassRead()
|
||||
28
script/test/TestRotation.py
Executable file
28
script/test/TestRotation.py
Executable file
@@ -0,0 +1,28 @@
|
||||
import ch.psi.pshell.epics.Positioner as Positioner
|
||||
|
||||
|
||||
class Readback(ReadonlyRegisterBase):
|
||||
def doRead(self):
|
||||
return caget("TESTIOC:TESTCALCOUT:Output",'d') + 360.0
|
||||
|
||||
readback = Readback()
|
||||
readback.initialize()
|
||||
readback.setPolling(2000)
|
||||
|
||||
p = Positioner("rot", "TESTIOC:TESTCALCOUT:Input", None, readback)
|
||||
|
||||
#p = Positioner("RotationPositioner", "TESTIOC:TESTCALCOUT:Input", "TESTIOC:TESTCALCOUT:Output")
|
||||
p.monitored=True
|
||||
p.config.minValue = -360.0
|
||||
p.config.maxValue = 360.0
|
||||
p.config.precision = 3
|
||||
p.config.rotation = True
|
||||
p.config.resolution = 0.01
|
||||
p.config.save()
|
||||
p.initialize()
|
||||
|
||||
|
||||
add_device(p, True)
|
||||
|
||||
|
||||
print readback.read()
|
||||
17
script/test/TestScan.py
Executable file
17
script/test/TestScan.py
Executable file
@@ -0,0 +1,17 @@
|
||||
print args
|
||||
|
||||
if get_exec_pars().source == CommandSource.ui:
|
||||
msg = None
|
||||
start = 0
|
||||
end = 10.0
|
||||
steps = 10
|
||||
else:
|
||||
msg = args[0]
|
||||
start = float(args[1])
|
||||
end = float(args[2])
|
||||
steps = int(args[3])
|
||||
|
||||
|
||||
print msg
|
||||
r = lscan (out, sin, start, end, steps, 0.2)
|
||||
|
||||
75
script/test/TestUndulatorScan.py
Executable file
75
script/test/TestUndulatorScan.py
Executable file
@@ -0,0 +1,75 @@
|
||||
import ch.psi.pshell.epics.ControlledVariable as ControlledVariable
|
||||
import ch.psi.pshell.epics.ChannelSettlingCondition as ChannelSettlingCondition
|
||||
import ch.psi.pshell.device.SettlingCondition as SettlingCondition
|
||||
|
||||
#cam_server.start("SAROP21-PSRD103_sp1", True)
|
||||
pip.start("simulation_sp")
|
||||
pip.stream.waitCacheChange(-1)
|
||||
i = pip.stream.getChild("intensity")
|
||||
iavg = create_averager(i, 2, interval = -1)
|
||||
|
||||
x=0
|
||||
|
||||
|
||||
"""
|
||||
class DCM(RegisterBase):
|
||||
def doWrite(self, value):
|
||||
print "Putting " , value
|
||||
caput ("TESTIOC:TESTCALCOUT:Output", value)
|
||||
print "Waiting " , value
|
||||
cawait('TESTIOC:TESTCALCOUT:Output', value, timeout = 3600.0)
|
||||
print "Done "
|
||||
#if abs(value - self.read()) > IN_POSITION_BAND :
|
||||
# raise Exception("Cannot set mono")
|
||||
def doRead(self):
|
||||
global x
|
||||
x=x+1
|
||||
return caget ("TESTIOC:TESTCALCOUT:Input") + x
|
||||
|
||||
#return caget("SARUN03-UIND030:FELPHOTENE.VAL")
|
||||
|
||||
undulator = DCM()
|
||||
undulator.initialize()
|
||||
"""
|
||||
|
||||
"""
|
||||
class DCM(Readable, Writable):
|
||||
def write(self, value):
|
||||
print "Putting " , value
|
||||
caput ("TESTIOC:TESTCALCOUT:Output", value)
|
||||
print "Waiting " , value
|
||||
cawait('TESTIOC:TESTCALCOUT:Output', value, timeout = 3600.0)
|
||||
print "Done "
|
||||
#if abs(value - self.read()) > IN_POSITION_BAND :
|
||||
# raise Exception("Cannot set mono")
|
||||
def read(self):
|
||||
global x
|
||||
x=x+1
|
||||
return caget ("TESTIOC:TESTCALCOUT:Input") + x
|
||||
|
||||
#return caget("SARUN03-UIND030:FELPHOTENE.VAL")
|
||||
|
||||
undulator = DCM()
|
||||
"""
|
||||
|
||||
|
||||
class MySettlingCondition(SettlingCondition):
|
||||
def waitSettled(self):
|
||||
time.sleep(100)
|
||||
cawait('TESTIOC:TESTCALCOUT:Input', value, timeout = 3600.0)
|
||||
|
||||
|
||||
|
||||
#return caget("SARUN03-UIND030:FELPHOTENE.VAL")
|
||||
|
||||
undulator = ControlledVariable("undulator", "TESTIOC:TESTCALCOUT:Output", "TESTIOC:TESTSINUS:SinCalc")
|
||||
undulator.config.resolution = float('inf')
|
||||
undulator.initialize()
|
||||
undulator.setSettlingCondition(ChannelSettlingCondition("TESTIOC:TESTCALCOUT:Input", 0, None, 'i', None))
|
||||
|
||||
undulator.settlingCondition.latency = 100
|
||||
|
||||
|
||||
lscan(undulator, [iavg], 1.0100, 1.18, 0.005 , latency= 0.2, range="auto")
|
||||
|
||||
|
||||
16
script/test/averager.py
Executable file
16
script/test/averager.py
Executable file
@@ -0,0 +1,16 @@
|
||||
#diode = Channel("TESTIOC:TESTSINUS:SinCalc")
|
||||
|
||||
#diode = create_channel_device("TESTIOC:TESTSINUS:SinCalc")
|
||||
#diode.monitored = True
|
||||
#iavg = create_averager(diode, 3, interval = -1)
|
||||
|
||||
|
||||
|
||||
#iavg = create_averager("ca://TESTIOC:TESTSINUS:SinCalc", 3, interval = -1)
|
||||
iavg = create_averager("bs://Int8Scalar", 3, interval = 0.1)
|
||||
|
||||
|
||||
tscan (iavg, 10, 0.5)
|
||||
|
||||
|
||||
#$iavg.close()
|
||||
6
script/test/back.py
Executable file
6
script/test/back.py
Executable file
@@ -0,0 +1,6 @@
|
||||
import java.util.logging.Logger as Logger
|
||||
logger = Logger.getLogger("back")
|
||||
|
||||
logger.info("Started")
|
||||
|
||||
|
||||
6
script/test/calc.groovy
Executable file
6
script/test/calc.groovy
Executable file
@@ -0,0 +1,6 @@
|
||||
|
||||
|
||||
def calc(a){
|
||||
a*2
|
||||
}
|
||||
|
||||
5
script/test/calc.js
Executable file
5
script/test/calc.js
Executable file
@@ -0,0 +1,5 @@
|
||||
|
||||
|
||||
function calc(a) {
|
||||
return a * 5;
|
||||
}
|
||||
3
script/test/calc.py
Executable file
3
script/test/calc.py
Executable file
@@ -0,0 +1,3 @@
|
||||
def calc(a):
|
||||
return a*4
|
||||
|
||||
7
script/test/cls.groovy
Executable file
7
script/test/cls.groovy
Executable file
@@ -0,0 +1,7 @@
|
||||
package script
|
||||
class cls {
|
||||
double val = 1.0
|
||||
void exec(){
|
||||
println "Exec"
|
||||
}
|
||||
}
|
||||
4
script/test/cls.py
Executable file
4
script/test/cls.py
Executable file
@@ -0,0 +1,4 @@
|
||||
class cls:
|
||||
def execute(self):
|
||||
print "Execute"
|
||||
|
||||
31
script/test/script.groovy
Executable file
31
script/test/script.groovy
Executable file
@@ -0,0 +1,31 @@
|
||||
|
||||
def function(a){
|
||||
a*2
|
||||
}
|
||||
//evaluate (new File("calc.groovy"))
|
||||
//evaluate (new File("cls.groovy"))
|
||||
|
||||
println "--------------"
|
||||
|
||||
lib.load "calc"
|
||||
cls = lib.load "cls"
|
||||
|
||||
|
||||
//This is how to load a new class dinamically
|
||||
// ClassLoader parent = lib.class.getClassLoader();
|
||||
// groovy.lang.GroovyClassLoader loader = new groovy.lang.GroovyClassLoader(parent);
|
||||
// Class cls = loader.parseClass(new File("script\\cls.groovy"));
|
||||
|
||||
|
||||
println dev.get()
|
||||
println dev2.val
|
||||
println calc(6)
|
||||
|
||||
|
||||
//cls = Class.forName('cls')
|
||||
//obj = new cls()
|
||||
obj = cls.newInstance()
|
||||
println obj.val
|
||||
obj.exec()
|
||||
|
||||
|
||||
13
script/test/script.js
Executable file
13
script/test/script.js
Executable file
@@ -0,0 +1,13 @@
|
||||
function calcx(a) {
|
||||
return a * 5;
|
||||
}
|
||||
|
||||
print('Hello, World')
|
||||
lib.load ("calc")
|
||||
|
||||
|
||||
a=3
|
||||
a
|
||||
print (dev.get())
|
||||
print (dev2.val)
|
||||
print (calc(5))
|
||||
53
script/test/startup.groovy
Executable file
53
script/test/startup.groovy
Executable file
@@ -0,0 +1,53 @@
|
||||
import ch.psi.pshell.scan.LineScan;
|
||||
import ch.psi.pshell.scan.AreaScan;
|
||||
|
||||
|
||||
def sleep(millis){
|
||||
Thread.sleep(millis);
|
||||
}
|
||||
|
||||
def toArray(obj){
|
||||
/* if (!obj.getClass().isArray()){
|
||||
arr = java.lang.reflect.Array.newInstance(obj.getClass(), 1);
|
||||
arr[0]= obj;
|
||||
obj=arr
|
||||
}*/
|
||||
return obj
|
||||
}
|
||||
|
||||
|
||||
def scan(writables, readables, start, end, steps, latency_ms=0, plot=null){
|
||||
writables=toList(writables)
|
||||
readables=toList(readables)
|
||||
start=toList(start)
|
||||
end=toList(end)
|
||||
scan = LineScan(writables,readables, start, end , steps,latency_ms, controller)
|
||||
scan.setPlotName(plot)
|
||||
scan.start()
|
||||
return scan.getResult()
|
||||
}
|
||||
|
||||
def tscan(readables, points, interval_ms, plot=null){
|
||||
writables=[]
|
||||
//readables=toList(readables)
|
||||
readables=[readables,]
|
||||
start=[0]
|
||||
|
||||
end=[points]
|
||||
steps=points
|
||||
scan = LineScan(writables,readables, start, end , steps,interval_ms, controller)
|
||||
scan.setPlotName(plot)
|
||||
scan.start()
|
||||
return scan.getResult()
|
||||
}
|
||||
|
||||
def ascan(writables, readables, start, end, steps, latency_ms0, plot=null){
|
||||
writables=toList(writables)
|
||||
readables=toList(readables)
|
||||
start=toList(start)
|
||||
end=toList(end)
|
||||
scan = AreaScan(writables,readables, start, end , steps,latency_ms, controller)
|
||||
scan.setPlotName(plot)
|
||||
scan.start()
|
||||
return scan.getResult()
|
||||
}
|
||||
2
script/test/swing.py
Executable file
2
script/test/swing.py
Executable file
@@ -0,0 +1,2 @@
|
||||
from javax.swing import *
|
||||
a=JPanel()
|
||||
2
script/test/test.py
Executable file
2
script/test/test.py
Executable file
@@ -0,0 +1,2 @@
|
||||
def test():
|
||||
print dev.read()
|
||||
Reference in New Issue
Block a user