From 768d76c43ab11c584f063983e7a09877e2713b50 Mon Sep 17 00:00:00 2001 From: Michael Fogleman Date: Sun, 15 Jan 2017 20:28:07 -0500 Subject: [PATCH] axi main --- axi/device.py | 29 +++++++++++++++++++++++++++-- axi/main.py | 39 +++++++++++++++++++++++++++++++++++++++ setup.py | 5 +++++ 3 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 axi/main.py diff --git a/axi/device.py b/axi/device.py index 4e3428d..0143cb1 100644 --- a/axi/device.py +++ b/axi/device.py @@ -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() diff --git a/axi/main.py b/axi/main.py new file mode 100644 index 0000000..8a492f3 --- /dev/null +++ b/axi/main.py @@ -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() diff --git a/setup.py b/setup.py index a0f6596..68797cd 100644 --- a/setup.py +++ b/setup.py @@ -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',