This commit is contained in:
Michael Fogleman 2017-01-15 20:28:07 -05:00
parent 44d5a3fcdf
commit 768d76c43a
3 changed files with 71 additions and 2 deletions

View File

@ -89,6 +89,18 @@ class Device(object):
self.serial.write(line + '\r')
return self.readline()
# higher level functions
def move(self, dx, dy):
self.run_path([(0, 0), (dx, dy)])
def goto(self, x, y):
px, py = self.read_position()
self.run_path([(px, py), (x, y)])
def home(self):
self.goto(0, 0)
# misc commands
def version(self):
return self.command('V')
@ -103,7 +115,20 @@ class Device(object):
def motor_status(self):
return self.command('QM')
def move(self, duration, a, b):
def zero_position(self):
return self.command('CS')
def read_position(self):
response = self.command('QS')
self.readline()
a, b = map(int, response.split(','))
a /= self.steps_per_unit
b /= self.steps_per_unit
y = (a - b) / 2
x = y + b
return x, y
def stepper_move(self, duration, a, b):
return self.command('XM', duration, a, b)
def wait(self):
@ -122,7 +147,7 @@ class Device(object):
ex, sx = modf(d.x * self.steps_per_unit + ex)
ey, sy = modf(d.y * self.steps_per_unit + ey)
self.error = ex, ey
self.move(step_ms, int(sx), int(sy))
self.stepper_move(step_ms, int(sx), int(sy))
t += step_s
self.wait()

39
axi/main.py Normal file
View File

@ -0,0 +1,39 @@
import axi
import sys
'''
TODO:
axi draw FILE
axi (repl)
'''
def main():
args = sys.argv[1:]
if len(args) == 0:
return
command, args = args[0], args[1:]
command = command.lower()
device = axi.Device()
if command == 'zero':
device.zero_position()
elif command == 'home':
device.home()
elif command == 'up':
device.pen_up()
elif command == 'down':
device.pen_down()
elif command == 'on':
device.enable_motors()
elif command == 'off':
device.disable_motors()
elif command == 'move':
dx, dy = map(float, args)
device.move(dx, dy)
elif command == 'goto':
x, y = map(float, args)
device.goto(x, y)
else:
pass
if __name__ == '__main__':
main()

View File

@ -8,6 +8,11 @@ setup(
author_email='michael.fogleman@gmail.com',
packages=['axi'],
install_requires=['pyserial', 'shapely'],
entry_points={
'console_scripts': [
'axi = axi.main:main'
]
},
license='MIT',
classifiers=(
'Development Status :: 3 - Alpha',