From: Joseph Coffland Date: Thu, 8 Sep 2016 07:29:56 +0000 (-0700) Subject: Fixed GCode EOF, Implemented axis zeroing X-Git-Url: https://git.buildbotics.com/?a=commitdiff_plain;h=80d11babf0fc19ca38444aa5a6fd9c5fa3b9c1ac;p=bbctrl-firmware Fixed GCode EOF, Implemented axis zeroing --- diff --git a/src/js/axis-control.js b/src/js/axis-control.js index 78434fe..a8c2427 100644 --- a/src/js/axis-control.js +++ b/src/js/axis-control.js @@ -9,16 +9,6 @@ module.exports = { methods: { jog: function (axis, move) { this.$dispatch('jog', this.axes[axis], move) - }, - - - home: function (axis) { - this.$dispatch('home', this.axes[axis]) - }, - - - zero: function (axis) { - this.$dispatch('zero', this.axes[axis]) } } } diff --git a/src/js/control-view.js b/src/js/control-view.js index f958b0a..1aba590 100644 --- a/src/js/control-view.js +++ b/src/js/control-view.js @@ -35,9 +35,7 @@ module.exports = { events: { // TODO These should all be implemented via the API - jog: function (axis, move) {this.send('g91 g0' + axis + move)}, - home: function (axis) {this.send('$home ' + axis)}, - zero: function (axis) {this.send('$zero ' + axis)} + jog: function (axis, move) {this.send('g91 g0' + axis + move)} }, @@ -136,6 +134,11 @@ module.exports = { home: function () {api.put('home')}, + zero: function (axis) { + api.put('zero' + (typeof axis == 'undefined' ? '' : '/' + axis)); + }, + + start_pause: function () { if (this.state.x == 'RUNNING') this.pause(); diff --git a/src/py/bbctrl/AVR.py b/src/py/bbctrl/AVR.py index cb4a799..3ee8ab6 100644 --- a/src/py/bbctrl/AVR.py +++ b/src/py/bbctrl/AVR.py @@ -27,6 +27,7 @@ I2C_FLUSH = 7 I2C_REPORT = 8 I2C_HOME = 9 I2C_REBOOT = 10 +I2C_ZERO = 11 class AVR(): @@ -60,6 +61,8 @@ class AVR(): self.i2c_bus = None log.warning('Failed to open device: %s', e) + # Reset AVR communication + self.stop(); self.report() @@ -77,7 +80,7 @@ class AVR(): self.stream = None - def _i2c_command(self, cmd, word = None): + def _i2c_command(self, cmd, byte = None, word = None): if self.i2c_bus is None: return log.info('I2C: %d' % cmd) @@ -85,9 +88,13 @@ class AVR(): while True: try: - if word is not None: + if byte is not None: + self.i2c_bus.write_byte_data(self.i2c_addr, cmd, byte) + + elif word is not None: self.i2c_bus.write_word_data(self.i2c_addr, cmd, word) - self.i2c_bus.write_byte(self.i2c_addr, cmd) + + else: self.i2c_bus.write_byte(self.i2c_addr, cmd) break except IOError as e: @@ -180,7 +187,7 @@ class AVR(): if 'firmware' in msg: log.error('AVR rebooted') - self._stop_sending_gcode() + self.stop(); self.report() if 'x' in msg and msg['x'] == 'ESTOPPED': @@ -242,3 +249,4 @@ class AVR(): def unpause(self): self._i2c_command(I2C_RUN) def optional_pause(self): self._i2c_command(I2C_OPTIONAL_PAUSE) def step(self): self._i2c_command(I2C_STEP) + def zero(self, axis = None): self._i2c_command(I2C_ZERO, byte = axis) diff --git a/src/py/bbctrl/GCodeStream.py b/src/py/bbctrl/GCodeStream.py index d2d2e5f..5beb15b 100644 --- a/src/py/bbctrl/GCodeStream.py +++ b/src/py/bbctrl/GCodeStream.py @@ -39,7 +39,7 @@ class GCodeStream(): def next(self): line = self.f.readline() - if line is None: return + if line is None or line == '': return # Remove comments line = self.comment1RE.sub('', line) diff --git a/src/py/bbctrl/Web.py b/src/py/bbctrl/Web.py index f87d14b..8877cc3 100644 --- a/src/py/bbctrl/Web.py +++ b/src/py/bbctrl/Web.py @@ -56,6 +56,12 @@ class StepHandler(bbctrl.APIHandler): def put_ok(self): self.ctrl.avr.step() +class ZeroHandler(bbctrl.APIHandler): + def put_ok(self, axis): + if axis is not None: axis = ord(axis[1:].lower()) + self.ctrl.avr.zero(axis) + + class OverrideFeedHandler(bbctrl.APIHandler): def put_ok(self, value): self.ctrl.avr.override_feed(float(value)) @@ -110,6 +116,7 @@ class Web(tornado.web.Application): (r'/api/unpause', UnpauseHandler), (r'/api/pause/optional', OptionalPauseHandler), (r'/api/step', StepHandler), + (r'/api/zero(/[xyzabcXYZABC])?', ZeroHandler), (r'/api/override/feed/([\d.]+)', OverrideFeedHandler), (r'/api/override/speed/([\d.]+)', OverrideSpeedHandler), (r'/(.*)', tornado.web.StaticFileHandler,