Fixed a disconnect but, and unhoming on failed probe

This commit is contained in:
David Carley
2021-10-21 19:25:27 -07:00
parent 2571475700
commit 3710a3e1f6
6 changed files with 61 additions and 29 deletions

View File

@@ -10,6 +10,7 @@
"jstransformer-escape-html": "", "jstransformer-escape-html": "",
"jstransformer-stylus": "", "jstransformer-stylus": "",
"lodash.merge": "4.6.2", "lodash.merge": "4.6.2",
"lodash.omit": "^4.5.0",
"pug-cli": "" "pug-cli": ""
} }
} }

View File

@@ -27,9 +27,10 @@
'use strict' 'use strict'
var api = require('./api'); const api = require('./api');
var cookie = require('./cookie')('bbctrl-'); const cookie = require('./cookie')('bbctrl-');
var Sock = require('./sock'); const Sock = require('./sock');
const omit = require('lodash.omit');
function is_newer_version(current, latest) { function is_newer_version(current, latest) {
const pattern = /(\d+)\.(\d+)\.(\d+)(.*)/; const pattern = /(\d+)\.(\d+)\.(\d+)(.*)/;
@@ -385,10 +386,10 @@ module.exports = new Vue({
} }
if ('log' in e.data) { if ('log' in e.data) {
if (this.state.probing_active && e.data.log.msg === "Switch not found") { if (e.data.log.msg === "Switch not found") {
this.$broadcast('probing_failed'); this.$broadcast('probing_failed');
} else { } else {
this.$broadcast('log', JSON.stringify(e.data.log, null, 4)); this.$broadcast('log', e.data.log);
} }
delete e.data.log; delete e.data.log;
@@ -407,6 +408,25 @@ module.exports = new Vue({
} }
} }
// Set this to true to get console output of changes to the state
const debugStateChanges = false;
if (debugStateChanges) {
const data = omit(e.data, [
'vdd',
'vin',
'vout',
'motor',
'temp',
'heartbeat',
'load1',
'load2',
'rpi_temp'
]);
if (Object.keys(data).length > 0) {
console.log(JSON.stringify(data, null, 4));
}
}
update_object(this.state, e.data, false); update_object(this.state, e.data, false);
if (this.state.pw === 0) { if (this.state.pw === 0) {

View File

@@ -182,7 +182,7 @@ html(lang="en")
p This process should take less than 5 minutes. If it takes longer than this, please restart the controller and try via USB. p This process should take less than 5 minutes. If it takes longer than this, please restart the controller and try via USB.
div(slot="footer") div(slot="footer")
message(v-if="popupMessages.length", :show="true") message(v-if="popupMessages.length", show=true)
h3(slot="header") GCode message h3(slot="header") GCode message
div(slot="body") div(slot="body")

View File

@@ -136,7 +136,7 @@ class Mach(Comm):
def process_log(self, log): def process_log(self, log):
# Detect when a probe has failed, and reset the planner # Detect when a probe has failed, and reset the planner
if log['msg'] == 'Switch not found': if log['msg'] == 'Switch not found':
self.planner.reset(False) self.planner.reset(stop = False, resetState = False)
def _update(self, update): def _update(self, update):
@@ -152,7 +152,7 @@ class Mach(Comm):
# Handle EStop # Handle EStop
if state_changed and state == 'ESTOPPED': if state_changed and state == 'ESTOPPED':
self.planner.reset(False) self.planner.reset(stop = False)
# Exit cycle if state changed to READY # Exit cycle if state changed to READY
if (state_changed and self._get_cycle() != 'idle' and if (state_changed and self._get_cycle() != 'idle' and
@@ -201,9 +201,6 @@ class Mach(Comm):
self.unpausing = True self.unpausing = True
def _reset(self): self.planner.reset()
def _i2c_block(self, block): def _i2c_block(self, block):
super().i2c_command(block[0], block = block[1:]) super().i2c_command(block[0], block = block[1:])
@@ -218,12 +215,13 @@ class Mach(Comm):
@overrides(Comm) @overrides(Comm)
def comm_error(self): self._reset() def comm_error(self):
self.planner.reset()
@overrides(Comm) @overrides(Comm)
def connect(self): def connect(self):
self._reset() self.planner.reset()
super().connect() super().connect()
@@ -246,14 +244,17 @@ class Mach(Comm):
def mdi(self, cmd, with_limits = True): def mdi(self, cmd, with_limits = True):
if not len(cmd): return try:
if cmd[0] == '$': self._query_var(cmd) if not len(cmd): return
elif cmd[0] == '\\': super().queue_command(cmd[1:]) if cmd[0] == '$': self._query_var(cmd)
else: elif cmd[0] == '\\': super().queue_command(cmd[1:])
self._begin_cycle('mdi') else:
self.planner.mdi(cmd, with_limits) self._begin_cycle('mdi')
super().resume() self.planner.mdi(cmd, with_limits)
super().resume()
except BaseException as err:
self.mlog.info("Exception during MDI: %s" % err)
pass
def set(self, code, value): def set(self, code, value):
super().queue_command('${}={}'.format(code, value)) super().queue_command('${}={}'.format(code, value))
@@ -312,7 +313,7 @@ class Mach(Comm):
def clear(self): def clear(self):
if self._is_estopped(): if self._is_estopped():
self._reset() self.planner.reset()
super().clear() super().clear()

View File

@@ -64,7 +64,7 @@ class Planner():
ctrl.state.add_listener(self._update) ctrl.state.add_listener(self._update)
self.reset(False) self.reset(stop = False)
self._report_time() self._report_time()
@@ -324,8 +324,11 @@ class Planner():
self.planner.set_logger(None) self.planner.set_logger(None)
def reset(self, stop = True): def reset(self, *args, **kwargs):
if stop: self.ctrl.mach.stop() stop = kwargs.get('stop', True)
if stop:
self.ctrl.mach.stop()
self.planner = gplan.Planner() self.planner = gplan.Planner()
self.planner.set_resolver(self._get_var_cb) self.planner.set_resolver(self._get_var_cb)
# TODO logger is global and will not work correctly in demo mode # TODO logger is global and will not work correctly in demo mode
@@ -333,7 +336,10 @@ class Planner():
self._position_dirty = True self._position_dirty = True
self.cmdq.clear() self.cmdq.clear()
self.reset_times() self.reset_times()
self.ctrl.state.reset()
resetState = kwargs.get('resetState', True)
if resetState:
self.ctrl.state.reset()
def mdi(self, cmd, with_limits = True): def mdi(self, cmd, with_limits = True):

View File

@@ -441,7 +441,8 @@ class ClientConnection(object):
self.app.closed(self.ctrl) self.app.closed(self.ctrl)
def on_message(self, data): self.ctrl.mach.mdi(data) def on_message(self, data):
self.ctrl.mach.mdi(data)
# Used by CAMotics # Used by CAMotics
@@ -451,8 +452,11 @@ class WSConnection(ClientConnection, tornado.websocket.WebSocketHandler):
tornado.websocket.WebSocketHandler.__init__( tornado.websocket.WebSocketHandler.__init__(
self, app, request, **kwargs) self, app, request, **kwargs)
def send(self, msg): self.write_message(msg) def send(self, msg):
def open(self): self.on_open() self.write_message(msg)
def open(self):
self.on_open()
# Used by Web frontend # Used by Web frontend