Commit af24f9a9 authored by blissadm's avatar blissadm

bla

parent 58195c94
from bliss.controllers.motor import Controller
from bliss.controllers.motor import add_axis_method
from bliss.common.axis import READY, MOVING
from bliss.common.task_utils import task, error_cleanup, cleanup
import functools
import random
import math
import time
......@@ -31,7 +33,12 @@ class PI_E517(Controller):
# Init of each axis.
def initialize_axis(self, axis):
# Enables the closed-loop.
self.sock.write("SVO 1 1\n")
# self.sock.write("SVO 1 1\n")
axis.channel = axis.config.get("channel")
axis.chan_letter = axis.config.get("chan_letter")
add_axis_method(axis, self.get_id)
def position(self, axis, new_position=None, measured=False):
if new_position is not None:
......@@ -49,8 +56,8 @@ class PI_E517(Controller):
if new_velocity is not None:
pass
return self.axis_settings.get(axis, "velocity")
#return self.axis_settings.get(axis, "velocity")
return 1
def state(self, axis):
if self._get_closed_loop_status():
......@@ -79,120 +86,121 @@ class PI_E517(Controller):
E517 specific communication
"""
def _send(self, axis, cmd):
def send(self, axis, cmd):
_chan = axis.channel
_cmd = cmd + "\n"
print "Send %s to %s"%(cmd, _chan)
_ans = self.sock.write_readline()
_ans = self.sock.write_readline(_cmd)
return _ans
def _send_no_ans(self, axis, cmd):
def send_no_ans(self, axis, cmd):
_chan = axis.channel
_cmd = cmd + "\n"
print "Send %s to %s"%(cmd, _chan)
self.sock.write(_cmd)
def _get_pos(self):
def _get_pos(self, axis):
'''
Returns real position read by capcitive captor.
'''
_ans = self.sock.write_readline("POS?\n")
_ans = self.send("POS? %s"%axis.chan_letter)
# _ans should looks like "1=-8.45709419e+01\n"
# "\n" removed by tcp lib.
_pos = float(_ans[2:])
print "position POS:", _ans
return _pos
def _get_target_pos(self):
'''
Returns last target position (setpoint value).
'''
_ans = self.sock.write_readline("MOV?\n")
# _ans should looks like "1=-8.45709419e+01\n"
# _ans should looks like ""
# "\n" removed by tcp lib.
_pos = float(_ans[2:])
# _pos = float(_ans[2:])
return _pos
def _get_identifier(self):
return self.sock.write_readline("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)
'''
Returns a set of usefull information about controller.
Can be helpful to tune the device.
'''
def _get_infos(self):
_infos = [
("Identifier ", "IDN?\n"),
("Com level ", "CCL?\n"),
("Real Position ", "POS?\n"),
("Setpoint Position ", "MOV?\n"),
("Position low limit ", "SPA? 1 0x07000000\n"),
("Position High limit ", "SPA? 1 0x07000001\n"),
("Velocity ", "VEL?\n"),
("On target ", "ONT?\n"),
("Target tolerance ", "SPA? 1 0X07000900\n"),
("Settling time ", "SPA? 1 0X07000901\n"),
("Sensor Offset ", "SPA? 1 0x02000200\n"),
("Sensor Gain ", "SPA? 1 0x02000300\n"),
("Motion status ", "#5\n"),
("Closed loop status ", "SVO?\n"),
("Auto Zero Calibration ? ", "ATZ?\n"),
("Analog input setpoint ", "AOS?\n"),
("Low Voltage Limit ", "SPA? 1 0x07000A00\n"),
("High Voltage Limit ", "SPA? 1 0x07000A01\n")
]
_txt = ""
for i in _infos:
_txt = _txt + " %s %s\n"%(i[0],
self.sock.write_readline(i[1]))
_txt = _txt + " %s \n%s\n"%("Communication parameters",
"\n".join(self.sock.write_readlines("IFC?\n", 5)))
_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
# def _get_target_pos(self):
# '''
# Returns last target position (setpoint value).
# '''
# _ans = self.sock.write_readline("MOV?\n")
#
# # _ans should looks like "1=-8.45709419e+01\n"
# # "\n" removed by tcp lib.
# _pos = float(_ans[2:])
#
# return _pos
#
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)
#
# '''
# Returns a set of usefull information about controller.
# Can be helpful to tune the device.
# '''
# def _get_infos(self):
# _infos = [
# ("Identifier ", "IDN?\n"),
# ("Com level ", "CCL?\n"),
# ("Real Position ", "POS?\n"),
# ("Setpoint Position ", "MOV?\n"),
# ("Position low limit ", "SPA? 1 0x07000000\n"),
# ("Position High limit ", "SPA? 1 0x07000001\n"),
# ("Velocity ", "VEL?\n"),
# ("On target ", "ONT?\n"),
# ("Target tolerance ", "SPA? 1 0X07000900\n"),
# ("Settling time ", "SPA? 1 0X07000901\n"),
# ("Sensor Offset ", "SPA? 1 0x02000200\n"),
# ("Sensor Gain ", "SPA? 1 0x02000300\n"),
# ("Motion status ", "#5\n"),
# ("Closed loop status ", "SVO?\n"),
# ("Auto Zero Calibration ? ", "ATZ?\n"),
# ("Analog input setpoint ", "AOS?\n"),
# ("Low Voltage Limit ", "SPA? 1 0x07000A00\n"),
# ("High Voltage Limit ", "SPA? 1 0x07000A01\n")
# ]
#
# _txt = ""
#
# for i in _infos:
# _txt = _txt + " %s %s\n"%(i[0],
# self.sock.write_readline(i[1]))
#
# _txt = _txt + " %s \n%s\n"%("Communication parameters",
# "\n".join(self.sock.write_readlines("IFC?\n", 5)))
#
# _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
#
......@@ -41,25 +41,27 @@ class TestPI_E517Controller(unittest.TestCase):
def setUp(self):
bliss.load_cfg_fromstring(config_xml)
def test_get_axis(self):
pz = bliss.get_axis("pz")
self.assertTrue(pz)
def test_controller_from_axis(self):
pz = bliss.get_axis("pz")
self.assertEqual(pz.controller.name, "testid16")
def test_get_position(self):
pz = bliss.get_axis("pz")
print "E517 position :", pz.position()
def test_get_id(self):
pz = bliss.get_axis("pz")
print "E517 IDN :", pz.controller._get_identifier()
print "E517 IDN :", pz.get_id()
def test_get_infos(self):
pz = bliss.get_axis("pz")
print "E517 INFOS :\n", pz.controller._get_infos()
# def test_get_axis(self):
# pz = bliss.get_axis("pz")
# self.assertTrue(pz)
#
# def test_controller_from_axis(self):
# pz = bliss.get_axis("pz")
# self.assertEqual(pz.controller.name, "testid16")
#
# def test_get_position(self):
# pz = bliss.get_axis("pz")
# print "E517 position :", pz.position()
#
#
# def test_get_infos(self):
# pz = bliss.get_axis("pz")
# print "E517 INFOS :\n", pz.controller._get_infos()
# # called at end of each test
# def tearDown(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment