refactoring

This commit is contained in:
Nikolay Khabarov
2017-06-12 00:52:11 +03:00
parent 0fe98f4cca
commit 98bf7e914e
23 changed files with 448 additions and 405 deletions
+23 -22
View File
@@ -1,10 +1,8 @@
from __future__ import division
import logging
import time
from cnc.pulses import PulseGeneratorLinear, PulseGeneratorCircular
from cnc.pulses import *
from cnc.config import *
from cnc.coordinates import Coordinates
""" This is virtual device class which is very useful for debugging.
It checks PulseGenerator with some tests.
@@ -25,6 +23,7 @@ def spindle_control(percent):
logging.info("spindle control: {}%".format(percent))
# noinspection PyUnusedLocal
def move(generator):
""" Move head to specified position.
:param generator: PulseGenerator object.
@@ -35,28 +34,28 @@ def move(generator):
dx, dy, dz, de = 0, 0, 0, 0
mx, my, mz, me = 0, 0, 0, 0
cx, cy, cz, ce = 0, 0, 0, 0
dirx, diry, dirz, dire = 1, 1, 1, 1
direction_x, direction_y, direction_z, dire = 1, 1, 1, 1
st = time.time()
direction_found = False
for dir, tx, ty, tz, te in generator:
if dir:
for direction, tx, ty, tz, te in generator:
if direction:
direction_found = True
dirx, diry, dirz, dire = tx, ty, tz, te
direction_x, direction_y, direction_z, dire = tx, ty, tz, te
if isinstance(generator, PulseGeneratorLinear):
assert (tx < 0 and delta.x < 0) or (tx > 0 and delta.x > 0) \
or delta.x == 0
assert (ty < 0 and delta.y < 0) or (ty > 0 and delta.y > 0) \
or delta.y == 0
assert (tz < 0 and delta.z < 0) or (tz > 0 and delta.z > 0) \
or delta.z == 0
assert (te < 0 and delta.e < 0) or (te > 0 and delta.e > 0) \
or delta.e == 0
assert ((tx < 0 and delta.x < 0) or (tx > 0 and delta.x > 0)
or delta.x == 0)
assert ((ty < 0 and delta.y < 0) or (ty > 0 and delta.y > 0)
or delta.y == 0)
assert ((tz < 0 and delta.z < 0) or (tz > 0 and delta.z > 0)
or delta.z == 0)
assert ((te < 0 and delta.e < 0) or (te > 0 and delta.e > 0)
or delta.e == 0)
continue
if tx is not None:
if tx > mx:
mx = tx
tx = int(round(tx * 1000000))
ix += dirx
ix += direction_x
cx += 1
if lx is not None:
dx = tx - lx
@@ -68,7 +67,7 @@ def move(generator):
if ty > my:
my = ty
ty = int(round(ty * 1000000))
iy += diry
iy += direction_y
cy += 1
if ly is not None:
dy = ty - ly
@@ -80,7 +79,7 @@ def move(generator):
if tz > mz:
mz = tz
tz = int(round(tz * 1000000))
iz += dirz
iz += direction_z
cz += 1
if lz is not None:
dz = tz - lz
@@ -101,7 +100,8 @@ def move(generator):
else:
de = None
# very verbose, uncomment on demand
# logging.debug("Iteration {} is {} {} {} {}".format(max(ix, iy, iz, ie), tx, ty, tz, te))
# logging.debug("Iteration {} is {} {} {} {}".
# format(max(ix, iy, iz, ie), tx, ty, tz, te))
f = list(x for x in (tx, ty, tz, te) if x is not None)
assert f.count(f[0]) == len(f), "fast forwarded pulse detected"
pt = time.time()
@@ -110,10 +110,11 @@ def move(generator):
assert iy / STEPPER_PULSES_PER_MM_Y == delta.y, "y wrong number of pulses"
assert iz / STEPPER_PULSES_PER_MM_Z == delta.z, "z wrong number of pulses"
assert ie / STEPPER_PULSES_PER_MM_E == delta.e, "e wrong number of pulses"
assert max(mx, my, mz, me) <= generator.total_time_s(), "interpolation time or pulses wrong"
assert max(mx, my, mz, me) <= generator.total_time_s(), \
"interpolation time or pulses wrong"
logging.debug("Moved {}, {}, {}, {} iterations".format(ix, iy, iz, ie))
logging.info("prepared in " + str(round(pt - st, 2)) \
+ "s, estimated " + str(round(generator.total_time_s(), 2)) + "s")
logging.info("prepared in " + str(round(pt - st, 2)) + "s, estimated "
+ str(round(generator.total_time_s(), 2)) + "s")
def join():