Added accel config, scale velocity and accel, connect planner seek function
authorJoseph Coffland <joseph@cauldrondevelopment.com>
Tue, 16 Jan 2018 22:08:05 +0000 (14:08 -0800)
committerJoseph Coffland <joseph@cauldrondevelopment.com>
Tue, 16 Jan 2018 22:08:05 +0000 (14:08 -0800)
src/avr/src/axis.c
src/avr/src/config.h
src/avr/src/exec.c
src/avr/src/seek.c
src/avr/src/switch.c
src/jade/templates/control-view.jade
src/py/bbctrl/AVR.py
src/py/bbctrl/Cmd.py
src/py/bbctrl/Planner.py
src/resources/config-template.json

index 5f151d378a00b4ac54561825c5d6660659085c8e..32ffa3a15ad779edca21082e643729e6e2235432 100644 (file)
@@ -124,8 +124,6 @@ float axis_get_vector_length(const float a[], const float b[]) {
 
 AXIS_SET(homed, bool)
 
-AXIS_GET(velocity_max, float, 0)
-AXIS_GET(accel_max, float, 0)
 AXIS_GET(homed, bool, false)
 AXIS_GET(homing_mode, homing_mode_t, HOMING_MANUAL)
 AXIS_GET(radius, float, 0)
@@ -136,13 +134,24 @@ AXIS_GET(latch_velocity, float, 0)
 AXIS_GET(zero_backoff, float, 0)
 AXIS_GET(latch_backoff, float, 0)
 
-/* Note on jerk functions
- *
- * Jerk values can be rather large.  Jerk values are stored in the system in
- * truncated format; values are divided by 1,000,000 then multiplied before use.
- *
- * The axis_jerk() functions expect the jerk in divided by 1,000,000 form.
- */
+
+/// Velocity is scaled by 1,000.
+float axis_get_velocity_max(int axis) {
+  int motor = axis_get_motor(axis);
+  return motor == -1 ? 0 : axes[motor].velocity_max * VELOCITY_MULTIPLIER;
+}
+AXIS_VAR_GET(velocity_max, float)
+
+
+/// Acceleration is scaled by 1,000.
+float axis_get_accel_max(int axis) {
+  int motor = axis_get_motor(axis);
+  return motor == -1 ? 0 : axes[motor].accel_max * ACCEL_MULTIPLIER;
+}
+AXIS_VAR_GET(accel_max, float)
+
+
+/// Jerk is scaled by 1,000,000.
 float axis_get_jerk_max(int axis) {
   int motor = axis_get_motor(axis);
   return motor == -1 ? 0 : axes[motor].jerk_max * JERK_MULTIPLIER;
@@ -152,6 +161,7 @@ AXIS_VAR_GET(jerk_max, float)
 
 AXIS_VAR_SET(velocity_max, float)
 AXIS_VAR_SET(accel_max, float)
+AXIS_VAR_SET(jerk_max, float)
 AXIS_VAR_SET(radius, float)
 AXIS_VAR_SET(travel_min, float)
 AXIS_VAR_SET(travel_max, float)
@@ -160,7 +170,6 @@ AXIS_VAR_SET(search_velocity, float)
 AXIS_VAR_SET(latch_velocity, float)
 AXIS_VAR_SET(zero_backoff, float)
 AXIS_VAR_SET(latch_backoff, float)
-AXIS_VAR_SET(jerk_max, float)
 
 
 float get_homing_dir(int axis) {
index bb9ce42cea9f080478a55f25c2813eb72c13a4cf..0393dda467919caf3149c11a9d330510a9b5bbf6 100644 (file)
@@ -210,6 +210,8 @@ enum {
 #define CURRENT_SENSE_RESISTOR   0.05          // ohms
 #define CURRENT_SENSE_REF        2.75          // volts
 #define MAX_CURRENT              10            // amps
+#define VELOCITY_MULTIPLIER      1000.0
+#define ACCEL_MULTIPLIER         1000.0
 #define JERK_MULTIPLIER          1000000.0
 #define SYNC_QUEUE_SIZE          4096
 #define EXEC_FILL_TARGET         8
index 352a932decab4b00e45ec7520b5a6293778eac82..e8f75a32759c677788acec0ae2b87c4b4d8df51a 100644 (file)
@@ -110,9 +110,9 @@ stat_t exec_next() {
 // Variable callbacks
 int32_t get_line() {return ex.line;}
 uint8_t get_tool() {return ex.tool;}
-float get_velocity() {return ex.velocity;}
-float get_acceleration() {return ex.accel;}
-float get_jerk() {return ex.jerk;}
+float get_velocity() {return ex.velocity / VELOCITY_MULTIPLIER;}
+float get_acceleration() {return ex.accel / ACCEL_MULTIPLIER;}
+float get_jerk() {return ex.jerk / JERK_MULTIPLIER;}
 float get_feed_override() {return ex.feed_override;}
 float get_speed_override() {return ex.spindle_override;}
 float get_axis_position(int axis) {return ex.position[axis];}
index 0f8ad1dead87f4eb3986540ae6b1cdc4379d5ae2..34516a14acf5a28150e038ecf94946d86569d2d3 100644 (file)
@@ -31,6 +31,7 @@
 #include "switch.h"
 #include "estop.h"
 #include "util.h"
+#include "state.h"
 
 #include <stdint.h>
 
@@ -92,6 +93,4 @@ stat_t command_seek(char *cmd) {
 
 
 unsigned command_seek_size() {return sizeof(seek_t);}
-
-
 void command_seek_exec(void *data) {seek = *(seek_t *)data;}
index 68898fc3281c8aeb9b6acc20374f9ef4112edde5..28a28672d22eca2d892fea2e0a6d13677e032f01 100644 (file)
@@ -124,6 +124,7 @@ void switch_rtc_callback() {
 
 
 bool switch_is_active(int index) {
+  // NOTE, switch inputs are active lo
   switch (switches[index].type) {
   case SW_DISABLED: break; // A disabled switch cannot be active
   case SW_NORMALLY_OPEN: return !switches[index].state;
index c1ae4a323ed2f66bb5877a4f2c43b72d22490d16..cacc72d0f8a3a6706d72db8dc0170623ad9e5b3f 100644 (file)
@@ -95,8 +95,8 @@ script#control-view-template(type="text/x-template")
     table.info
       tr
         th Velocity
-        td {{state.v || 0 | fixed 0}}
-        td mm/min
+        td {{state.v || 0 | fixed 2}}
+        td m/min
       tr
         th Line
         td {{0 <= state.ln ? state.ln : '-'}}
index 96461c19c1dd357ede79787acf61d159f99503f8..f96fdc84b3b494928a9696155ffc865cafc0e53a 100644 (file)
@@ -3,6 +3,7 @@ import serial
 import json
 import time
 import logging
+import traceback
 from collections import deque
 
 import bbctrl
@@ -149,7 +150,7 @@ class AVR():
             if self.ctrl.ioloop.READ & events: self.serial_read()
             if self.ctrl.ioloop.WRITE & events: self.serial_write()
         except Exception as e:
-            log.error('Serial handler error: %s', e)
+            log.error('Serial handler error: %s', traceback.format_exc())
 
 
     def serial_write(self):
index 51513abd6f58a1402632d4ca0a9dde730fa5b041..64d51488c2e5b654fdfa7b5625bdc670c5c5f667 100644 (file)
@@ -18,8 +18,8 @@ FLUSH    = 'F'
 STEP     = 'S'
 RESUME   = 'c'
 
-SEEK_OPEN  = 1 << 0
-SEEK_ERROR = 1 << 1
+SEEK_ACTIVE = 1 << 0
+SEEK_ERROR  = 1 << 1
 
 
 def encode_float(x):
@@ -68,3 +68,25 @@ def speed(speed): return '#s=:' + encode_float(speed)
 def dwell(seconds): return 'd' + encode_float(seconds)
 def pause(optional = False): 'P' + ('1' if optional else '0')
 def jog(axes): return 'j' + encode_axes(axes)
+
+
+def seek(switch, active, error):
+    cmd = SEEK
+
+    if switch == 'probe': cmd += '1'
+    elif switch == 'x-min': cmd += '2'
+    elif switch == 'x-max': cmd += '3'
+    elif switch == 'y-min': cmd += '4'
+    elif switch == 'y-max': cmd += '5'
+    elif switch == 'z-min': cmd += '6'
+    elif switch == 'z-max': cmd += '7'
+    elif switch == 'a-min': cmd += '8'
+    elif switch == 'a-max': cmd += '9'
+    else: raise Exception('Unsupported switch "%s"' % switch)
+
+    flags = 0
+    if active: flags |= SEEK_ACTIVE
+    if error:  flags |= SEEK_ERROR
+    cmd += chr(flags + ord('0'))
+
+    return cmd
index 6d71b7a31f49862884034f3ba5568911c1ad0023..658ed8cf74b15590e837e1b77d09254f8cfb3cf8 100644 (file)
@@ -42,10 +42,10 @@ class Planner():
 
         # Planner config
         self.config = {
-            "start": start,
-            "max-vel": get_vector('vm'),
-            "max-accel": get_vector('am'),
-            "max-jerk": get_vector('jm', 1000000),
+            "start":     start,
+            "max-vel":   get_vector('vm', 1000),
+            "max-accel": get_vector('am', 1000),
+            "max-jerk":  get_vector('jm', 1000000),
             # TODO junction deviation & accel
             }
         log.info('Planner config: ' + json.dumps(self.config))
@@ -94,6 +94,8 @@ class Planner():
         if type == 'speed': return Cmd.speed(block['speed'])
         if type == 'dwell': return Cmd.dwell(block['seconds'])
         if type == 'pause': return Cmd.pause(block['optional'])
+        if type == 'seek':
+            return Cmd.seek(block['switch'], block['active'], block['error'])
 
         raise Exception('Unknown planner type "%s"' % type)
 
index cf472336ca17f2d034d0dc03e55ce97d1d87daca..6f2d802dfb23a400a5d83e99b89cc9589f512067 100644 (file)
       "max-velocity": {
         "type": "float",
         "min": 0,
-        "unit": "mm/min",
-        "default": 6000,
+        "unit": "m/min",
+        "default": 5,
         "code": "vm"
       },
+      "max-accel": {
+        "type": "float",
+        "min": 0,
+        "unit": "m/min²",
+        "default": 100,
+        "code": "am"
+      },
       "max-jerk": {
         "type": "float",
         "min": 0,
-        "unit": "mm/min³",
+        "unit": "km/min³",
         "default": 50,
         "code": "jm"
       },