Test_VSCANNER.py 3.27 KB
Newer Older
1 2 3 4 5 6 7
# -*- coding: utf-8 -*-
#
# This file is part of the bliss project
#
# Copyright (c) 2016 Beamline Control Unit, ESRF
# Distributed under the GNU LGPLv3. See LICENSE for more info.

8 9 10 11 12 13 14 15
import unittest
import sys
import os
import time

sys.path.insert(
    0,
    os.path.abspath(
16 17 18
        os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir)
    ),
)
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

import bliss
from bliss.common import log as elog


# using 0-100 scale (ex microns of a piezo)
# velocity : 1.3 um / s
config_xml = """
<config>
  <controller class="VSCANNER" name="test_VSCAN_R">
    <serial_line value = "/dev/ttyS0" />
    <axis name="px">
      <velocity value="1.3" />
      <chan_letter value="X"/>
      <steps_per_unit value="0.1"/>
    </axis>
    <axis name="py">
      <velocity value="12" />
      <chan_letter value="Y"/>
      <steps_per_unit value="0.1"/>
    </axis>
  </controller>
</config>
"""

cyril@lid269's avatar
pep8  
cyril@lid269 committed
44

45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
class Test_VSCANNER_Controller(unittest.TestCase):

    # called for each test
    def setUp(self):
        # elog.level(10)
        bliss.load_cfg_fromstring(config_xml)

    def test_get_id(self):
        print "################### get_id ###############"
        px = bliss.get_axis("px")
        print "ID :", px.get_id()
        print "SPU: ", px.config.get("steps_per_unit")

    def test_get_id(self):
        print "################### get_velocity ###############"
        px = bliss.get_axis("px")
cyril@lid269's avatar
pep8  
cyril@lid269 committed
61
        _vel = px.velocity()
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
        print "px velocity: ", _vel

    def test_get_chan(self):
        print "################### get_chan ###############"
        px = bliss.get_axis("px")
        print "VSCANNER px chan_letter :", px.chan_letter
        py = bliss.get_axis("py")
        print "VSCANNER py chan_letter :", py.chan_letter

    def test_get_position(self):
        print "################### get_position ###############"
        px = bliss.get_axis("px")
        print "VSCANNER px position :", px.position()
        py = bliss.get_axis("py")
        print "VSCANNER py position :", py.position()

    def test_get_state(self):
        print "################### get_state ###############"
        px = bliss.get_axis("px")
        print "VSCANNER px state:", px.state()
        py = bliss.get_axis("py")
        print "VSCANNER py state:", py.state()

    def test_get_info(self):
        print "################### get_info ###############"
        px = bliss.get_axis("px")
        print "VSCANNER INFOS :\n", px.get_info()

    def test_move(self):
        print "################### move ###############"
        px = bliss.get_axis("px")
        _pos = px.position()
        print "VSCANNER px.position = %g" % _pos
cyril@lid269's avatar
pep8  
cyril@lid269 committed
95
        if _pos < 88:
96 97 98
            _new_pos = _pos + 11.11
        else:
            _new_pos = 0
cyril@lid269's avatar
pep8  
cyril@lid269 committed
99
        print "VSCANNER move to ", _new_pos
100 101 102
        px.move(_new_pos)
        print "VSCANNER new pos : ", px.position()

103 104

if __name__ == "__main__":
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
    unittest.main()


'''
Interactive test :

load_cfg_fromstring("""
<config>
  <controller class="VSCANNER" name="VS_POOL">
    <axis name="p1">
      <chan_letter value="X" />
      <velocity value="10" />
      <steps_per_unit value="1" />
    </axis>
    <axis name="p2">
      <chan_letter value="Y" />
      <velocity value="10" />
      <steps_per_unit value="1" />
    </axis>
  </controller>
</config>
cyril@lid269's avatar
pep8  
cyril@lid269 committed
126
""");
127 128 129 130 131

a=get_axis("p1")
b=get_axis("p2")

'''