From: Joseph Coffland Date: Fri, 16 Nov 2018 20:41:32 +0000 (-0800) Subject: Don't output NaN or Infinity in JSON, improvements to plan cancel. X-Git-Url: https://git.buildbotics.com/?a=commitdiff_plain;h=2b8b6e097d64fd18e2d009dddff3c73850b15f17;p=bbctrl-firmware Don't output NaN or Infinity in JSON, improvements to plan cancel. --- diff --git a/src/js/path-viewer.js b/src/js/path-viewer.js index 2ac7082..7f07777 100644 --- a/src/js/path-viewer.js +++ b/src/js/path-viewer.js @@ -351,6 +351,8 @@ module.exports = { var size = bbox.getSize(new THREE.Vector3()); var length = (size.x + size.y + size.z) / 24; + if (length < 1) length = 1; + var material = new THREE.MeshPhongMaterial({ transparent: true, opacity: 0.75, @@ -402,6 +404,9 @@ module.exports = { var size = bbox.getSize(new THREE.Vector3()); var length = (size.x + size.y + size.z) / 3; length /= 10; + + if (length < 1) length = 1; + var radius = length / 20; var group = new THREE.Group(); @@ -592,10 +597,15 @@ module.exports = { get_model_bounds: function () { - var bbox = new THREE.Box3(); + var bbox = new THREE.Box3(new THREE.Vector3(0, 0, 0), + new THREE.Vector3(0.00001, 0.00001, 0.00001)); function add(o) { - if (typeof o != 'undefined') bbox.union(o.geometry.boundingBox); + if (typeof o != 'undefined') { + var oBBox = new THREE.Box3(); + oBBox.setFromObject(o); + bbox.union(oBBox); + } } add(this.pathView); diff --git a/src/py/bbctrl/Camera.py b/src/py/bbctrl/Camera.py index 9f7a3da..98a0403 100755 --- a/src/py/bbctrl/Camera.py +++ b/src/py/bbctrl/Camera.py @@ -611,7 +611,6 @@ class VideoHandler(web.RequestHandler): self.flush() except iostream.StreamBufferFullError: - log.info('Camera buffer full') pass # Drop frame if buffer is full diff --git a/src/py/bbctrl/Preplanner.py b/src/py/bbctrl/Preplanner.py index 764f210..129565d 100644 --- a/src/py/bbctrl/Preplanner.py +++ b/src/py/bbctrl/Preplanner.py @@ -52,9 +52,9 @@ def _dump_json(o): elif isinstance(o, int): yield str(o) elif isinstance(o, float): - if o != o: yield 'NaN' - elif o == float('inf'): yield 'Infinity' - elif o == float('-inf'): yield '-Infinity' + if o != o: yield '"NaN"' + elif o == float('inf'): yield '"Infinity"' + elif o == float('-inf'): yield '"-Infinity"' else: yield format(o, '.2f') elif isinstance(o, (list, tuple)): @@ -101,6 +101,7 @@ def plan_hash(path, config): buf = f.read(1024 * 1024) if not buf: break h.update(buf) + time.sleep(0.001) # Yield some time return h.hexdigest() @@ -185,11 +186,15 @@ class Preplanner(object): def invalidate(self, filename): with self.lock: if filename in self.plans: + self.plans[filename][0].cancel() del self.plans[filename] def invalidate_all(self): - with self.lock: self.plans = {} + with self.lock: + for filename, plan in self.plans.items(): + plan[0].cancel() + self.plans = {} def delete_all_plans(self): @@ -315,7 +320,6 @@ class Preplanner(object): bounds = dict(min = {}, max = {}) messages = [] count = 0 - cancelled = False # Initialized axis states and bounds for axis in 'xyzabc': @@ -323,6 +327,7 @@ class Preplanner(object): bounds['min'][axis] = math.inf bounds['max'][axis] = -math.inf + def add_to_bounds(axis, value): if value < bounds['min'][axis]: bounds['min'][axis] = value if bounds['max'][axis] < value: bounds['max'][axis] = value @@ -393,8 +398,9 @@ class Preplanner(object): if update_speed(s): m = compute_move(startPos, unit, d) - m['s'] = cur - moves.append(m) + if cur is not None: + m['s'] = cur + moves.append(m) move['s'] = s moves.append(move) @@ -413,8 +419,7 @@ class Preplanner(object): elif cmd['type'] == 'dwell': totalTime += cmd['seconds'] if not self._progress(filename, maxLine / totalLines): - cancelled = True - raise Exception('Plan canceled.') + return # Plan cancelled if self.max_preplan_time < time.time() - start: raise Exception('Max planning time (%d sec) exceeded.' % @@ -430,7 +435,7 @@ class Preplanner(object): except Exception as e: log_cb('error', str(e), filename, line, 0) - self._progress(filename, 1) + if not self._progress(filename, 1): return # Cancelled # Remove infinity from bounds for axis in 'xyzabc': @@ -447,8 +452,7 @@ class Preplanner(object): meta_comp = gzip.compress(dump_json(meta).encode('utf8')) # Save plan & meta data - if not cancelled: - with open(plan_path, 'wb') as f: f.write(data) - with open(meta_path, 'wb') as f: f.write(meta_comp) + with open(plan_path, 'wb') as f: f.write(data) + with open(meta_path, 'wb') as f: f.write(meta_comp) return (data, meta) diff --git a/src/py/bbctrl/State.py b/src/py/bbctrl/State.py index 938f76f..648f9b0 100644 --- a/src/py/bbctrl/State.py +++ b/src/py/bbctrl/State.py @@ -189,7 +189,6 @@ class State(object): def add_listener(self, listener): - log.info(self.vars) self.listeners.append(listener) listener(self.vars)