fix issue with g0 velocity and g92 command

This commit is contained in:
Nikolay Khabarov
2017-07-02 03:48:04 +03:00
parent 5b9c0de25e
commit 9c4277e228
3 changed files with 35 additions and 14 deletions

View File

@@ -313,7 +313,8 @@ class GMachine(object):
c = 'G1'
# read parameters
if self._absoluteCoordinates:
coord = gcode.coordinates(self._position, self._convertCoordinates)
coord = gcode.coordinates(self._position - self._local,
self._convertCoordinates)
coord = coord + self._local
delta = coord - self._position
else:
@@ -336,19 +337,19 @@ class GMachine(object):
if l > 0:
proportion = abs(delta) / l
if proportion.x > 0:
v = MAX_VELOCITY_MM_PER_MIN_X / proportion.x
v = int(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
v = int(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
v = int(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
v = int(MAX_VELOCITY_MM_PER_MIN_E / proportion.e)
if v < vl:
vl = v
self._move_linear(delta, vl)
@@ -391,9 +392,15 @@ class GMachine(object):
elif c == 'G91': # switch to relative coords
self._absoluteCoordinates = False
elif c == 'G92': # switch to local coords
self._local = self._position - \
gcode.coordinates(Coordinates(0.0, 0.0, 0.0, 0.0),
self._convertCoordinates)
if gcode.has_coordinates():
self._local = self._position - gcode.coordinates(
Coordinates(self._position.x - self._local.x,
self._position.y - self._local.y,
self._position.z - self._local.z,
self._position.e - self._local.e),
self._convertCoordinates)
else:
self._local = self._position
elif c == 'M3': # spindle on
spindle_rpm = gcode.get('S', self._spindle_rpm)
if spindle_rpm < 0 or spindle_rpm > SPINDLE_MAX_RPM:

View File

@@ -165,10 +165,14 @@ def move(generator):
assert f.count(f[0]) == len(f), "fast forwarded pulse detected"
pt = time.time()
assert direction_found, "direction not found"
assert ix / STEPPER_PULSES_PER_MM_X == delta.x, "x wrong number of pulses"
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 round(ix / STEPPER_PULSES_PER_MM_X, 10) == delta.x,\
"x wrong number of pulses"
assert round(iy / STEPPER_PULSES_PER_MM_Y, 10) == delta.y,\
"y wrong number of pulses"
assert round(iz / STEPPER_PULSES_PER_MM_Z, 10) == delta.z, \
"z wrong number of pulses"
assert round(ie / STEPPER_PULSES_PER_MM_E, 10) == delta.e, \
"e wrong number of pulses"
assert max(mx, my, mz, me) <= generator.total_time_s(), \
"interpolation time or pulses wrong"
logging.debug("Moved {}, {}, {}, {} iterations".format(ix, iy, iz, ie))

View File

@@ -56,6 +56,8 @@ class TestGMachine(unittest.TestCase):
# Test gcode commands.
def test_g0_g1(self):
m = GMachine()
m.do_command(GCode.parse_line("G0X10Y10Z11"))
self.assertEqual(m.position(), Coordinates(10, 10, 11, 0))
m.do_command(GCode.parse_line("G0X3Y2Z1E-2"))
self.assertEqual(m.position(), Coordinates(3, 2, 1, -2))
m.do_command(GCode.parse_line("G1X1Y2Z3E4"))
@@ -185,7 +187,7 @@ class TestGMachine(unittest.TestCase):
m.do_command(GCode.parse_line("X1Y1Z1E1"))
self.assertEqual(m.position(), Coordinates(1, 1, 1, 1))
def test_g90_g92(self):
def test_g53_g92(self):
m = GMachine()
m.do_command(GCode.parse_line("G92X100Y100Z100E100"))
m.do_command(GCode.parse_line("X101Y102Z103E104"))
@@ -196,9 +198,17 @@ class TestGMachine(unittest.TestCase):
m.do_command(GCode.parse_line("G92X3Y4Z5E6"))
m.do_command(GCode.parse_line("X0Y0Z0E0"))
self.assertEqual(m.position(), Coordinates(0, 0, 0, 0))
m.do_command(GCode.parse_line("G90"))
m.do_command(GCode.parse_line("X1Y2Z3E4"))
self.assertEqual(m.position(), Coordinates(1, 2, 3, 4))
m.do_command(GCode.parse_line("G53"))
m.do_command(GCode.parse_line("X6Y7Z8E9"))
self.assertEqual(m.position(), Coordinates(6, 7, 8, 9))
m.do_command(GCode.parse_line("G92E0"))
m.do_command(GCode.parse_line("X6Y7Z8E1"))
self.assertEqual(m.position(), Coordinates(6, 7, 8, 10))
m.do_command(GCode.parse_line("G92"))
m.do_command(GCode.parse_line("X1Y1Z1E1"))
self.assertEqual(m.position(), Coordinates(7, 8, 9, 11))
def test_g53_g91_g92(self):
m = GMachine()