TestGalilDMC213.py 2.26 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

import bliss
21
from bliss.common.axis import READY, MOVING
22
import bliss.common.log
23

24 25 26 27 28 29 30 31 32
bliss.common.log.level(bliss.log.DEBUG)

config_xml = """
<config>
  <controller class="GalilDMC213">
    <host value="192.168.0.2"/>
    <axis name="omega">
      <channel value="A"/>
      <steps_per_unit value="-12800"/>
33
      <velocity value="50"/>
34 35
      <acceleration value="400"/>
      <encoder_steps_per_unit value=""/>
36 37 38 39 40 41 42 43 44
    </axis>
  </controller>
</config>
"""


class TestGalilDMC213(unittest.TestCase):
    def setUp(self):
        bliss.load_cfg_fromstring(config_xml)
45

46 47 48 49
    def testCommunication(self):
        o = bliss.get_axis("omega")
        self.assertEquals(o.controller._galil_query("MG 1+3"), "4.0000")
        self.assertRaises(RuntimeError, o.controller._galil_query, "BLA")
50 51 52 53
        self.assertTrue(
            o.controller._galil_query(chr(18) + chr(22)).startswith("DMC2112")
        )

54 55
    def testVelocity(self):
        o = bliss.get_axis("omega")
56
        self.assertEquals(o.velocity(), 50)
57 58
        self.assertEquals(o.acceleration(), 400)
        self.assertEquals(o.acctime(), 0.125)
59 60
        t0 = time.time()
        o.rmove(100)
61
        dt = time.time() - t0
62 63
        self.assertTrue(dt < 2.4)
        o.velocity(100)
64
        o.acctime(0.125)
65
        self.assertEquals(o.acceleration(), o.velocity() / o.acctime())
66 67 68 69 70
        t0 = time.time()
        o.rmove(-100)
        dt = time.time() - t0
        self.assertTrue(dt < 1.4)

71 72 73
    def testHomeSearch(self):
        o = bliss.get_axis("omega")
        o.home()
74

75 76 77 78
    def testPosition(self):
        o = bliss.get_axis("omega")
        p = o.position()
        o.rmove(10)
79 80
        self.assertAlmostEquals(o.position(), p + 10, places=3)

81 82 83 84 85 86
    """
    def testEncoder(self):
        o = bliss.get_axis("omega")
        p = o.measured_position()
        o.rmove(10)
        self.assertAlmostEquals(o.measured_position(), p+10, places=3)
87 88 89 90
    """


if __name__ == "__main__":
91
    unittest.main()