Commit b3ab0be4 authored by Cyril Guilloud's avatar Cyril Guilloud

FlexDC improved

*in config : added : step_sizem, acc/dec-celeration smoothing velocity target_params
*use add_axis_method
*read_state() done
*end of motion  EM status
*VR flavours added
*prepare_move() start_move() done
parent 22e63404
from bliss.controllers.motor import Controller
from bliss.controllers.motor import add_method
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
......@@ -13,8 +13,15 @@ from bliss.comm import tcp
"""
Bliss controller for ethernet FlexDC piezo-motor controller.
Cyril Guilloud ESRF BLISS January 2014
NOT DONE :
*Dead band
"""
class FlexDC(Controller):
def __init__(self, name, config, axes):
Controller.__init__(self, name, config, axes)
......@@ -30,9 +37,22 @@ class FlexDC(Controller):
# Init of each axis.
def initialize_axis(self, axis):
axis.channel = axis.config.get("channel")
print "FLEXDC initialize_axis"
add_method(axis, "get_id", functools.partial(self._get_id, axis.channel))
axis.channel = axis.config.get("channel")
axis.target_radius = axis.config.get("target_radius", int)
axis.target_time = axis.config.get("target_time", int)
axis.smoothing = axis.config.get("smoothing", int)
axis.acceleration = axis.config.get("acceleration", int)
axis.deceleration = axis.config.get("deceleration", int)
axis.velocity = axis.config.get("velocity", int)
add_axis_method(axis, self.get_id)
add_axis_method(axis, self.get_info)
# Enabling servo mode.
self._flexdc_query("%sMO=1"%axis.channel)
# Sets "point to point" motion mode.
# 0 -> point to point
......@@ -40,14 +60,19 @@ class FlexDC(Controller):
# ( 5 -> position based ECAM ; 8 -> Step command (no profile) )
print self._flexdc_query("%sMM=0"%axis.channel)
# Special motion mode attribute parameter
# 0 -> no special mode
# ( 1 -> repetitive motion )
print self._flexdc_query("%sSM=0"%axis.channel)
# Defines smoothing 4.
print self._flexdc_query("%sWW=4"%axis.channel)
# Defines smoothing (typically 4).
self._flexdc_query("%sWW=%d"%(axis.channel, axis.smoothing))
# Target Time (settling time?)
self.flexdc_parameter(axis, "TT", axis.target_time)
# Target Radius (target window ?)
self.flexdc_parameter(axis, "TR", axis.target_radius)
# Checks if closed loop parameters have been set.
_ans = self._flexdc_query("%sTT"%axis.channel)
......@@ -58,11 +83,34 @@ class FlexDC(Controller):
if _ans == "0":
print "Missing closed loop param TR (Target Radius)!!"
# Acceleration
self._flexdc_query("%sAC=%d"%(axis.channel, axis.acceleration))
# Deceleration
self._flexdc_query("%sAD=%d"%(axis.channel, axis.deceleration))
# Velocity
self._flexdc_query("%sSP=%d"%(axis.channel, axis.velocity))
def read_position(self, axis, measured=False):
# position in steps
_pos = self._flexdc_query("%sDP"%axis.channel)
return _pos
def position(self, axis, new_position=None, measured=False):
if new_position:
pass
else:
if measured:
# position in steps
# PS : sensor position
_pos = int(self._flexdc_query("%sPS"%axis.channel))
print "FLEXDC measured position :", _pos
return _pos
else:
# position in steps
# DP : desired position
# When an axis is in motion, DP holds the real time servo
# loop control reference position
_pos = int(self._flexdc_query("%sDP"%axis.channel))
print "FLEXDC setpoint position :", _pos
return _pos
def velocity(self, axis, new_velocity=None):
......@@ -75,28 +123,38 @@ class FlexDC(Controller):
def read_state(self, axis):
ret = 0
_ret = 0
sta = 0
_ansMS = self._flexdc_query("%sMS"%axis.channel)
if(sta & (1<<0)):
ret |= 0x02
# Motion Status : MS command
# bit 0 : 0x01 : In motion.
# bit 1 : 0x02 : In stop.
# bit 2 : 0x04 : In acceleration.
# bit 3 : 0x08 : In deceleration.
# bit 4 : 0x10 : Waiting for input to start motion.
# bit 5 : 0x20 : In PTP stop (decelerating to target).
# bit 6 : 0x40 : Waiting for end of WT period.
_ansMS = int(self._flexdc_query("%sMS"%axis.channel))
if(_ansMS & 0x01):
_ret = MOVING
else:
_ret = READY
# return MOVING
print "SSSSSSSSSSSTTTTTTTTEEEEEEEEEE"
return READY
print "FLEXDC read_state :", _ret
return _ret
def prepare_move(self, axis, target_pos, delta):
pass
print "FLEXDC prepare_move, target_pos=", target_pos
self._flexdc_query("%sAP=%d"%(axis.channel, int(target_pos)))
def start_move(self, axis, target_pos, delta):
pass
print "FLEXDC start_move, target_pos=", target_pos
self._flexdc_query("%sBG"%axis.channel)
def stop(self, axis):
print "FLEXDC stop"
_ans = self._flexdc_query("%sST"%axis.channel)
......@@ -117,19 +175,84 @@ class FlexDC(Controller):
print "missing ack character ???"
return _ans
def _get_id(self, channel):
_cmd = "%sVR"%channel
def get_id(self, axis):
_cmd = "%sVR"%axis.channel
return self._flexdc_query(_cmd)
'''
SET / GET parameter
'''
def flexdc_parameter(self, axis, param, value=None):
if value:
_cmd = "%s%s=%d"%(axis.channel, param, value)
self._flexdc_query(_cmd)
return(value)
else:
_cmd = "%s%s"%(axis.channel, param)
return self._flexdc_query(_cmd)
'''
Homing command
'''
def flexdc_home(self, axis):
_cmd = "%sQE,#HINX_X"%axis.channel
self._flexdc_query(_cmd)
'''
In Traget : Status register bit 6
'''
def flexdc_in_target(self, axis):
_cmd = "%sSR"%axis.channel
_ans = int(self._flexdc_query(_cmd))
# Returns True if bit 6 of status register is set.
if _ans & 32 :
return True
else:
return False
'''
EM : End of motion status.
Returns a 2-uple of strings (EM CODE, Description).
'''
def flexdc_em(self, axis):
_cmd = "%sEM"%axis.channel
_ans = int(self._flexdc_query(_cmd))
_reasons = [
("EM_IN_MOTION" , "In motion, or After Boot up."),
("EM_NORMAL" , "Last Motion ended Normally."),
("EM_FLS" , "Last Motion ended due to Hardware FLS."),
("EM_RLS" , "Last Motion ended due to Hardware RLS."),
("EM_HL" , "Last Motion ended due to Software HL."),
("EM_LL" , "Last Motion ended due to Software LL."),
("EM_MF" , "Last Motion ended due to Motor Fault (check MF)."),
("EM_USER_STOP" , "Last Motion ended due to User Stop (ST or AB)."),
("EM_MOTOR_OFF" , "Last Motion ended due to Motor OFF (MO=0)."),
("EM_BAD_PROFILE_PARAM" , "Last Motion ended due to Bad ECAM Parameters.")
]
return _reasons[_ans]
'''
Returns information about controller.
Can be helpful to tune the device.
'''
def _get_infos(self, channel):
def get_info(self, axis):
# list of commands and descriptions
_infos = [
("VR,0", "VR,0"),
("VR,1", "VR,1"),
("VR,2", "VR,2"),
("VR,3", "VR,3"),
("VR,4", "VR,4"),
("VR,5", "VR,5"),
("VR,6", "VR,6"),
("AC", "Acceleration"),
("AD", "Analog Input Dead Band"),
("AF", "Analog Input Gain Factor"),
......@@ -178,8 +301,11 @@ class FlexDC(Controller):
_txt = ""
for i in _infos:
_cmd = "%s%s"%(channel, i[0])
_cmd = "%s%s"%(axis.channel, i[0])
_txt = _txt + "%35s %8s = %s \n"%(i[1], i[0], self._flexdc_query(_cmd))
(_emc, _emstr) = self.flexdc_em(axis)
_txt = _txt + "%35s %8s = %s \n"%( _emstr, "EM", _emc)
return _txt
......@@ -11,7 +11,14 @@ config_xml = """
<controller class="FlexDC" name="id16phn">
<host value="flexdcnina"/>
<axis name="fd">
<channel value="X"/>
<channel value="X"/>
<step_size value="2000"/>
<target_radius value="20"/>
<target_time value="10"/>
<smoothing value="4"/>
<acceleration value="1000"/>
<deceleration value="1000"/>
<velocity value="1000"/>
</axis>
</controller>
</config>
......@@ -35,34 +42,34 @@ class TestFlexDCController(unittest.TestCase):
fd = bliss.get_axis("fd")
print "FlexDC state :", fd.state()
# def test_get_position(self):
# fd = bliss.get_axis("fd")
# print "FlexDC position :", fd.position()
def test_position(self):
fd = bliss.get_axis("fd")
print "FlexDC position :", fd.position()
def test_get_id(self):
fd = bliss.get_axis("fd")
print "FlexDC ID :", fd.controller._get_id(fd.channel)
print "FlexDC ID :", fd.get_id()
def test_velocity(self):
fd = bliss.get_axis("fd")
print "FlexDC valocity :", fd.velocity()
def test_get_infos(self):
def test_get_info(self):
fd = bliss.get_axis("fd")
print "FlexDC INFOS :\n", fd.controller._get_infos(fd.channel)
print "FlexDC INFOS :\n", fd.get_info()
# # called at end of each test
# def tearDown(self):
# self.fd.controller.sock.close()
# called at end of each test
def tearDown(self):
fd = bliss.get_axis("fd")
fd.controller.sock.close()
# def test_axis_move(self):
# fd = bliss.get_axis("fd")
# self.assertEqual(fd.state(), "READY")
# move_greenlet=fd.move(10, wait=False)
# self.assertEqual(fd.state(), "MOVING")
# move_greenlet.join()
# self.assertEqual(fd.state(), "READY")
# def test_axis_move(self):
# fd = bliss.get_axis("fd")
# self.assertEqual(fd.state(), "READY")
# move_greenlet=fd.move(10, wait=False)
# self.assertEqual(fd.state(), "MOVING")
# move_greenlet.join()
# self.assertEqual(fd.state(), "READY")
if __name__ == '__main__':
unittest.main()
......@@ -76,16 +83,25 @@ load_cfg_fromstring("""<config>
<controller class="FlexDC" name="id16phn">
<host value="flexdcnina"/>
<axis name="fd">
<channel value="X"/>
<channel value="X"/>
<step_size value="13111"/>
<target_radius value="20"/>
<target_time value="10"/>
<smoothing value="4"/>
<acceleration value="1000"/>
<deceleration value="1000"/>
<velocity value="1000"/>
</axis>
</controller>
</config>
""")
"""); a=get_axis("fd") ; print a.state()
a=get_axis("fd")
print a.get_id()
print a.controller._flexdc_get_id()
print a.get_info()
print a.controller
# print a.controller.sock.write_readline("\n")
......
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