bugs correction and improve moving x and y axis

This commit is contained in:
sinseman44
2020-09-13 18:22:16 +01:00
parent ea9db33b19
commit 3875c13356
4 changed files with 164 additions and 106 deletions
+4 -4
View File
@@ -31,8 +31,8 @@ STEPPER_STEPS_PER_REV_Y = 20
# Invert axises direction, by default(False) high level means increase of # Invert axises direction, by default(False) high level means increase of
# position. For inverted(True) axis, high level means decrease of position. # position. For inverted(True) axis, high level means decrease of position.
STEPPER_INVERTED_X = True STEPPER_INVERTED_X = False
STEPPER_INVERTED_Y = False STEPPER_INVERTED_Y = True
STEPPER_INVERTED_Z = False STEPPER_INVERTED_Z = False
STEPPER_INVERTED_E = True STEPPER_INVERTED_E = True
@@ -44,8 +44,8 @@ ENDSTOP_INVERTED_Y = True
ENDSTOP_INVERTED_Z = False # Auto leveler ENDSTOP_INVERTED_Z = False # Auto leveler
# Workplace physical size. # Workplace physical size.
TABLE_SIZE_X_MM = 40 TABLE_SIZE_X_MM = 41
TABLE_SIZE_Y_MM = 40 TABLE_SIZE_Y_MM = 51
TABLE_SIZE_Z_MM = 0 TABLE_SIZE_Z_MM = 0
# Mixed settings. # Mixed settings.
+70 -32
View File
@@ -46,7 +46,7 @@ class stepper:
self.state = self.STEPPER_DISABLED self.state = self.STEPPER_DISABLED
self.dir = self.STATE_DIR_DIRECT self.dir = self.STATE_DIR_DIRECT
self.axe = axe self.axe = axe
self.seq = self.FULL_STEP_SEQ self.seq = self.FULL_STEP_SEQ[:]
self.pins = pins self.pins = pins
self.step_number = 0 self.step_number = 0
self.current_seq_num = 0 self.current_seq_num = 0
@@ -68,11 +68,11 @@ class stepper:
if mode > self.MODE_HALF: if mode > self.MODE_HALF:
raise ValueError raise ValueError
elif mode == self.MODE_FULL: elif mode == self.MODE_FULL:
self.seq = self.FULL_STEP_SEQ self.seq = self.FULL_STEP_SEQ[:]
if self.dir == self.STATE_DIR_INV: if self.dir == self.STATE_DIR_INV:
self.seq.reverse() self.seq.reverse()
elif mode == self.MODE_HALF: elif mode == self.MODE_HALF:
self.seq = self.HALF_STEP_SEQ self.seq = self.HALF_STEP_SEQ[:]
if self.dir == self.STATE_DIR_INV: if self.dir == self.STATE_DIR_INV:
self.seq.reverse() self.seq.reverse()
@@ -81,26 +81,41 @@ class stepper:
if direction > self.STATE_DIR_INV: if direction > self.STATE_DIR_INV:
raise ValueError raise ValueError
elif direction == self.STATE_DIR_INV and self.dir == self.STATE_DIR_DIRECT: elif direction == self.STATE_DIR_INV and self.dir == self.STATE_DIR_DIRECT:
#logging.debug("SET DIR INV")
self.dir = direction self.dir = direction
#logging.debug("BEFORE: {}".format(self.seq))
self.seq.reverse() self.seq.reverse()
#logging.debug("AFTER: {}".format(self.seq))
if self.current_seq_num > 0:
self.current_seq_num = len(self.seq) - 1 - self.current_seq_num
elif direction == self.STATE_DIR_DIRECT and self.dir == self.STATE_DIR_INV: elif direction == self.STATE_DIR_DIRECT and self.dir == self.STATE_DIR_INV:
#logging.debug("SET DIR DIRECT")
self.dir = direction self.dir = direction
#logging.debug("BEFORE: {}".format(self.seq))
self.seq.reverse() self.seq.reverse()
#logging.debug("AFTER: {}".format(self.seq))
if self.current_seq_num > 0:
self.current_seq_num = len(self.seq) - 1 - self.current_seq_num
else: else:
logging.warning("direction already set") logging.warning("direction already set")
def inc_seq_num(self): def inc_seq_num(self):
''' increment current sequence number ''' ''' increment current sequence number '''
self.current_seq_num += 1 if self.current_seq_num >= len(self.seq) - 1:
self.current_seq_num = 0
else:
self.current_seq_num += 1
def dec_seq_num(self): def dec_seq_num(self):
''' decrement current sequence number ''' ''' decrement current sequence number '''
self.current_seq_num -= 1 if self.current_seq_num == 0:
self.current_seq_num = len(self.seq) - 1
else:
self.current_seq_num -= 1
def get_current_seq(self): def get_current_seq(self):
''' get current sequence ''' ''' get current sequence '''
i = self.current_seq_num % (len(self.seq)) return self.seq[self.current_seq_num]
return self.seq[i]
def disable(self): def disable(self):
''' disable stepper ''' ''' disable stepper '''
@@ -112,9 +127,24 @@ class stepper:
''' enable stepper ''' ''' enable stepper '''
self.state = self.STEPPER_ENABLED self.state = self.STEPPER_ENABLED
def set_speed(self, speed): def debug(self):
''' sets the speed in rev per minute ''' ''' debug mode '''
logging.debug("speed = {}".format(60*1000*1000 / self.number_of_steps / speed)) logging.debug("state = {} - \
dir = {} - \
axe = {} - \
seq = {} - \
pins = {} - \
step_number = {} - \
current_seq_num = {} - \
number_of_steps = {}".format(self.state,
self.dir,
self.axe,
self.seq,
self.pins,
self.step_number,
self.current_seq_num,
self.number_of_steps))
stepper_x = stepper(axe=stepper.AXE_X, pins=STEPPER_STEP_PINS_X) stepper_x = stepper(axe=stepper.AXE_X, pins=STEPPER_STEP_PINS_X)
stepper_y = stepper(axe=stepper.AXE_Y, pins=STEPPER_STEP_PINS_Y) stepper_y = stepper(axe=stepper.AXE_Y, pins=STEPPER_STEP_PINS_Y)
@@ -127,12 +157,18 @@ def init():
stepper_x.init() stepper_x.init()
stepper_x.set_mode(mode = stepper.MODE_HALF) stepper_x.set_mode(mode = stepper.MODE_HALF)
stepper_x.set_steps_number(STEPPER_STEPS_PER_REV_X) stepper_x.set_steps_number(STEPPER_STEPS_PER_REV_X)
if STEPPER_INVERTED_X:
stepper_x.set_dir(stepper.STATE_DIR_INV)
stepper_x.enable() stepper_x.enable()
stepper_x.debug()
# Init Y stepper # Init Y stepper
# stepper_y.init() stepper_y.init()
# stepper_y.set_mode(mode = stepper.MODE_HALF) stepper_y.set_mode(mode = stepper.MODE_HALF)
# stepper_x.set_steps_number(STEPPER_STEPS_PER_REV_Y) stepper_y.set_steps_number(STEPPER_STEPS_PER_REV_Y)
# stepper_y.enable() if STEPPER_INVERTED_Y:
stepper_y.set_dir(stepper.STATE_DIR_INV)
stepper_y.enable()
stepper_y.debug()
# Watchdog start # Watchdog start
watchdog.start() watchdog.start()
@@ -217,26 +253,30 @@ def move(generator):
idx = 0 idx = 0
for direction, tx, ty, tz, te in generator: for direction, tx, ty, tz, te in generator:
if current_cb is not None: if current_cb is not None:
logging.debug("{} + {} => result = {}".format(dma.current_address(), bytes_per_iter, dma.current_address() + bytes_per_iter)) #logging.debug("{} + {} => result = {}".format(dma.current_address(), bytes_per_iter, dma.current_address() + bytes_per_iter))
while dma.current_address() + bytes_per_iter >= current_cb: while dma.current_address() + bytes_per_iter >= current_cb:
time.sleep(0.001) time.sleep(0.001)
current_cb = dma.current_control_block() current_cb = dma.current_control_block()
logging.debug("current control block : {}".format(current_cb)) #logging.debug("current control block : {}".format(current_cb))
if current_cb is None: if current_cb is None:
k0 = k k0 = k
st = time.time() st = time.time()
break # previous dma sequence has stopped break # previous dma sequence has stopped
# logging.debug("[{}] direction: {} - tx: {} - ty: {} - tz: {} - te: {}".format(idx, direction, tx, ty, tz, te)) # logging.debug("[{}] direction: {} - tx: {} - ty: {} - tz: {} - te: {}".format(idx, direction, tx, ty, tz, te))
if direction: # set up directions if direction: # set up directions
logging.debug("[{}] direction: {} - tx: {} - ty: {} - tz: {} - te: {}".format(idx, direction, tx, ty, tz, te))
if tx > 0: if tx > 0:
logging.debug("TX Direct")
stepper_x.set_dir(stepper.STATE_DIR_DIRECT) stepper_x.set_dir(stepper.STATE_DIR_DIRECT)
elif tx < 0: elif tx < 0:
logging.debug("TX Inverse")
stepper_x.set_dir(stepper.STATE_DIR_INV) stepper_x.set_dir(stepper.STATE_DIR_INV)
if ty > 0: if ty > 0:
logging.debug("TY Direct")
stepper_y.set_dir(stepper.STATE_DIR_DIRECT) stepper_y.set_dir(stepper.STATE_DIR_DIRECT)
elif ty < 0: elif ty < 0:
logging.debug("TY Inverse")
stepper_y.set_dir(stepper.STATE_DIR_INV) stepper_y.set_dir(stepper.STATE_DIR_INV)
dma.add_delay(STEPPER_PULSE_LENGTH_US)
continue continue
mask_x = 0 mask_x = 0
@@ -248,26 +288,25 @@ def move(generator):
cur_seq_x = stepper_x.get_current_seq() cur_seq_x = stepper_x.get_current_seq()
#logging.debug("[TX] prev = {} - K = {} - diff : {} - cur_seq_x : {}".format(prevx, kx, kx - prevx, cur_seq_x)) #logging.debug("[TX] prev = {} - K = {} - diff : {} - cur_seq_x : {}".format(prevx, kx, kx - prevx, cur_seq_x))
# mask pins # mask pins
for i, enable in enumerate(cur_seq_x): for i, enable_x in enumerate(cur_seq_x):
if enable: if enable_x:
mask_x += 1 << STEPPER_STEP_PINS_X[i] mask_x += 1 << STEPPER_STEP_PINS_X[i]
# set pulse with diff between current time and previous time # set pulse with diff between current time and previous time
# logging.debug("[TX] MASK: {} - TIME(us): {}".format(bin(mask_x), kx - prevx)) #logging.debug("[TX] MASK: {} - TIME(us): {}".format(bin(mask_x), kx - prevx))
dma.add_pulse(mask_x, kx - prevx) dma.add_pulse(mask_x, kx - prevx)
stepper_x.inc_seq_num() stepper_x.inc_seq_num()
prevx = kx + STEPPER_PULSE_LENGTH_US prevx = kx + STEPPER_PULSE_LENGTH_US
if ty is not None: if ty is not None:
logging.debug("not implemented ...") ky = int(round(ty * US_IN_SECONDS))
# ky = int(round(ty * US_IN_SECONDS)) cur_seq_y = stepper_y.get_current_seq()
# cur_seq_y = stepper_y.get_current_seq() #logging.debug("[TY] prev = {} - K = {} - diff : {} - cur_seq_y : {}".format(prevy, ky, ky - prevy, cur_seq_y))
# #logging.debug("[TY] prev = {} - K = {} - diff : {} - cur_seq_y : {}".format(prevy, ky, ky - prevy, cur_seq_y)) for j, enable_y in enumerate(cur_seq_y):
# for j, enable in enumerate(cur_seq_y): if enable_y:
# if enable: mask_y += 1 << STEPPER_STEP_PINS_Y[j]
# mask_y += 1 << STEPPER_STEP_PINS_Y[j] #logging.debug("[TY] MASK: {} - TIME(us): {}".format(bin(mask_y), ky - prevy))
# logging.debug("[TY] MASK: {} - TIME(us): {}".format(bin(mask_y), ky - prevy)) dma.add_pulse(mask_y, ky - prevy)
# dma.add_pulse(mask_y, ky - prevy) stepper_y.inc_seq_num()
# stepper_y.inc_seq_num() prevy = ky + STEPPER_PULSE_LENGTH_US
# prevy = ky + STEPPER_PULSE_LENGTH_US
# run stream ... # run stream ...
# if not is_ran and instant and current_cb is None: # if not is_ran and instant and current_cb is None:
# # TODO: wait 100 ms # # TODO: wait 100 ms
@@ -282,7 +321,6 @@ def move(generator):
# after long command, we can fill short buffer, that why we may need to # after long command, we can fill short buffer, that why we may need to
# wait until long command finishes # wait until long command finishes
while dma.is_active(): while dma.is_active():
logging.debug("wait ...")
time.sleep(0.01) time.sleep(0.01)
dma.run(False) dma.run(False)
else: else:
+29 -35
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
from .rpgpio_private import * #from .rpgpio_private import *
#from rpgpio_private import * from rpgpio_private import *
import time import time
import logging import logging
@@ -463,9 +463,9 @@ def test():
# for testing purpose # for testing purpose
def main(): def main():
#pins_x = [4,17,27,22] #pins_x = [22,27,17,4]
pins_x = [22,27,17,4] #pins_y = [12,16,20,21]
pins_y = [12,16,20,21] pins_x = [12,16,20,21]
seqs = [[1,0,0,0], # Phase A seqs = [[1,0,0,0], # Phase A
[1,0,1,0], # Phase AB [1,0,1,0], # Phase AB
[0,0,1,0], # Phase B [0,0,1,0], # Phase B
@@ -480,44 +480,38 @@ def main():
print("Start output PIN: {}".format(pin)) print("Start output PIN: {}".format(pin))
g.init(pin, GPIO.MODE_OUTPUT) g.init(pin, GPIO.MODE_OUTPUT)
#for pin in pins_y:
# print("Start output PIN: {}".format(pin))
# g.init(pin, GPIO.MODE_OUTPUT)
dg = DMAGPIO() dg = DMAGPIO()
dg.clear()
# counter_max = 100 counter_max = 100
# counter_current = 0 counter_current = 0
# while counter_current < counter_max: while counter_current < counter_max:
# for i in range(0, 63): for i in range(0, 63):
# for seq in seqs: for seq in seqs:
# mask = 0 mask = 0
# for idx, enable in enumerate(seq): for idx, enable in enumerate(seq):
# if enable: if enable:
# mask += 1 << pins_x[idx] mask += 1 << pins_x[idx]
# #mask += 1 << pins_y[idx] dg.add_pulse(mask, 1000)
# dg.add_pulse(mask, 1000) dg.finalize_stream()
# dg.finalize_stream()
# dg.run_stream()
# dg.run_stream() while dg.is_active():
# while dg.is_active(): time.sleep(0.01)
# time.sleep(0.01) dg.clear()
# dg.clear() seqs.reverse()
# seqs.reverse() counter_current += 1
# counter_current += 1 # try:
try: # print("press enter to stop...")
print("press enter to stop...") # sys.stdin.readline()
sys.stdin.readline() # except KeyboardInterrupt:
except KeyboardInterrupt: # pass
pass
dg.clear() dg.clear()
dg.stop() dg.stop()
for pin in pins_x: for pin in pins_x:
print("Stop output PIN: {}".format(pin)) print("Stop output PIN: {}".format(pin))
g.clear(pin) g.clear(pin)
# for pin in pins_y:
# print("Stop output PIN: {}".format(pin))
# g.clear(pin)
if __name__ == "__main__": if __name__ == "__main__":
main() main()
+61 -35
View File
@@ -1,36 +1,62 @@
g21 G91 f2000
g90
; move to start position
g1x50y50f1800
z20f120
f1800
g91
; run ; run
x100 G1 x39 f2000
y100 G1 y49 f2000
x-100 G1 x-39 f2000
y-90 G1 y-49 f2000
x90 G1 x35 f2500
y80 G1 y45 f2500
x-80 G1 x-35 f2500
y-70 G1 y-45 f2500
x70 G1 x30 f3000
y60 G1 y40 f3000
x-60 G1 x-30 f3000
y-50 G1 y-40 f3000
x50 G1 x20 f3500
y40 G1 y35 f3500
x-40 G1 x-20 f3500
y-30 G1 y-35 f3500
x30 G1 x10 f4000
y20 G1 y45 f4000
x-20 G1 x-10 f4000
y-10 G1 y-45 f4000
x10 G1 x39 f2000
y5 G1 y49 f2000
x-5 G1 x-39 f2000
y-2.5 G1 y-49 f2000
x2.5 G1 x35 f2500
; homing G1 y45 f2500
g28 G1 x-35 f2500
G1 y-45 f2500
G1 x30 f3000
G1 y40 f3000
G1 x-30 f3000
G1 y-40 f3000
G1 x20 f3500
G1 y35 f3500
G1 x-20 f3500
G1 y-35 f3500
G1 x10 f4000
G1 y45 f4000
G1 x-10 f4000
G1 y-45 f4000
G1 x39 f2000
G1 y49 f2000
G1 x-39 f2000
G1 y-49 f2000
G1 x35 f2500
G1 y45 f2500
G1 x-35 f2500
G1 y-45 f2500
G1 x30 f3000
G1 y40 f3000
G1 x-30 f3000
G1 y-40 f3000
G1 x20 f3500
G1 y35 f3500
G1 x-20 f3500
G1 y-35 f3500
G1 x10 f4000
G1 y45 f4000
G1 x-10 f4000
G1 y-45 f4000