TestPI_E517.py 8.39 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
import unittest
import sys
import os
blissadm's avatar
merged.    
blissadm committed
11
import time
12

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

import bliss

config_xml = """
<config>
24
25
  <controller class="PI_E517" name="testid16a">
    <host value="192.168.167.10"/>
bliss administrator's avatar
bliss administrator committed
26
27
28
29
    <encoder name="encA">
      <steps_per_unit value="1"/>
      <tolerance value="0.001"/>
    </encoder>
blissadm's avatar
blissadm committed
30
31
32
33
34
35
36
37
    <axis name="px">
      <channel       value="1"/>
      <chan_letter   value="A"/>
    </axis>
    <axis name="py">
      <channel       value="2"/>
      <chan_letter   value="B"/>
    </axis>
38
    <axis name="pz">
blissadm's avatar
blissadm committed
39
40
      <channel       value="3"/>
      <chan_letter   value="C"/>
41
42
43
44
45
    </axis>
  </controller>
</config>
"""

Matias Guijarro's avatar
Matias Guijarro committed
46

47
48
49
50
51
52
class TestPI_E517Controller(unittest.TestCase):

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

bliss administrator's avatar
bliss administrator committed
53
    def test_get_informations(self):
54
        pz = bliss.get_axis("pz")
55
56
57
        print "PI_E517 IDN :", pz.get_id()
        print "PI_E517 channel :", pz.channel
        print "PI_E517 chan_letter :", pz.chan_letter
bliss administrator's avatar
bliss administrator committed
58
59
        print "PI_E517 pz state:", pz.state()
        print "PI_E517 INFOS :\n", pz.get_info()
60

blissadm's avatar
blissadm committed
61
62
    def test_get_position(self):
        pz = bliss.get_axis("pz")
63
64
65
        print "PI_E517 pz position :", pz.position()
        print "PI_E517 pz measured position :", pz.measured_position()
        print "PI_E517 pz output voltage :", pz.controller._get_voltage(pz)
blissadm's avatar
merged.    
blissadm committed
66
67
68

    def test_get_closed_loop_status(self):
        pz = bliss.get_axis("pz")
69
        print "PI_E517 pz closed loop enabled :", \
Matias Guijarro's avatar
Matias Guijarro committed
70
              pz.controller._get_closed_loop_status(pz)
blissadm's avatar
merged.    
blissadm committed
71

72
73
74
75
76
77
78
    def test_very_small_move(self):
        pz = bliss.get_axis("pz")
        _pos = pz.position()
        _new_pos = _pos + 0.001
        print "PI_E517 move to ",  _new_pos
        pz.move(_new_pos)

bliss administrator's avatar
bliss administrator committed
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
    def test_encoder(self):
        encA = bliss.get_encoder("encA")
        self.assertTrue(encA)
        print "PI_E517 encoder : ", encA.read()

#    def test_multiple_move(self):
#        pz = bliss.get_axis("pz")
#        _pos = pz.position()
#        for i in range(1000):
#            print i,
#            pz.move(_pos, wait=True)
#
#    def test_multiple_raw_move(self):
#        pz = bliss.get_axis("pz")
#        _pos = pz.position()
#        _cmd = "SVA %s %g \n" % (pz.chan_letter, _pos)
#        for i in range(1000):
#            print i,
#            pz.controller.sock.write(_cmd)
#            # time.sleep(0.001)
#        _pos = pz.position()
#        print "PI_E517 pos=", _pos
#
#
#    def test_multiple_raw_read_pos(self):
#        '''
#        25 mar.2014 :
#        nb_cmd=10000, mean=1.217250ms, max=2.267838 Ran 1 test in 12.414s
#        nb_cmd=100000,mean=1.242071ms, max=919.186115
#               val> 4ms : 627.511 919.186 887.565
#        '''
#        pz = bliss.get_axis("pz")
#        _cmd = "SVA? %s\n" % pz.chan_letter
#        _sum_time = 0
#        _nb_cmd = 100000
#        _max_duration = 0
#        _errors = 0
#        for i in range(_nb_cmd):
#            _t0 = time.time()
#            try:
#                _pos = pz.controller.sock.write_readline(_cmd, timeout=0.1),
#            except:
#                import pdb
#                pdb.set_trace()
#                print "TIMEOUT"
#            _duration = (time.time() - _t0) *1000
#            _sum_time = _sum_time + _duration
#            if _duration > _max_duration:
#                _max_duration = _duration
#            if _duration > 5:
#                print "i=%d  %6.3f" % (i, _duration)
#                _errors = _errors + 1
#            if (i % 100) == 0:
#                print ".",
#        print "nb_cmd=%d, mean=%fms, max=%f" % (_nb_cmd, _sum_time / _nb_cmd, _max_duration)
#
#
#     def test_multiple_raw_read_pos_and_move(self):
#         print " \n\n"
#         pz = bliss.get_axis("pz")
#         _pos = pz.position()
#         _cmd_move = "SVA %s %g \n" % (pz.chan_letter, _pos)
#         _cmd_pos = "SVA? %s\n" % pz.chan_letter
#         for i in range(100):
#             print i,
#             print pz.controller.sock.write_readline(_cmd_pos),
#             # time.sleep(0.01)
#             pz.controller.sock.write(_cmd_move)
#
#
#    def test_multiple_raw_read_pos_and_move_3chan(self):
#        print " \n\n"
#        px = bliss.get_axis("px")
#        py = bliss.get_axis("py")
#        pz = bliss.get_axis("pz")
#        _pos_x = px.position()
#        _pos_y = py.position()
#        _pos_z = pz.position()
#        _cmd_move_x = "SVA %s %g \n" % (px.chan_letter, _pos_x)
#        _cmd_pos_x = "SVA? %s\n" % px.chan_letter
#        _cmd_move_y = "SVA %s %g \n" % (py.chan_letter, _pos_y)
#        _cmd_pos_y = "SVA? %s\n" % py.chan_letter
#        _cmd_move_z = "SVA %s %g \n" % (pz.chan_letter, _pos_z)
#        _cmd_pos_z = "SVA? %s\n" % pz.chan_letter
#
#        _respire = 0
#
#        for i in range(100):
#            print i,
#
#            _t0 = time.time()
#            px.controller.sock.write(_cmd_move_x)
#            _ans = px.controller.sock.write_readline(_cmd_pos_x)
#            _duration = 1000 * (time.time() - _t0)
#            print _ans,
#            if _duration > 5:
#                print "oups duration : ", _duration
#            time.sleep(_respire)
#
#            _t0 = time.time()
#            py.controller.sock.write(_cmd_move_y)
#            _ans = py.controller.sock.write_readline(_cmd_pos_y)
#            _duration = 1000 * (time.time() - _t0)
#            print _ans,
#            if _duration > 5:
#                print "oups duration : ", _duration
#            time.sleep(_respire)
#
#            _t0 = time.time()
#            pz.controller.sock.write(_cmd_move_z)
#            _ans =  pz.controller.sock.write_readline(_cmd_pos_z)
#            _duration = 1000 * (time.time() - _t0)
#            print _ans,
#            if _duration > 5:
#                print "oups duration : ", _duration
#            time.sleep(_respire)
195
196


blissadm's avatar
merged.    
blissadm committed
197
198
    def test_get_on_target_status(self):
        pz = bliss.get_axis("pz")
199
        print "PI_E517 pz on target :", pz.controller._get_on_target_status(pz)
200

blissadm's avatar
merged.    
blissadm committed
201
202
203
    # called at end of each test
    def tearDown(self):
        # Little wait time to let time to PI controller to
204
        # close peacefully its sockets... (useful ?)
blissadm's avatar
merged.    
blissadm committed
205
        time.sleep(0.2)
206

207

208
209
210
211
212
213
214
215

if __name__ == '__main__':
    unittest.main()


'''
NI Interactive test :

blissadm's avatar
blissadm committed
216
217
load_cfg_fromstring("""
<config>
218
219
  <controller class="PI_E517" name="testid16a">
    <host value="192.168.167.10"/>
blissadm's avatar
blissadm committed
220
    <axis name="p4">
blissadm's avatar
blissadm committed
221
      <channel       value="1"/>
blissadm's avatar
merged.    
blissadm committed
222
      <chan_letter   value="A"/>
blissadm's avatar
blissadm committed
223
    </axis>
blissadm's avatar
blissadm committed
224
    <axis name="p5">
blissadm's avatar
blissadm committed
225
      <channel       value="2"/>
blissadm's avatar
merged.    
blissadm committed
226
      <chan_letter   value="B"/>
227
    </axis>
blissadm's avatar
blissadm committed
228
229
230
231
232
    <axis name="p6">
      <channel       value="3"/>
      <chan_letter   value="C"/>
    </axis>
  </controller>
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
  <controller class="PI_E517" name="testid16b">
    <host value="192.168.168.10"/>
    <axis name="p1">
      <channel       value="1"/>
      <chan_letter   value="A"/>
    </axis>
    <axis name="p2">
      <channel       value="2"/>
      <chan_letter   value="B"/>
    </axis>
    <axis name="p3">
      <channel       value="3"/>
      <chan_letter   value="C"/>
    </axis>
  </controller>
blissadm's avatar
blissadm committed
248
249
250
251
252
253
254
255
256
257
</config>
""")

d=get_axis("p4")
e=get_axis("p5")
f=get_axis("p6")


load_cfg_fromstring("""
<config>
258
259
  <controller class="PI_E517" name="e517b">
    <host value="192.168.168.10" />
blissadm's avatar
blissadm committed
260
    <axis name="p1">
261
262
263
264
265
      <channel value="1" />
      <chan_letter value="A" />
      <velocity value="10" />
      <steps_per_unit value="1" />
    <settings><velocity value="10.0" /><position value="20.3624" /><low_limit value="-1000000000.0" /><high_limit value="1000000000.0" /></settings></axis>
blissadm's avatar
blissadm committed
266
    <axis name="p2">
267
268
269
270
271
      <channel value="2" />
      <chan_letter value="B" />
      <velocity value="10" />
      <steps_per_unit value="1" />
    <settings><velocity value="10.0" /><position value="38.3457" /><low_limit value="-1000000000.0" /><high_limit value="1000000000.0" /></settings></axis>
blissadm's avatar
blissadm committed
272
    <axis name="p3">
273
274
275
276
277
      <channel value="3" />
      <chan_letter value="C" />
      <velocity value="10" />
      <steps_per_unit value="1" />
    <settings><velocity value="10.0" /><position value="-0.3161" /><low_limit value="-1000000000.0" /><high_limit value="1000000000.0" /></settings></axis>
278
279
  </controller>
</config>
280
""") ; 
281
282


blissadm's avatar
blissadm committed
283
284
285
a=get_axis("p1")
b=get_axis("p2")
c=get_axis("p3")
286
287
288


'''