mirror of
https://github.com/sinseman44/PyCNC.git
synced 2026-07-16 08:37:09 +00:00
migration to a new hardware, adding additional configs
This commit is contained in:
+17
-7
@@ -1,16 +1,26 @@
|
||||
# Hardware limitations config
|
||||
STEPPER_PULSE_LENGTH_US = 2
|
||||
STEPPER_MAX_VELOCITY_MM_PER_MIN = 1800 # mm per min
|
||||
STEPPER_MAX_ACCELERATION_MM_PER_S2 = 200 # mm per sec^2
|
||||
STEPPER_MAX_ACCELERATION_MM_PER_S2 = 3000 # for all axis, mm per sec^2
|
||||
|
||||
STEPPER_PULSES_PER_MM_X = 400
|
||||
STEPPER_PULSES_PER_MM_Y = 400
|
||||
MAX_VELOCITY_MM_PER_MIN_X = 30000 # mm per min
|
||||
MAX_VELOCITY_MM_PER_MIN_Y = 24000 # mm per min
|
||||
MAX_VELOCITY_MM_PER_MIN_Z = 120 # mm per min
|
||||
MAX_VELOCITY_MM_PER_MIN_E = 1500 # mm per min
|
||||
|
||||
STEPPER_PULSES_PER_MM_X = 100
|
||||
STEPPER_PULSES_PER_MM_Y = 100
|
||||
STEPPER_PULSES_PER_MM_Z = 400
|
||||
STEPPER_PULSES_PER_MM_E = 80
|
||||
STEPPER_PULSES_PER_MM_E = 150
|
||||
|
||||
# invert axises direction
|
||||
STEPPER_INVERTED_X = True
|
||||
STEPPER_INVERTED_Y = False
|
||||
STEPPER_INVERTED_Z = False
|
||||
STEPPER_INVERTED_E = True
|
||||
|
||||
TABLE_SIZE_X_MM = 200
|
||||
TABLE_SIZE_Y_MM = 300
|
||||
TABLE_SIZE_Z_MM = 48
|
||||
TABLE_SIZE_Y_MM = 200
|
||||
TABLE_SIZE_Z_MM = 220
|
||||
|
||||
SPINDLE_MAX_RPM = 10000
|
||||
EXTRUDER_MAX_TEMPERATURE = 250
|
||||
|
||||
+56
-15
@@ -25,7 +25,6 @@ class GMachine(object):
|
||||
# init variables
|
||||
self._velocity = 0
|
||||
self._spindle_rpm = 0
|
||||
self._pause = 0
|
||||
self._local = None
|
||||
self._convertCoordinates = 0
|
||||
self._absoluteCoordinates = 0
|
||||
@@ -47,9 +46,11 @@ class GMachine(object):
|
||||
def reset(self):
|
||||
""" Reinitialize all program configurable thing.
|
||||
"""
|
||||
self._velocity = 1000
|
||||
self._velocity = min(MAX_VELOCITY_MM_PER_MIN_X,
|
||||
MAX_VELOCITY_MM_PER_MIN_Y,
|
||||
MAX_VELOCITY_MM_PER_MIN_Z,
|
||||
MAX_VELOCITY_MM_PER_MIN_E)
|
||||
self._spindle_rpm = 1000
|
||||
self._pause = 0
|
||||
self._local = Coordinates(0.0, 0.0, 0.0, 0.0)
|
||||
self._convertCoordinates = 1.0
|
||||
self._absoluteCoordinates = True
|
||||
@@ -96,6 +97,14 @@ class GMachine(object):
|
||||
TABLE_SIZE_Z_MM, 0)):
|
||||
raise GMachineException("out of effective area")
|
||||
|
||||
# noinspection PyMethodMayBeStatic
|
||||
def __check_velocity(self, max_velocity):
|
||||
if max_velocity.x > MAX_VELOCITY_MM_PER_MIN_X \
|
||||
or max_velocity.y > MAX_VELOCITY_MM_PER_MIN_Y \
|
||||
or max_velocity.z > MAX_VELOCITY_MM_PER_MIN_Z \
|
||||
or max_velocity.e > MAX_VELOCITY_MM_PER_MIN_E:
|
||||
raise GMachineException("out of maximum speed")
|
||||
|
||||
def _move_linear(self, delta, velocity):
|
||||
delta = delta.round(1.0 / STEPPER_PULSES_PER_MM_X,
|
||||
1.0 / STEPPER_PULSES_PER_MM_Y,
|
||||
@@ -103,10 +112,12 @@ class GMachine(object):
|
||||
1.0 / STEPPER_PULSES_PER_MM_E)
|
||||
if delta.is_zero():
|
||||
return
|
||||
velocity_per_axis = abs(delta) * (velocity / delta.length())
|
||||
self.__check_delta(delta)
|
||||
|
||||
logging.info("Moving linearly {}".format(delta))
|
||||
gen = PulseGeneratorLinear(delta, velocity)
|
||||
self.__check_velocity(gen.max_velocity())
|
||||
hal.move(gen)
|
||||
# save position
|
||||
self._position = self._position + delta
|
||||
@@ -212,14 +223,19 @@ class GMachine(object):
|
||||
direction, radius, velocity))
|
||||
gen = PulseGeneratorCircular(circle_end, radius, self._plane, direction,
|
||||
velocity)
|
||||
hal.move(gen)
|
||||
self.__check_velocity(gen.max_velocity())
|
||||
# if finish coords is not on circle, move some distance linearly
|
||||
linear_delta = delta - circle_end
|
||||
linear_gen = None
|
||||
if not linear_delta.is_zero():
|
||||
logging.info("Moving additionally {} to finish circle command".
|
||||
format(linear_delta))
|
||||
gen = PulseGeneratorLinear(linear_delta, velocity)
|
||||
hal.move(gen)
|
||||
linear_gen = PulseGeneratorLinear(linear_delta, velocity)
|
||||
self.__check_velocity(linear_gen.max_velocity())
|
||||
# do movements
|
||||
hal.move(gen)
|
||||
if linear_gen is not None:
|
||||
hal.move(linear_gen)
|
||||
# save position
|
||||
self._position = self._position + circle_end + linear_delta
|
||||
|
||||
@@ -227,9 +243,10 @@ class GMachine(object):
|
||||
""" Move head to park position
|
||||
"""
|
||||
d = Coordinates(0, 0, -self._position.z, 0)
|
||||
self._move_linear(d, STEPPER_MAX_VELOCITY_MM_PER_MIN)
|
||||
self._move_linear(d, MAX_VELOCITY_MM_PER_MIN_Z)
|
||||
d = Coordinates(-self._position.x, -self._position.y, 0, 0)
|
||||
self._move_linear(d, STEPPER_MAX_VELOCITY_MM_PER_MIN)
|
||||
self._move_linear(d, min(MAX_VELOCITY_MM_PER_MIN_X,
|
||||
MAX_VELOCITY_MM_PER_MIN_Y))
|
||||
|
||||
def position(self):
|
||||
""" Return current machine position (after the latest command)
|
||||
@@ -294,17 +311,37 @@ class GMachine(object):
|
||||
self._convertCoordinates)
|
||||
# coord = self._position + delta
|
||||
velocity = gcode.get('F', self._velocity)
|
||||
pause = gcode.get('P', self._pause)
|
||||
radius = gcode.radius(Coordinates(0.0, 0.0, 0.0, 0.0),
|
||||
self._convertCoordinates)
|
||||
# check parameters
|
||||
if velocity <= 0 or velocity > STEPPER_MAX_VELOCITY_MM_PER_MIN:
|
||||
raise GMachineException("bad feed speed")
|
||||
if pause < 0:
|
||||
raise GMachineException("bad delay")
|
||||
if velocity <= 0:
|
||||
raise GMachineException("negative feed speed")
|
||||
# select command and run it
|
||||
if c == 'G0': # rapid move
|
||||
self._move_linear(delta, STEPPER_MAX_VELOCITY_MM_PER_MIN)
|
||||
vl = max(MAX_VELOCITY_MM_PER_MIN_X,
|
||||
MAX_VELOCITY_MM_PER_MIN_Y,
|
||||
MAX_VELOCITY_MM_PER_MIN_Z,
|
||||
MAX_VELOCITY_MM_PER_MIN_E)
|
||||
l = delta.length()
|
||||
if l > 0:
|
||||
proportion = abs(delta) / l
|
||||
if proportion.x > 0:
|
||||
v = MAX_VELOCITY_MM_PER_MIN_X / proportion.x
|
||||
if v < vl:
|
||||
vl = v
|
||||
if proportion.y > 0:
|
||||
v = MAX_VELOCITY_MM_PER_MIN_Y / proportion.y
|
||||
if v < vl:
|
||||
vl = v
|
||||
if proportion.z > 0:
|
||||
v = MAX_VELOCITY_MM_PER_MIN_Z / proportion.z
|
||||
if v < vl:
|
||||
vl = v
|
||||
if proportion.e > 0:
|
||||
v = MAX_VELOCITY_MM_PER_MIN_E / proportion.e
|
||||
if v < vl:
|
||||
vl = v
|
||||
self._move_linear(delta, vl)
|
||||
elif c == 'G1': # linear interpolation
|
||||
self._move_linear(delta, velocity)
|
||||
elif c == 'G2': # circular interpolation, clockwise
|
||||
@@ -312,6 +349,11 @@ class GMachine(object):
|
||||
elif c == 'G3': # circular interpolation, counterclockwise
|
||||
self._circular(delta, radius, velocity, CCW)
|
||||
elif c == 'G4': # delay in s
|
||||
if not gcode.has('P'):
|
||||
raise GMachineException("P is not specified")
|
||||
pause = gcode.get('P', 0)
|
||||
if pause < 0:
|
||||
raise GMachineException("bad delay")
|
||||
hal.join()
|
||||
time.sleep(pause)
|
||||
elif c == 'G17': # XY plane select
|
||||
@@ -394,6 +436,5 @@ class GMachine(object):
|
||||
raise GMachineException("unknown command")
|
||||
# save parameters on success
|
||||
self._velocity = velocity
|
||||
self._pause = pause
|
||||
logging.debug("position {}".format(self._position))
|
||||
return answer
|
||||
|
||||
@@ -42,6 +42,8 @@ def init():
|
||||
gpio.clear(BED_HEATER_PIN)
|
||||
|
||||
# calibration
|
||||
# TODO remove this from hal and rewrite, check if there is a special g
|
||||
# command for this
|
||||
gpio.set(STEPPER_DIR_PIN_X)
|
||||
gpio.set(STEPPER_DIR_PIN_Y)
|
||||
gpio.set(STEPPER_DIR_PIN_Z)
|
||||
@@ -73,7 +75,10 @@ def init():
|
||||
break
|
||||
dma.run(False)
|
||||
# limit velocity at ~10% of top velocity
|
||||
time.sleep((1 / 0.10) / (STEPPER_MAX_VELOCITY_MM_PER_MIN
|
||||
time.sleep((1 / 0.10) / (min(MAX_VELOCITY_MM_PER_MIN_X,
|
||||
MAX_VELOCITY_MM_PER_MIN_Y,
|
||||
MAX_VELOCITY_MM_PER_MIN_Z,
|
||||
MAX_VELOCITY_MM_PER_MIN_E)
|
||||
/ 60 * max(STEPPER_PULSES_PER_MM_X,
|
||||
STEPPER_PULSES_PER_MM_Y,
|
||||
STEPPER_PULSES_PER_MM_Z)))
|
||||
|
||||
+19
-11
@@ -74,22 +74,30 @@ 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
|
||||
direction_x, direction_y, direction_z, dire = 1, 1, 1, 1
|
||||
direction_x, direction_y, direction_z, direction_e = 1, 1, 1, 1
|
||||
st = time.time()
|
||||
direction_found = False
|
||||
for direction, tx, ty, tz, te in generator:
|
||||
if direction:
|
||||
direction_found = True
|
||||
direction_x, direction_y, direction_z, dire = tx, ty, tz, te
|
||||
direction_x, direction_y, direction_z, direction_e = tx, ty, tz, te
|
||||
if STEPPER_INVERTED_X:
|
||||
direction_x = -direction_x
|
||||
if STEPPER_INVERTED_Y:
|
||||
direction_y = -direction_y
|
||||
if STEPPER_INVERTED_Z:
|
||||
direction_z = -direction_z
|
||||
if STEPPER_INVERTED_E:
|
||||
direction_e = -direction_e
|
||||
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 ((direction_x < 0 and delta.x < 0)
|
||||
or (direction_x > 0 and delta.x > 0) or delta.x == 0)
|
||||
assert ((direction_y < 0 and delta.y < 0)
|
||||
or (direction_y > 0 and delta.y > 0) or delta.y == 0)
|
||||
assert ((direction_z < 0 and delta.z < 0)
|
||||
or (direction_z > 0 and delta.z > 0) or delta.z == 0)
|
||||
assert ((direction_e < 0 and delta.e < 0)
|
||||
or (direction_e > 0 and delta.e > 0) or delta.e == 0)
|
||||
continue
|
||||
if tx is not None:
|
||||
if tx > mx:
|
||||
@@ -131,7 +139,7 @@ def move(generator):
|
||||
if te > me:
|
||||
me = te
|
||||
te = int(round(te * 1000000))
|
||||
ie += dire
|
||||
ie += direction_e
|
||||
ce += 1
|
||||
if le is not None:
|
||||
de = te - le
|
||||
|
||||
+42
-10
@@ -86,7 +86,7 @@ class PulseGenerator(object):
|
||||
(self._acceleration_time_s, self._linear_time_s,
|
||||
max_axis_velocity_mm_per_sec) = self._get_movement_parameters()
|
||||
# helper variable
|
||||
self._2Vmax_per_a = (2.0 * max_axis_velocity_mm_per_sec
|
||||
self._2Vmax_per_a = (2.0 * max_axis_velocity_mm_per_sec.find_max()
|
||||
/ STEPPER_MAX_ACCELERATION_MM_PER_S2)
|
||||
self._iteration_x = 0
|
||||
self._iteration_y = 0
|
||||
@@ -152,7 +152,16 @@ class PulseGenerator(object):
|
||||
# check if direction update:
|
||||
if direction != self._iteration_direction:
|
||||
self._iteration_direction = direction
|
||||
return (True,) + direction
|
||||
dir_x, dir_y, dir_z, dir_e = direction
|
||||
if STEPPER_INVERTED_X:
|
||||
dir_x = -dir_x
|
||||
if STEPPER_INVERTED_Y:
|
||||
dir_y = -dir_y
|
||||
if STEPPER_INVERTED_Z:
|
||||
dir_z = -dir_z
|
||||
if STEPPER_INVERTED_E:
|
||||
dir_e = -dir_e
|
||||
return True, dir_x, dir_y, dir_z, dir_e
|
||||
# check condition to stop
|
||||
if tx is None and ty is None and tz is None and te is None:
|
||||
raise StopIteration
|
||||
@@ -204,6 +213,13 @@ class PulseGenerator(object):
|
||||
"""
|
||||
return self._delta
|
||||
|
||||
def max_velocity(self):
|
||||
""" Get max velocity for each axis.
|
||||
:return: Vector with max velocity(in mm per min) for each axis.
|
||||
"""
|
||||
_, _, v = self._get_movement_parameters()
|
||||
return v * SECONDS_IN_MINUTE
|
||||
|
||||
|
||||
class PulseGeneratorLinear(PulseGenerator):
|
||||
def __init__(self, delta_mm, velocity_mm_per_min):
|
||||
@@ -253,7 +269,7 @@ class PulseGeneratorLinear(PulseGenerator):
|
||||
"""
|
||||
return (self.acceleration_time_s,
|
||||
self.linear_time_s,
|
||||
self.max_velocity_mm_per_sec.find_max())
|
||||
self.max_velocity_mm_per_sec)
|
||||
|
||||
@staticmethod
|
||||
def __linear(i, pulses_per_mm, total_pulses, velocity_mm_per_sec):
|
||||
@@ -431,8 +447,10 @@ class PulseGeneratorCircular(PulseGenerator):
|
||||
self._iterations_a += round(radius * apm)
|
||||
self._iterations_b += round(radius * bpm)
|
||||
if direction == CCW:
|
||||
self._iterations_a = 4 * round(radius * apm) - self._iterations_a
|
||||
self._iterations_b = 4 * round(radius * bpm) - self._iterations_b
|
||||
self._iterations_a = (4 * round(radius * apm)
|
||||
- self._iterations_a)
|
||||
self._iterations_b = (4 * round(radius * bpm)
|
||||
- self._iterations_b)
|
||||
|
||||
arc = delta_angle * radius
|
||||
e2 = delta.e * delta.e
|
||||
@@ -472,19 +490,33 @@ class PulseGeneratorCircular(PulseGenerator):
|
||||
self._e_velocity = abs(delta.e) / l * velocity
|
||||
self._r_div_v = radius / circular_velocity
|
||||
self._e_dir = math.copysign(1, delta.e)
|
||||
self.max_velocity_mm_per_sec = max(circular_velocity,
|
||||
self._velocity_3rd, self._e_velocity)
|
||||
self.acceleration_time_s = (self.max_velocity_mm_per_sec
|
||||
if self._plane == PLANE_XY:
|
||||
self.max_velocity_mm_per_sec = Coordinates(circular_velocity,
|
||||
circular_velocity,
|
||||
self._velocity_3rd,
|
||||
self._e_velocity)
|
||||
elif self._plane == PLANE_YZ:
|
||||
self.max_velocity_mm_per_sec = Coordinates(self._velocity_3rd,
|
||||
circular_velocity,
|
||||
circular_velocity,
|
||||
self._e_velocity)
|
||||
elif self._plane == PLANE_ZX:
|
||||
self.max_velocity_mm_per_sec = Coordinates(circular_velocity,
|
||||
self._velocity_3rd,
|
||||
circular_velocity,
|
||||
self._e_velocity)
|
||||
self.acceleration_time_s = (self.max_velocity_mm_per_sec.find_max()
|
||||
/ STEPPER_MAX_ACCELERATION_MM_PER_S2)
|
||||
if l == 0:
|
||||
self.linear_time_s = 0.0
|
||||
self.max_velocity_mm_per_sec = 0
|
||||
self.max_velocity_mm_per_sec = Coordinates(0, 0, 0, 0)
|
||||
elif STEPPER_MAX_ACCELERATION_MM_PER_S2 * self.acceleration_time_s \
|
||||
** 2 > l:
|
||||
self.acceleration_time_s = \
|
||||
math.sqrt(l / STEPPER_MAX_ACCELERATION_MM_PER_S2)
|
||||
self.linear_time_s = 0.0
|
||||
self.max_velocity_mm_per_sec = l / self.acceleration_time_s
|
||||
v = l / self.acceleration_time_s
|
||||
self.max_velocity_mm_per_sec = Coordinates(v, v, v, v)
|
||||
else:
|
||||
linear_distance_mm = l - self.acceleration_time_s ** 2 \
|
||||
* STEPPER_MAX_ACCELERATION_MM_PER_S2
|
||||
|
||||
Reference in New Issue
Block a user