split pulses per mm parameter for each axis

This commit is contained in:
Nikolay Khabarov
2017-05-27 03:53:30 +03:00
parent 0de4f3dc00
commit 665ba2ad1e
8 changed files with 47 additions and 30 deletions
+4 -1
View File
@@ -2,7 +2,10 @@
STEPPER_PULSE_LINGTH_US = 2
STEPPER_MAX_VELOCITY_MM_PER_MIN = 1800 # mm per min
STEPPER_MAX_ACCELERATION_MM_PER_S2 = 200 # mm per sec^2
STEPPER_PULSES_PER_MM = 400
STEPPER_PULSES_PER_MM_X = 400
STEPPER_PULSES_PER_MM_Y = 400
STEPPER_PULSES_PER_MM_Z = 400
TABLE_SIZE_X_MM = 200
TABLE_SIZE_Y_MM = 300
+7 -5
View File
@@ -44,14 +44,16 @@ class Coordinates(object):
"""
return math.sqrt(self.x * self.x + self.y * self.y + self.z * self.z)
def round(self, base):
def round(self, base_x, base_y, base_z):
""" Round values to specified base, ie 0.49 with base 0.25 will be 0.5.
:param base: Base.
:param base_x: Base for x axis.
:param base_y: Base for y axis.
:param base_z: Base for z axis.
:return: New rounded object.
"""
return Coordinates(round(self.x / base) * base,
round(self.y / base) * base,
round(self.z / base) * base)
return Coordinates(round(self.x / base_x) * base_x,
round(self.y / base_y) * base_y,
round(self.z / base_z) * base_z)
def find_max(self):
""" Find a maximum value of all values.
+9 -3
View File
@@ -65,7 +65,9 @@ class GMachine(object):
raise GMachineException("out of effective area")
def _move_linear(self, delta, velocity):
delta = delta.round(1.0 / STEPPER_PULSES_PER_MM)
delta = delta.round(1.0 / STEPPER_PULSES_PER_MM_X,
1.0 / STEPPER_PULSES_PER_MM_Y,
1.0 / STEPPER_PULSES_PER_MM_Z)
if delta.is_zero():
return
self.__check_delta(delta)
@@ -126,7 +128,9 @@ class GMachine(object):
return ea, eb
def _circular(self, delta, radius, velocity, direction):
delta = delta.round(1.0 / STEPPER_PULSES_PER_MM)
delta = delta.round(1.0 / STEPPER_PULSES_PER_MM_X,
1.0 / STEPPER_PULSES_PER_MM_Y,
1.0 / STEPPER_PULSES_PER_MM_Z)
self.__check_delta(delta)
# get delta vector and put it on circle
circle_end = Coordinates(0,0,0)
@@ -148,7 +152,9 @@ class GMachine(object):
self._position.z, self._position.x,
TABLE_SIZE_Z_MM, TABLE_SIZE_X_MM)
circle_end.y = delta.y
circle_end = circle_end.round(1.0 / STEPPER_PULSES_PER_MM)
circle_end = circle_end.round(1.0 / STEPPER_PULSES_PER_MM_X,
1.0 / STEPPER_PULSES_PER_MM_Y,
1.0 / STEPPER_PULSES_PER_MM_Z)
hal.move_circular(circle_end, radius, self._plane, velocity, direction)
# if finish coords is not on circle, move some distance linearly
linear_delta = delta - circle_end
+9 -3
View File
@@ -52,8 +52,12 @@ def init():
dma.clear()
dma.add_pulse(pins, STEPPER_PULSE_LINGTH_US)
st = time.time()
max_pulses_left = int(1.2 * STEPPER_PULSES_PER_MM * max(
TABLE_SIZE_X_MM, TABLE_SIZE_Y_MM, TABLE_SIZE_Z_MM))
max_pulses_left = int(1.2 * max(STEPPER_PULSES_PER_MM_X,
STEPPER_PULSES_PER_MM_Y,
STEPPER_PULSES_PER_MM_Z) *
max(TABLE_SIZE_X_MM,
TABLE_SIZE_Y_MM,
TABLE_SIZE_Z_MM))
try:
while max_pulses_left > 0:
if (STEP_PIN_MASK_X & pins) != 0 and gpio.read(ENDSTOP_PIN_X) == 0:
@@ -73,7 +77,9 @@ def init():
dma.run(False)
# limit velocity at ~10% of top velocity
time.sleep((1 / 0.10) / (STEPPER_MAX_VELOCITY_MM_PER_MIN
/ 60 * STEPPER_PULSES_PER_MM))
/ 60 * max(STEPPER_PULSES_PER_MM_X,
STEPPER_PULSES_PER_MM_Y,
STEPPER_PULSES_PER_MM_Z)))
max_pulses_left -= 1
if st is not None:
if time.time() - st > 2:
+3 -3
View File
@@ -76,9 +76,9 @@ def move_linear(delta, velocity):
f = list(x for x in (tx, ty, tz) if x is not None)
assert f.count(f[0]) == len(f), "fast forwarded pulse detected"
pt = time.time()
assert ix / STEPPER_PULSES_PER_MM == abs(delta.x), "x wrong number of pulses"
assert iy / STEPPER_PULSES_PER_MM == abs(delta.y), "y wrong number of pulses"
assert iz / STEPPER_PULSES_PER_MM == abs(delta.z), "z wrong number of pulses"
assert ix / STEPPER_PULSES_PER_MM_X == abs(delta.x), "x wrong number of pulses"
assert iy / STEPPER_PULSES_PER_MM_Y == abs(delta.y), "y wrong number of pulses"
assert iz / STEPPER_PULSES_PER_MM_Z == abs(delta.z), "z wrong number of pulses"
assert max(mx, my, mz) <= generator.total_time_s(), "interpolation time or pulses wrong"
logging.debug("Did {}, {}, {} iterations".format(ix, iy, iz))
logging.info("prepared in " + str(round(pt - st, 2)) \
+3 -3
View File
@@ -216,10 +216,10 @@ class PulseGeneratorLinear(PulseGenerator):
""" Calculate interpolation values for linear movement, see super class
for details.
"""
t_x = self.__linear(ix / STEPPER_PULSES_PER_MM, self._distance_mm.x,
t_x = self.__linear(ix / STEPPER_PULSES_PER_MM_X, self._distance_mm.x,
self.max_velocity_mm_per_sec.x)
t_y = self.__linear(iy / STEPPER_PULSES_PER_MM, self._distance_mm.y,
t_y = self.__linear(iy / STEPPER_PULSES_PER_MM_Y, self._distance_mm.y,
self.max_velocity_mm_per_sec.y)
t_z = self.__linear(iz / STEPPER_PULSES_PER_MM, self._distance_mm.z,
t_z = self.__linear(iz / STEPPER_PULSES_PER_MM_Z, self._distance_mm.z,
self.max_velocity_mm_per_sec.z)
return t_x, t_y, t_z