unit tests

This commit is contained in:
Nikolay Khabarov
2017-05-13 21:02:27 +03:00
parent bb0f74c6d9
commit dc90aab445
12 changed files with 512 additions and 6 deletions
+1
View File
@@ -1,3 +1,4 @@
from __future__ import division
import math
+2 -2
View File
@@ -33,7 +33,7 @@ class GCode(object):
return default
return float(self.params[argname]) * multiply
def getXYZ(self, default, multiply):
def coordinates(self, default, multiply):
""" Get X, Y and Z values as Coord object.
:param default: Default values, if any of coords is not specified.
:param multiply: If value exist, multiply it by this value.
@@ -44,7 +44,7 @@ class GCode(object):
z = self.get('Z', default.z, multiply)
return Coordinates(x, y, z)
def isXYZ(self):
def has_coordinates(self):
""" Check if at least one of the coordinates is present.
:return: Boolean value.
"""
+14 -4
View File
@@ -1,3 +1,4 @@
from __future__ import division
import time
import logging
@@ -69,6 +70,15 @@ class GMachine(object):
d = Coordinates(-self._position.x, -self._position.y, 0)
self._move(d, STEPPER_MAX_VELOCITY_MM_PER_MIN)
def position(self):
""" Return current machine position (after the latest command)
Note that hal might still be moving motors and in this case
function will block until motors stops.
This function for tests only.
"""
hal.join()
return self._position
def do_command(self, gcode):
""" Perform action.
:param gcode: GCode object which represent one gcode line
@@ -78,15 +88,15 @@ class GMachine(object):
logging.debug("got command " + str(gcode.params))
# read command
c = gcode.command()
if c is None and gcode.isXYZ():
if c is None and gcode.has_coordinates():
c = 'G1'
# read parameters
if self._absoluteCoordinates:
coord = gcode.getXYZ(self._position, self._convertCoordinates)
coord = gcode.coordinates(self._position, self._convertCoordinates)
coord = coord + self._local
delta = coord - self._position
else:
delta = gcode.getXYZ(Coordinates(0.0, 0.0, 0.0), self._convertCoordinates)
delta = gcode.coordinates(Coordinates(0.0, 0.0, 0.0), self._convertCoordinates)
coord = self._position + delta
velocity = gcode.get('F', self._velocity)
spindle_rpm = gcode.get('S', self._spindle_rpm)
@@ -118,7 +128,7 @@ class GMachine(object):
self._absoluteCoordinates = False
elif c == 'G92': # switch to local coords
self._local = self._position - \
gcode.getXYZ(Coordinates(0.0, 0.0, 0.0), self._convertCoordinates)
gcode.coordinates(Coordinates(0.0, 0.0, 0.0), self._convertCoordinates)
elif c == 'M3': # spinle on
self._spindle(spindle_rpm)
elif c == 'M5': # spindle off
+1
View File
@@ -1,3 +1,4 @@
from __future__ import division
import logging
import time