Line 47... |
Line 47... |
47 |
self.SPU = StepsPerUnit |
47 |
self.SPU = StepsPerUnit |
48 |
self.Reset() |
48 |
self.Reset() |
49 |
|
49 |
|
50 |
def Reset(self): |
50 |
def Reset(self): |
51 |
' Reset Axis and set default parameters for H-bridge ' |
51 |
' Reset Axis and set default parameters for H-bridge ' |
52 |
self.spi.xfer( 0xC0) # reset |
52 |
self.spi.xfer([0xC0]) # reset |
53 |
# self.spi.xfer( 0x14) # Stall Treshold setup |
53 |
# self.spi.xfer( 0x14) # Stall Treshold setup |
54 |
# self.spi.xfer( 0xFF) |
54 |
# self.spi.xfer( 0xFF) |
55 |
# self.spi.xfer( 0x13) # Over Current Treshold setup |
55 |
# self.spi.xfer( 0x13) # Over Current Treshold setup |
56 |
# self.spi.xfer( 0xFF) |
56 |
# self.spi.xfer( 0xFF) |
57 |
self.spi.xfer( 0x15) # Full Step speed |
57 |
self.spi.xfer([0x15]) # Full Step speed |
58 |
self.spi.xfer( 0xFF) |
58 |
self.spi.xfer([0xFF]) |
59 |
self.spi.xfer( 0xFF) |
59 |
self.spi.xfer([0xFF]) |
60 |
self.spi.xfer( 0x05) # ACC |
60 |
self.spi.xfer([0x05]) # ACC |
61 |
self.spi.xfer( 0x00) |
61 |
self.spi.xfer([0x00]) |
62 |
self.spi.xfer( 0x10) |
62 |
self.spi.xfer([0x10]) |
63 |
self.spi.xfer( 0x06) # DEC |
63 |
self.spi.xfer([0x06]) # DEC |
64 |
self.spi.xfer( 0x00) |
64 |
self.spi.xfer([0x00]) |
65 |
self.spi.xfer( 0x10) |
65 |
self.spi.xfer([0x10]) |
66 |
self.spi.xfer( 0x0A) # KVAL_RUN |
66 |
self.spi.xfer([0x0A]) # KVAL_RUN |
67 |
self.spi.xfer( 0xFF) |
67 |
self.spi.xfer([0xFF]) |
68 |
self.spi.xfer( 0x0B) # KVAL_ACC |
68 |
self.spi.xfer([0x0B]) # KVAL_ACC |
69 |
self.spi.xfer( 0xFF) |
69 |
self.spi.xfer([0xFF]) |
70 |
self.spi.xfer( 0x0C) # KVAL_DEC |
70 |
self.spi.xfer([0x0C]) # KVAL_DEC |
71 |
self.spi.xfer( 0xFF) |
71 |
self.spi.xfer([0xFF]) |
72 |
self.spi.xfer( 0x18) # CONFIG |
72 |
self.spi.xfer([0x18]) # CONFIG |
73 |
self.spi.xfer( 0b00111000) |
73 |
self.spi.xfer([0b00111000]) |
74 |
self.spi.xfer( 0b00000000) |
74 |
self.spi.xfer([0b00000000]) |
75 |
|
75 |
|
76 |
def MaxSpeed(self, speed): |
76 |
def MaxSpeed(self, speed): |
77 |
' Setup of maximum speed ' |
77 |
' Setup of maximum speed ' |
78 |
self.spi.xfer( 0x07) # Max Speed setup |
78 |
self.spi.xfer([0x07]) # Max Speed setup |
79 |
self.spi.xfer( 0x00) |
79 |
self.spi.xfer([0x00]) |
80 |
self.spi.xfer( speed) |
80 |
self.spi.xfer([speed]) |
81 |
|
81 |
|
82 |
def ReleaseSW(self): |
82 |
def ReleaseSW(self): |
83 |
' Go away from Limit Switch ' |
83 |
' Go away from Limit Switch ' |
84 |
while self.ReadStatusBit(2) == 1: # is Limit Switch ON ? |
84 |
while self.ReadStatusBit(2) == 1: # is Limit Switch ON ? |
85 |
self.spi.xfer( 0x92 | (~self.Dir & 1)) # release SW |
85 |
self.spi.xfer([0x92 | (~self.Dir & 1)]) # release SW |
86 |
while self.IsBusy(): |
86 |
while self.IsBusy(): |
87 |
pass |
87 |
pass |
88 |
self.MoveWait(10) # move 10 units away |
88 |
self.MoveWait(10) # move 10 units away |
89 |
|
89 |
|
90 |
def GoZero(self, speed): |
90 |
def GoZero(self, speed): |
91 |
' Go to Zero position ' |
91 |
' Go to Zero position ' |
92 |
self.ReleaseSW() |
92 |
self.ReleaseSW() |
93 |
|
93 |
|
94 |
self.spi.xfer( 0x82 | (self.Dir & 1)) # Go to Zero |
94 |
self.spi.xfer([0x82 | (self.Dir & 1)]) # Go to Zero |
95 |
self.spi.xfer( 0x00) |
95 |
self.spi.xfer([0x00]) |
96 |
self.spi.xfer( speed) |
96 |
self.spi.xfer([speed]) |
97 |
while self.IsBusy(): |
97 |
while self.IsBusy(): |
98 |
pass |
98 |
pass |
99 |
time.sleep(0.3) |
99 |
time.sleep(0.3) |
100 |
self.ReleaseSW() |
100 |
self.ReleaseSW() |
101 |
|
101 |
|
102 |
def Move(self, units): |
102 |
def Move(self, units): |
103 |
' Move some distance units from current position ' |
103 |
' Move some distance units from current position ' |
104 |
steps = units * self.SPU # translate units to steps |
104 |
steps = units * self.SPU # translate units to steps |
105 |
if steps > 0: # look for direction |
105 |
if steps > 0: # look for direction |
106 |
self.spi.xfer( 0x40 | (~self.Dir & 1)) |
106 |
self.spi.xfer([0x40 | (~self.Dir & 1)]) |
107 |
else: |
107 |
else: |
108 |
self.spi.xfer( 0x40 | (self.Dir & 1)) |
108 |
self.spi.xfer([0x40 | (self.Dir & 1)]) |
109 |
steps = int(abs(steps)) |
109 |
steps = int(abs(steps)) |
110 |
self.spi.xfer( (steps >> 16) & 0xFF) |
110 |
self.spi.xfer([(steps >> 16) & 0xFF]) |
111 |
self.spi.xfer( (steps >> 8) & 0xFF) |
111 |
self.spi.xfer([(steps >> 8) & 0xFF]) |
112 |
self.spi.xfer( steps & 0xFF) |
112 |
self.spi.xfer([steps & 0xFF]) |
113 |
|
113 |
|
114 |
def MoveWait(self, units): |
114 |
def MoveWait(self, units): |
115 |
' Move some distance units from current position and wait for execution ' |
115 |
' Move some distance units from current position and wait for execution ' |
116 |
self.Move(units) |
116 |
self.Move(units) |
117 |
while self.IsBusy(): |
117 |
while self.IsBusy(): |