blob: 415465141fe265042e88940eada39befebb7a55d (
plain)
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
|
# -*- coding: utf-8 -*-
import Queue
import threading
class Action:
EXECUTING = 0
FINISHED = 1
ABORTED = 2
def execute(self):
self.aborted = False
self.do_execute()
def ended(self):
if self.aborted:
return True
return do_ended()
def abort(self):
self.do_abort()
self.aborted = True
def do_execute():
raise NotImplementedError
def do_abort():
raise NotImplementedError
def do_ended():
raise NotImplementedError
class ActionMotion(Action):
def __init__(self, axes, target, speed = None):
if len(axes) != len(target):
raise ValueError()
if speed and len(speed) != len(axes):
raise ValueError()
self.axes = axes
self.target_position = target
self.motion_speed = speed
def do_execute(self):
for i, axis enumerate(self.axes):
if self.speed:
axis.
class ActionExecuter(threading.Thread)
def __init__(self, action):
self.action = action
def start(self):
import threading, weakref
self.running = True
self.worker_thread = threading.Thread(target=ActionExecuter.run, args=(weakref.proxy(self),))
def abort(self):
self.running = False
self.worker_thread.join()
def run(self):
action = self.action
try:
action.execute()
except ReferenceError:
action.abort()
class MotionControl(object):
def __init__(self, name):
self.name = name
self.active = True
self.worker_thread = threading.Thread(target = self.workerLoop, name = "MotionControl.worker_thread")
self.worker_thread.setDaemon(True)
self.worker_thread.start()
def __del__(self):
def workerLoop(self):
import time
while self.active:
print self.name
time.sleep(1)
|