File: test-ui.py

package info (click to toggle)
linuxcnc 1%3A2.9.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 285,604 kB
  • sloc: python: 202,568; ansic: 109,036; cpp: 99,239; tcl: 16,054; xml: 10,631; sh: 10,303; makefile: 1,255; javascript: 138; sql: 72; asm: 15
file content (182 lines) | stat: -rwxr-xr-x 5,122 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
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
#!/usr/bin/env python3

import linuxcnc
import hal
import time
import sys

def wait_for_linuxcnc_startup(status, timeout=10.0):

    """Poll the Status buffer waiting for it to look initialized,
    rather than just allocated (all-zero).  Returns on success, throws
    RuntimeError on failure."""

    start_time = time.time()
    while time.time() - start_time < timeout:
        status.poll()
        if (status.angular_units == 0.0) \
            or (status.axis_mask == 0) \
            or (status.cycle_time == 0.0) \
            or (status.exec_state != linuxcnc.EXEC_DONE) \
            or (status.interp_state != linuxcnc.INTERP_IDLE) \
            or (status.inpos == False) \
            or (status.linear_units == 0.0) \
            or (status.max_acceleration == 0.0) \
            or (status.max_velocity == 0.0) \
            or (status.program_units == 0.0) \
            or (status.rapidrate == 0.0) \
            or (status.state != linuxcnc.RCS_DONE) \
            or (status.task_state != linuxcnc.STATE_ESTOP):
            time.sleep(0.1)
        else:
            # looks good
            return

    # timeout, throw an exception
    raise RuntimeError


def wait_for_mdi_queue(queue_len, timeout=10):
    start_time = time.time()
    while (time.time() - start_time) < timeout:
        s.poll()
        if s.queued_mdi_commands == queue_len:
            return
        time.sleep(0.1)
    print("queued_mdi_commands at %d after %.3f seconds" % (s.queued_mdi_commands, timeout))
    sys.exit(1)


c = linuxcnc.command()
s = linuxcnc.stat()
e = linuxcnc.error_channel()
comp = hal.component('hal-watcher')

# Wait for LinuxCNC to initialize itself so the Status buffer stabilizes.
wait_for_linuxcnc_startup(s)

c.state(linuxcnc.STATE_ESTOP_RESET)
c.state(linuxcnc.STATE_ON)
c.wait_complete()


# Check G-code / MDI spindle commands

c.mode(linuxcnc.MODE_MDI)

c.mdi("M3 S10 $0")
c.mdi("M3 S10 $1")
c.mdi("M3 S10 $2")
c.wait_complete()

s.poll()

assert hal.get_value('spindle.0.speed-out') == 100
assert s.spindle[0]['speed'] == 100
assert hal.get_value('spindle.1.speed-out') == 200
assert s.spindle[1]['speed'] == 200
assert hal.get_value('spindle.2.speed-out') == 300
assert s.spindle[2]['speed'] == 300

c.mdi("M3 S10000 $0")
c.mdi("M3 S10000 $1")
c.mdi("M3 S10000 $2")
c.wait_complete()

s.poll()

assert hal.get_value('spindle.0.speed-out') == 1000
assert s.spindle[0]['speed'] == 1000
assert hal.get_value('spindle.1.speed-out') == 2000
assert s.spindle[1]['speed'] == 2000
assert hal.get_value('spindle.2.speed-out') == 3000
assert s.spindle[2]['speed'] == 3000

c.mdi("M4 S10 $0")
c.mdi("M4 S10 $1")
c.mdi("M4 S10 $2")
c.wait_complete()

s.poll()

assert hal.get_value('spindle.0.speed-out') == -500
assert s.spindle[0]['speed'] == -500
assert hal.get_value('spindle.1.speed-out') == -200
assert s.spindle[1]['speed'] == -200
assert hal.get_value('spindle.2.speed-out') == -300
assert s.spindle[2]['speed'] == -300

c.mdi("M4 S10000 $0")
c.mdi("M4 S10000 $1")
c.mdi("M4 S10000 $2")
c.wait_complete()

s.poll()

assert hal.get_value('spindle.0.speed-out') == -1500
assert s.spindle[0]['speed'] == -1500
assert hal.get_value('spindle.1.speed-out') == -2500
assert s.spindle[1]['speed'] == -2500
assert hal.get_value('spindle.2.speed-out') == -3000
assert s.spindle[2]['speed'] == -3000

# Check Python interface commands

c.spindle(linuxcnc.SPINDLE_FORWARD, 10, 0, 0)
c.spindle(linuxcnc.SPINDLE_FORWARD, 10, 1, 0)
c.spindle(linuxcnc.SPINDLE_FORWARD, 10, 2, 0)
c.wait_complete()

s.poll()

assert hal.get_value('spindle.0.speed-out') == 100
assert s.spindle[0]['speed'] == 100
assert hal.get_value('spindle.1.speed-out') == 200
assert s.spindle[1]['speed'] == 200
assert hal.get_value('spindle.2.speed-out') == 300
assert s.spindle[2]['speed'] == 300

c.spindle(linuxcnc.SPINDLE_FORWARD, 10000, 0, 0)
c.spindle(linuxcnc.SPINDLE_FORWARD, 10000, 1, 0)
c.spindle(linuxcnc.SPINDLE_FORWARD, 10000, 2, 0)
c.wait_complete()

s.poll()

assert hal.get_value('spindle.0.speed-out') == 1000
assert s.spindle[0]['speed'] == 1000
assert hal.get_value('spindle.1.speed-out') == 2000
assert s.spindle[1]['speed'] == 2000
assert hal.get_value('spindle.2.speed-out') == 3000
assert s.spindle[2]['speed'] == 3000

c.spindle(linuxcnc.SPINDLE_REVERSE, 10, 0, 0)
c.spindle(linuxcnc.SPINDLE_REVERSE, 10, 1, 0)
c.spindle(linuxcnc.SPINDLE_REVERSE, 10, 2, 0)
c.wait_complete()

s.poll()

assert hal.get_value('spindle.0.speed-out') == -500
assert s.spindle[0]['speed'] == -500
assert hal.get_value('spindle.1.speed-out') == -200
assert s.spindle[1]['speed'] == -200
assert hal.get_value('spindle.2.speed-out') == -300
assert s.spindle[2]['speed'] == -300

c.spindle(linuxcnc.SPINDLE_REVERSE, 10000, 0, 0)
c.spindle(linuxcnc.SPINDLE_REVERSE, 10000, 1, 0)
c.spindle(linuxcnc.SPINDLE_REVERSE, 10000, 2, 0)
c.wait_complete()

s.poll()

assert hal.get_value('spindle.0.speed-out') == -1500
assert s.spindle[0]['speed'] == -1500
assert hal.get_value('spindle.1.speed-out') == -2500
assert s.spindle[1]['speed'] == -2500
assert hal.get_value('spindle.2.speed-out') == -3000
assert s.spindle[2]['speed'] == -3000

sys.exit(0)