TestFlexDC.py 3.11 KB
Newer Older
blissadm's avatar
blissadm committed
1 2 3 4
"""
Unittest for FlexDC controller in bliss library.
"""

5 6 7
import unittest
import sys
import os
8
import time
9

Matias Guijarro's avatar
Matias Guijarro committed
10 11 12
sys.path.insert(
    0,
    os.path.abspath(
13 14 15
        os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir)
    ),
)
16 17 18 19 20 21 22 23

import bliss

config_xml = """
<config>
  <controller class="FlexDC" name="id16phn">
    <host value="flexdcnina"/>
    <axis name="fd">
Cyril Guilloud's avatar
Cyril Guilloud committed
24 25 26 27
      <channel        value="X"/>
      <steps_per_unit value="13111"/>
      <target_radius  value="20"/>
      <target_time    value="10"/>
blissadm's avatar
blissadm committed
28 29
      <min_dead_zone value="40" />
      <max_dead_zone value="100" />
Cyril Guilloud's avatar
Cyril Guilloud committed
30
      <smoothing      value="4"/>
blissadm's avatar
blissadm committed
31 32 33
      <acceleration   value="3"/>
      <deceleration   value="2"/>
      <velocity       value="1.2"/>
34 35 36 37 38
    </axis>
  </controller>
</config>
"""

Matias Guijarro's avatar
Matias Guijarro committed
39

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
class TestFlexDCController(unittest.TestCase):

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

    def test_get_axis(self):
        fd = bliss.get_axis("fd")
        self.assertTrue(fd)

    def test_controller_from_axis(self):
        fd = bliss.get_axis("fd")
        self.assertEqual(fd.controller.name, "id16phn")

    def test_state(self):
        fd = bliss.get_axis("fd")
        print "FlexDC state :", fd.state()

Cyril Guilloud's avatar
Cyril Guilloud committed
58 59 60
    def test_position(self):
        fd = bliss.get_axis("fd")
        print "FlexDC position :", fd.position()
61 62 63

    def test_get_id(self):
        fd = bliss.get_axis("fd")
Cyril Guilloud's avatar
Cyril Guilloud committed
64
        print "FlexDC ID :", fd.get_id()
65

Cyril Guilloud's avatar
Cyril Guilloud committed
66
    def test_velocity(self):
67
        fd = bliss.get_axis("fd")
blissadm's avatar
blissadm committed
68
        _read_vel = fd.velocity()
Matias Guijarro's avatar
Matias Guijarro committed
69
        print "FlexDC read velocity :", _read_vel
blissadm's avatar
blissadm committed
70
        self.assertAlmostEqual(_read_vel, 1.2, places=3)
71

blissadm's avatar
blissadm committed
72 73 74
    def test_acceleration(self):
        fd = bliss.get_axis("fd")
        _read_acc = fd.settings.get("acceleration")
Matias Guijarro's avatar
Matias Guijarro committed
75
        print "FlexDC read acceleration :", _read_acc
blissadm's avatar
blissadm committed
76
        self.assertEqual(_read_acc, 3)
blissadm's avatar
blissadm committed
77

Cyril Guilloud's avatar
Cyril Guilloud committed
78
    def test_get_info(self):
79
        fd = bliss.get_axis("fd")
Cyril Guilloud's avatar
Cyril Guilloud committed
80
        print "FlexDC INFOS :\n", fd.get_info()
81

Cyril Guilloud's avatar
Cyril Guilloud committed
82 83
    # called at end of each test
    def tearDown(self):
84 85 86
        # Little wait time to let time to flexdc controller to
        # close peacefully its sockets...
        time.sleep(0.05)
87

88

Cyril Guilloud's avatar
Cyril Guilloud committed
89 90 91 92 93 94 95
#    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")
96

97
if __name__ == "__main__":
98 99 100 101
    unittest.main()


'''
102
NINA Interactive test :
103 104 105 106

load_cfg_fromstring("""<config>
  <controller class="FlexDC" name="id16phn">
    <host value="flexdcnina"/>
107
    <axis name="srot">
Cyril Guilloud's avatar
Cyril Guilloud committed
108 109 110 111 112 113 114 115 116 117
      <channel        value="X"/>
      <steps_per_unit value="13111.11"/>
      <target_radius  value="10"/>
      <target_time    value="20"/>
      <min_dead_zone  value="4"/>
      <max_dead_zone  value="10"/>
      <smoothing      value="4"/>
      <acceleration   value="398400"/>
      <deceleration   value="398400"/>
      <velocity       value="13111"/>
118 119 120
    </axis>
  </controller>
</config>
121 122
""");
a=get_axis("srot")  ; print a.state()
Cyril Guilloud's avatar
Cyril Guilloud committed
123

124

Cyril Guilloud's avatar
Cyril Guilloud committed
125
print a.get_id()
126

Cyril Guilloud's avatar
Cyril Guilloud committed
127
print a.get_info()
128

Cyril Guilloud's avatar
Cyril Guilloud committed
129
print a.controller
130 131 132


'''