Don't output NaN or Infinity in JSON, improvements to plan cancel.
authorJoseph Coffland <joseph@cauldrondevelopment.com>
Fri, 16 Nov 2018 20:41:32 +0000 (12:41 -0800)
committerJoseph Coffland <joseph@cauldrondevelopment.com>
Fri, 16 Nov 2018 20:41:32 +0000 (12:41 -0800)
src/js/path-viewer.js
src/py/bbctrl/Camera.py
src/py/bbctrl/Preplanner.py
src/py/bbctrl/State.py

index 2ac7082c4799e31c0fd799090fd3a62efde2c7c3..7f07777d4c7f26f274702f134e37dc73351659a8 100644 (file)
@@ -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);
index 9f7a3da9144c89bf56760bcecf5af05227cda981..98a0403fceea42c387b7caa19dc1a3f4d023ecc7 100755 (executable)
@@ -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
 
 
index 764f210b7d2d933234147625ba83266b57390a04..129565d5116889e5a720110e0dfa352420ba5cdd 100644 (file)
@@ -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)
index 938f76ff973fb1ca7cb71c2af346c8b3b8eec02f..648f9b0817ec9a2bd76b7ad2e9a0a2e2bca342d6 100644 (file)
@@ -189,7 +189,6 @@ class State(object):
 
 
     def add_listener(self, listener):
-        log.info(self.vars)
         self.listeners.append(listener)
         listener(self.vars)