Commit 83550788 authored by blissadm's avatar blissadm

merged.

parent 1dcdc66c
......@@ -33,7 +33,7 @@ class FlexDC(Controller):
# Init of controller.
def initialize(self):
# print "FLEXDC CONTROLLER initialize"
self.sock = tcp.Command(self.host, 4000)
self.sock = tcp.Socket(self.host, 4000)
def finalize(self):
# print "FLEXDC CONTROLLER finalize"
......@@ -55,6 +55,7 @@ class FlexDC(Controller):
add_axis_method(axis, self.get_id)
add_axis_method(axis, self.get_info)
add_axis_method(axis, self.acceleration)
add_axis_method(axis, self.steps_per_unit)
# Enabling servo mode.
self._flexdc_query("%sMO=1"%axis.channel)
......@@ -106,7 +107,7 @@ class FlexDC(Controller):
PS : Position from Sensor
'''
_pos = int(self._flexdc_query("%sPS"%axis.channel))
print "FLEXDC measured position :", _pos
print "FLEXDC *measured* position (in steps) :", _pos
return _pos
else:
''' position in steps
......@@ -115,7 +116,7 @@ class FlexDC(Controller):
loop control reference position
'''
_pos = int(self._flexdc_query("%sDP"%axis.channel))
print "FLEXDC setpoint position : %g"%(_pos)
print "FLEXDC *setpoint* position (in steps) : %g"%(_pos)
return _pos
......@@ -185,6 +186,13 @@ class FlexDC(Controller):
return axis.settings.get("acceleration")
def steps_per_unit(self, axis, new_step_per_unit=None):
if new_step_per_unit is None:
return float(axis.config.get("step_size"))
else:
print "steps_per_unit writing is not (yet?) implemented."
#
def _flexdc_query(self, cmd):
# Adds "\r" at end of command.
......
......@@ -24,12 +24,11 @@ class PI_E517(Controller):
# Init of controller.
def initialize(self):
self.sock = tcp.Command(self.host, 50000)
self.sock = tcp.Socket(self.host, 50000)
def finalize(self):
self.sock.close()
# Init of each axis.
def initialize_axis(self, axis):
# ONL ?
......@@ -42,59 +41,82 @@ class PI_E517(Controller):
add_axis_method(axis, self.get_id)
add_axis_method(axis, self.get_infos)
add_axis_method(axis, self.steps_per_unit)
def position(self, axis, new_position=None, measured=False):
if new_position is None:
if measured:
_ans = self._get_pos(axis)
_pos = self._get_pos(axis)
print "PI_E517 position measured read : ", _pos
else:
_ans = self._get_target_pos(axis)
return _ans
_pos = self._get_target_pos(axis)
print "PI_E517 position setpoint read : ", _pos
return _pos
def velocity(self, axis, new_velocity=None):
if new_velocity is not None:
pass
print "PI-E517 velocity()"
if new_velocity is None:
_velocity = self._get_velocity(axis)
print "PI_E517 velocity read : ", _velocity
else:
self.send_no_ans(axis, "VEL %s %f"%(axis.chan_letter, new_velocity))
print "PI_E517 velocity wrotten : ", new_velocity
_velocity = new_velocity
#return self.axis_settings.get(axis, "velocity")
return 1
return _velocity
def state(self, axis):
if self._get_closed_loop_status():
if self._get_on_target_status():
if self._get_closed_loop_status(axis):
print "CL is active"
if self._get_on_target_status(axis):
return READY
else:
return MOVING
else:
raise RuntimeError("closed loop disabled")
print "CL is not active"
pass
#raise RuntimeError("closed loop disabled")
def prepare_move(self, motion):
self._target_pos = motion.target_pos
pass
def start_one(self, motion): #axis, target_pos, delta):
self.sock.write("MOV 1 %g\n"%self._target_pos)
def start_one(self, motion):
# NB : must be in closed loop
self.send_no_ans(motion.axis, "MOV %s %g"%(motion.axis.chan_letter, motion.target_pos))
def stop(self, axis):
# HLT -> stop smoothly
# STP -> stop asap
# 24 -> stop asap
# to check : copy of current position into target position ???
self.sock.write("STP\n")
self.send_no_ans(axis, "HLT %s"%axis.chan_letter)
"""
E517 specific communication
"""
def steps_per_unit(self, axis, new_step_per_unit=None):
if new_step_per_unit is None:
return float(axis.config.get("step_size"))
else:
print "steps_per_unit writing is not (yet?) implemented."
# adds the terminator cheracter.
def send(self, axis, cmd):
_chan = axis.channel
_cmd = cmd + "\n"
print "Sends %s to %s"%(repr(_cmd), _chan)
# print "Sends %s to %s"%(repr(_cmd), _chan)
_ans = self.sock.write_readline(_cmd)
print "Received %s from %s"%(repr(_ans), _chan)
# print "Received %s from %s"%(repr(_ans), _chan)
return _ans
......@@ -107,15 +129,26 @@ class PI_E517(Controller):
self.sock.write(_cmd)
def _get_velocity(self, axis):
'''
Returns velocity taken from controller.
'''
_ans = self.send(axis, "VEL? %s"%axis.chan_letter)
# _ans should looks like "A=+0012.0000"
# "\n" removed by tcp lib.
# removes 'X=' prefix
_velocity = float(_ans[2:])
return _velocity
def _get_pos(self, axis):
'''
Returns real position read by capcitive captor.
'''
_ans = self.send(axis, "POS? %s"%axis.chan_letter)
# _ans should looks like ""
# "\n" removed by tcp lib.
# _pos = float(_ans[2:])
_pos = float(_ans[2:])
return _pos
......@@ -124,49 +157,57 @@ class PI_E517(Controller):
Returns last target position (setpoint value).
'''
_ans = self.send(axis, "MOV? %s"%axis.chan_letter)
# _ans should looks like 'C=+0001.2345'
# "\n" removed by tcp lib.
# removes 'X=' prefix
_pos = float(_ans[2:])
return _pos
def _get_voltage(self, axis):
'''
Returns Voltage Of Output Signal Channel
'''
_ans = self.send(axis, "VOL? %s"%axis.channel)
_vol = float(_ans[2:])
return _vol
def _get_closed_loop_status(self, axis):
'''
Returns Closed loop status (Servo state)
-> True/False
'''
_ans = self.send(axis, "VOL? %s"%axis.channel)
_status = float(_ans[2:])
if _status == 1:
return True
else:
return False
def _get_on_target_status(self, axis):
'''
Returns On Target status
True/False
'''
_ans = self.send(axis, "ONT? %s"%axis.chan_letter)
_status = float(_ans[2:])
if _status == 1:
return True
else:
return False
def get_id(self, axis):
return self.send(axis, "IDN?\n")
# def _get_closed_loop_status(self):
# _ans = self.sock.write_readline("SVO?\n")
#
# if _ans == "1=1":
# return True
# elif _ans == "1=0":
# return False
# else:
# return -1
#
# def _get_on_target_status(self):
# _ans = self.sock.write_readline("ONT?\n")
#
# if _ans =="":
# return True
# elif _ans =="":
# return False
# else:
# return -1
#
# def _get_error(self):
# _error_number = self.sock.write_readline("ERR?\n")
# _error_str = pi_gcs.get_error_str(_error_number)
#
# return (_error_number, _error_str)
#
# def _stop(self):
# self.sock.write("STP\n")
#
# def _set_velocity(self, velocity):
# self.sock.write("VEL 1 %f\n"%velocity)
return self.send(axis, "*IDN?\n")
def _get_error(self, axis):
_error_number = self.send("ERR?\n")
_error_str = pi_gcs.get_error_str(_error_number)
return (_error_number, _error_str)
def _stop(self):
self.sock.write("STP\n")
'''
Returns a set of usefull information about controller.
......@@ -183,35 +224,19 @@ class PI_E517(Controller):
("Position low limit ", "NLM? %s"%axis.chan_letter),
("Position high limit ", "PLM? %s"%axis.chan_letter),
("Closed loop status ", "SVO? %s"%axis.chan_letter),
("Voltage output high limit ", "VMA? %s"%axis.chan_letter),
("Voltage output low limit ", "VMI? %s"%axis.chan_letter),
("Voltage output high limit ", "VMA? %s"%axis.channel),
("Voltage output low limit ", "VMI? %s"%axis.channel),
("Output Voltage ", "VOL? %s"%axis.channel),
("Setpoint Position ", "MOV? %s"%axis.chan_letter),
("Drift compensation Offset ", "DCO? %s"%axis.chan_letter),
("Online ", "ONL? %s"%axis.chan_letter),
("Online ", "ONL? %s"%axis.channel),
("On target ", "ONT? %s"%axis.chan_letter),
("ADC Value of input signal ", "TAD? %s"%axis.chan_letter),
("ADC Value of input signal ", "TAD? %s"%axis.channel),
("Input Signal Position value", "TSP? %s"%axis.channel),
("Velocity control mode ", "VCO? %s"%axis.chan_letter),
("Velocity ", "VEL? %s"%axis.chan_letter),
("Osensor ", "SPA? %s 0x02000200"%axis.channel),
("Ksensor ", "SPA? %s 0x02000300"%axis.channel),
# (" ", "? %s"%axis.chan_letter),
# ("Setpoint Position ", "MOV?"),
# ("Position low limit ", "SPA? 1 0x07000000"),
# ("Position High limit ", "SPA? 1 0x07000001"),
# ("Velocity ", "VEL?"),
# ("On target ", "ONT?"),
# ("Target tolerance ", "SPA? 1 0X07000900"),
# ("Settling time ", "SPA? 1 0X07000901"),
# ("Sensor Offset ", "SPA? 1 0x02000200"),
# ("Sensor Gain ", "SPA? 1 0x02000300"),
# ("Motion status ", "#5"),
# ("Auto Zero Calibration ? ", "ATZ?"),
# ("Analog input setpoint ", "AOS?"),
# ("Low Voltage Limit ", "SPA? 1 0x07000A00"),
# ("High Voltage Limit ", "SPA? 1 0x07000A01")
]
_txt = ""
......@@ -227,10 +252,5 @@ class PI_E517(Controller):
"\n".join(self.sock.write_readlines("VER?\n", 3)))
# _txt = _txt + " %s \n%s\n"%("Analog setpoints",
# "\n".join(self.sock.write_readlines("TSP?\n", 2)))
# _txt = _txt + " %s \n%s\n"%("ADC value of analog input",
# "\n".join(self.sock.write_readlines("TAD?\n", 2)))
return _txt
......@@ -23,7 +23,7 @@ class PI_E753(Controller):
# Init of controller.
def initialize(self):
self.sock = tcp.Command(self.host, 50000)
self.sock = tcp.Socket(self.host, 50000)
def finalize(self):
self.sock.close()
......@@ -31,9 +31,13 @@ class PI_E753(Controller):
# Init of each axis.
def initialize_axis(self, axis):
add_axis_method(axis, self.steps_per_unit)
# Enables the closed-loop.
self.sock.write("SVO 1 1\n")
def position(self, axis, new_position=None, measured=False):
if new_position is not None:
pass
......@@ -80,6 +84,12 @@ class PI_E753(Controller):
E753 specific communication
"""
def steps_per_unit(self, axis, new_step_per_unit=None):
if new_step_per_unit is None:
return float(axis.config.get("step_size"))
else:
print "steps_per_unit writing is not (yet?) implemented."
def _get_pos(self):
'''
Returns real position read by capcitive captor.
......
......@@ -100,12 +100,16 @@ class BlissAxis(PyTango.Device_4Impl):
if not self.once:
try:
# Initialises "set" value of attributes.
# Position
attr = self.get_device_attr().get_attr_by_name("Position")
attr.set_write_value(self.axis.position())
# Velocity
attr = self.get_device_attr().get_attr_by_name("Velocity")
attr.set_write_value(float(self.axis.velocity()))
# Acceleration
try:
_acc = self.axis.acceleration()
attr = self.get_device_attr().get_attr_by_name("Acceleration")
......@@ -113,6 +117,24 @@ class BlissAxis(PyTango.Device_4Impl):
except:
print "No acceleration for axis %s"%self._axis_name
# Steps_per_unit
try:
_spu = float(self.axis.steps_per_unit())
attr = self.get_device_attr().get_attr_by_name("Steps_per_unit")
attr.set_write_value(_spu)
except:
print "No Step per unit method for axis %s"%self._axis_name
# Steps
try:
_steps = int(round(self.axis.position() * _spu))
attr = self.get_device_attr().get_attr_by_name("Steps")
attr.set_write_value(_steps)
except:
print "No Steps per unit method ? for axis %s"%self._axis_name
except:
print "ERROR : Cannot set one of attributs write value."
print traceback.format_exc()
......@@ -150,20 +172,23 @@ class BlissAxis(PyTango.Device_4Impl):
def read_Steps_per_unit(self, attr):
self.debug_stream("In read_Steps_per_unit()")
attr.set_value(self.attr_Steps_per_unit_read)
attr.set_value(self.axis.steps_per_unit())
def write_Steps_per_unit(self, attr):
self.debug_stream("In write_Steps_per_unit()")
data=attr.get_write_value()
print "not implemented"
def read_Steps(self, attr):
self.debug_stream("In read_Steps()")
attr.set_value(self.attr_Steps_read)
_spu = float(self.axis.steps_per_unit())
_steps = _spu * self.axis.position()
attr.set_value(int(round(_steps)))
def write_Steps(self, attr):
self.debug_stream("In write_Steps()")
data=attr.get_write_value()
# def write_Steps(self, attr):
# self.debug_stream("In write_Steps()")
# data=attr.get_write_value()
def read_Position(self, attr):
......@@ -195,7 +220,7 @@ class BlissAxis(PyTango.Device_4Impl):
self.debug_stream("In read_Acceleration(%f)"%float(_acc))
attr.set_value(_acc)
except:
print "unable to read Acceleration"
print "unable to read Acceleration for this axis"
traceback.print_exc()
raise
......@@ -206,7 +231,7 @@ class BlissAxis(PyTango.Device_4Impl):
self.debug_stream("In write_Acceleration(%f)"%data)
self.axis.acceleration(data)
except:
print "unable to write Acceleration"
print "unable to write Acceleration for this axis"
traceback.print_exc()
raise
......@@ -292,11 +317,11 @@ class BlissAxis(PyTango.Device_4Impl):
def read_StepSize(self, attr):
self.debug_stream("In read_StepSize()")
attr.set_value(self.attr_StepSize_read)
attr.set_value(self.axis.step_size())
def write_StepSize(self, attr):
self.debug_stream("In write_StepSize()")
data=attr.get_write_value()
# def write_StepSize(self, attr):
# self.debug_stream("In write_StepSize()")
# print "cannot set step_size"
def read_attr_hardware(self, data):
......@@ -401,33 +426,35 @@ class BlissAxisClass(PyTango.DeviceClass):
'Steps_per_unit':
[[PyTango.DevDouble,
PyTango.SCALAR,
PyTango.READ_WRITE],
#PyTango.READ_WRITE],
PyTango.READ],
{
'label': "Steps per mm",
'unit': "steps/mm",
'format': "%7.1f",
'Display level': PyTango.DispLevel.EXPERT,
'Memorized':"true"
#'Memorized':"true"
} ],
'Steps':
[[PyTango.DevLong,
PyTango.SCALAR,
PyTango.READ_WRITE],
#PyTango.READ_WRITE],
PyTango.READ],
{
'label': "Steps",
'unit': "steps",
'format': "%6d",
'description': "number of steps in the step counter\n",
'Memorized':"true"
#'Memorized':"true"
} ],
'Position':
[[PyTango.DevDouble,
PyTango.SCALAR,
PyTango.READ_WRITE],
{
'label': "position",
'label': "Position",
'unit': "mm",
'format': "%7.3f",
'format': "%10.3f",
'description': "The desired motor position.",
} ],
'Measured_Position':
......@@ -435,9 +462,9 @@ class BlissAxisClass(PyTango.DeviceClass):
PyTango.SCALAR,
PyTango.READ],
{
'label': "position",
'label': "Measured position",
'unit': "mm",
'format': "%7.3f",
'format': "%10.3f",
'description': "The measured motor position.",
} ],
'Acceleration':
......@@ -547,13 +574,12 @@ class BlissAxisClass(PyTango.DeviceClass):
'StepSize':
[[PyTango.DevDouble,
PyTango.SCALAR,
PyTango.READ_WRITE],
PyTango.READ],
{
'unit': "mm",
'format': "%10.3f",
'description': "Size of the relative step performed by the StepUp and StepDown commands.\nThe StepSize is expressed in physical unit.",
'Display level': PyTango.DispLevel.EXPERT,
'Memorized':"true"
} ],
}
......
......@@ -12,5 +12,26 @@
<velocity value="1234"/>
</axis>
</controller>
<controller class="PI_E517" name="testid16">
<host value="e517pela"/>
<axis name="px">
<channel value="1"/>
<chan_letter value="A"/>
<velocity value="12"/>
<step_size value="1"/>
</axis>
<axis name="py">
<channel value="2"/>
<chan_letter value="B"/>
<velocity value="12"/>
<step_size value="1"/>
</axis>
<axis name="pz">
<channel value="3"/>
<chan_letter value="C"/>
<velocity value="12"/>
<step_size value="1"/>
</axis>
</controller>
</config>
import unittest
import sys
import os
import time
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
......@@ -13,23 +14,17 @@ config_xml = """
<axis name="px">
<channel value="1"/>
<chan_letter value="A"/>
<acceleration value="123"/>
<deceleration value="321"/>
<velocity value="432"/>
<velocity value="12"/>
</axis>
<axis name="py">
<channel value="2"/>
<chan_letter value="B"/>
<acceleration value="123"/>
<deceleration value="321"/>
<velocity value="432"/>
<velocity value="12"/>
</axis>
<axis name="pz">
<channel value="3"/>
<chan_letter value="C"/>
<acceleration value="123"/>
<deceleration value="321"/>
<velocity value="432"/>
<velocity value="12"/>
</axis>
</controller>
</config>
......@@ -53,14 +48,31 @@ class TestPI_E517Controller(unittest.TestCase):
pz = bliss.get_axis("pz")
self.assertTrue(pz)
def test_get_state(self):
pz = bliss.get_axis("pz")
print "E517 pz state:", pz.state()
def test_get_infos(self):
pz = bliss.get_axis("pz")
print "E517 INFOS :\n", pz.get_infos()
def test_get_voltage(self):
pz = bliss.get_axis("pz")
print "E517 pz output voltage :", pz.controller._get_voltage(pz)
def test_get_closed_loop_status(self):
pz = bliss.get_axis("pz")
print "E517 pz closed loop enabled :", pz.controller._get_closed_loop_status(pz)
def test_get_on_target_status(self):
pz = bliss.get_axis("pz")
print "E517 pz on target :", pz.controller._get_on_target_status(pz)
# # called at end of each test
# def tearDown(self):
# self.pz.controller.sock.close()
# called at end of each test
def tearDown(self):
# Little wait time to let time to PI controller to
# close peacefully its sockets...
time.sleep(0.2)
# def test_axis_move(self):
# pz = bliss.get_axis("pz")
......@@ -83,21 +95,18 @@ load_cfg_fromstring("""
<host value="e517pela"/>
<axis name="px">
<channel value="1"/>
<acceleration value="123"/>
<deceleration value="321"/>
<velocity value="432"/>
<chan_letter value="A"/>
<velocity value="12"/>
</axis>
<axis name="py">
<channel value="2"/>
<acceleration value="123"/>