Fixed config, updates for frontend
authorJoseph Coffland <joseph@cauldrondevelopment.com>
Thu, 5 Jan 2017 02:45:01 +0000 (18:45 -0800)
committerJoseph Coffland <joseph@cauldrondevelopment.com>
Thu, 5 Jan 2017 02:45:01 +0000 (18:45 -0800)
22 files changed:
src/axes.c [deleted file]
src/axes.h [deleted file]
src/axis.c [new file with mode: 0644]
src/axis.h [new file with mode: 0644]
src/command.c
src/config.h
src/drv8711.c
src/gcode_parser.c
src/home.c
src/homing.c
src/machine.c
src/motor.c
src/motor.h
src/plan/arc.c
src/plan/exec.c
src/plan/jog.c
src/plan/line.c
src/plan/planner.c
src/probing.c
src/pwm_spindle.c
src/vars.c
src/vars.def

diff --git a/src/axes.c b/src/axes.c
deleted file mode 100644 (file)
index 3d45dff..0000000
+++ /dev/null
@@ -1,193 +0,0 @@
-/******************************************************************************\
-
-                This file is part of the Buildbotics firmware.
-
-                  Copyright (c) 2015 - 2016 Buildbotics LLC
-                            All rights reserved.
-
-     This file ("the software") is free software: you can redistribute it
-     and/or modify it under the terms of the GNU General Public License,
-      version 2 as published by the Free Software Foundation. You should
-      have received a copy of the GNU General Public License, version 2
-     along with the software. If not, see <http://www.gnu.org/licenses/>.
-
-     The software is distributed in the hope that it will be useful, but
-          WITHOUT ANY WARRANTY; without even the implied warranty of
-      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-               Lesser General Public License for more details.
-
-       You should have received a copy of the GNU Lesser General Public
-                License along with the software.  If not, see
-                       <http://www.gnu.org/licenses/>.
-
-                For information regarding this software email:
-                  "Joseph Coffland" <joseph@buildbotics.com>
-
-\******************************************************************************/
-
-
-#include "axes.h"
-#include "motor.h"
-#include "plan/planner.h"
-
-#include <math.h>
-
-
-axis_t axes[AXES] = {
-  {
-    .mode =              X_AXIS_MODE,
-    .velocity_max =      X_VELOCITY_MAX,
-    .feedrate_max =      X_FEEDRATE_MAX,
-    .travel_min =        X_TRAVEL_MIN,
-    .travel_max =        X_TRAVEL_MAX,
-    .jerk_max =          X_JERK_MAX,
-    .jerk_homing =       X_JERK_HOMING,
-    .junction_dev =      X_JUNCTION_DEVIATION,
-    .search_velocity =   X_SEARCH_VELOCITY,
-    .latch_velocity =    X_LATCH_VELOCITY,
-    .latch_backoff =     X_LATCH_BACKOFF,
-    .zero_backoff =      X_ZERO_BACKOFF,
-    .homing_mode =       X_HOMING_MODE,
-  }, {
-    .mode =              Y_AXIS_MODE,
-    .velocity_max =      Y_VELOCITY_MAX,
-    .feedrate_max =      Y_FEEDRATE_MAX,
-    .travel_min =        Y_TRAVEL_MIN,
-    .travel_max =        Y_TRAVEL_MAX,
-    .jerk_max =          Y_JERK_MAX,
-    .jerk_homing =       Y_JERK_HOMING,
-    .junction_dev =      Y_JUNCTION_DEVIATION,
-    .search_velocity =   Y_SEARCH_VELOCITY,
-    .latch_velocity =    Y_LATCH_VELOCITY,
-    .latch_backoff =     Y_LATCH_BACKOFF,
-    .zero_backoff =      Y_ZERO_BACKOFF,
-    .homing_mode =       Y_HOMING_MODE,
-  }, {
-    .mode =              Z_AXIS_MODE,
-    .velocity_max =      Z_VELOCITY_MAX,
-    .feedrate_max =      Z_FEEDRATE_MAX,
-    .travel_min =        Z_TRAVEL_MIN,
-    .travel_max =        Z_TRAVEL_MAX,
-    .jerk_max =          Z_JERK_MAX,
-    .jerk_homing =       Z_JERK_HOMING,
-    .junction_dev =      Z_JUNCTION_DEVIATION,
-    .search_velocity =   Z_SEARCH_VELOCITY,
-    .latch_velocity =    Z_LATCH_VELOCITY,
-    .latch_backoff =     Z_LATCH_BACKOFF,
-    .zero_backoff =      Z_ZERO_BACKOFF,
-    .homing_mode =       Z_HOMING_MODE,
-  }, {
-    .mode =              A_AXIS_MODE,
-    .velocity_max =      A_VELOCITY_MAX,
-    .feedrate_max =      A_FEEDRATE_MAX,
-    .travel_min =        A_TRAVEL_MIN,
-    .travel_max =        A_TRAVEL_MAX,
-    .jerk_max =          A_JERK_MAX,
-    .jerk_homing =       A_JERK_HOMING,
-    .junction_dev =      A_JUNCTION_DEVIATION,
-    .radius =            A_RADIUS,
-    .search_velocity =   A_SEARCH_VELOCITY,
-    .latch_velocity =    A_LATCH_VELOCITY,
-    .latch_backoff =     A_LATCH_BACKOFF,
-    .zero_backoff =      A_ZERO_BACKOFF,
-    .homing_mode =       A_HOMING_MODE,
-  }, {
-    .mode =              B_AXIS_MODE,
-    .velocity_max =      B_VELOCITY_MAX,
-    .feedrate_max =      B_FEEDRATE_MAX,
-    .travel_min =        B_TRAVEL_MIN,
-    .travel_max =        B_TRAVEL_MAX,
-    .jerk_max =          B_JERK_MAX,
-    .junction_dev =      B_JUNCTION_DEVIATION,
-    .radius =            B_RADIUS,
-  }, {
-    .mode =              C_AXIS_MODE,
-    .velocity_max =      C_VELOCITY_MAX,
-    .feedrate_max =      C_FEEDRATE_MAX,
-    .travel_min =        C_TRAVEL_MIN,
-    .travel_max =        C_TRAVEL_MAX,
-    .jerk_max =          C_JERK_MAX,
-    .junction_dev =      C_JUNCTION_DEVIATION,
-    .radius =            C_RADIUS,
-  }
-};
-
-
-char axis_get_char(int axis) {
-  return (axis < 0 || AXES <= axis) ? '?' : "XYZABCUVW"[axis];
-}
-
-
-/* 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.
- */
-
-/// Returns axis jerk
-float axes_get_jerk(int axis) {return axes[axis].jerk_max;}
-
-
-/// Sets jerk and its reciprocal for axis
-void axes_set_jerk(int axis, float jerk) {
-  axes[axis].jerk_max = jerk;
-  axes[axis].recip_jerk = 1 / (jerk * JERK_MULTIPLIER);
-}
-
-
-int axes_get_motor(int axis) {
-  for (int motor = 0; motor < MOTORS; motor++)
-    if (motor_get_axis(motor) == axis) return motor;
-  return -1;
-}
-
-
-float axes_get_vector_length(const float a[], const float b[]) {
-  return sqrt(square(a[AXIS_X] - b[AXIS_X]) + square(a[AXIS_Y] - b[AXIS_Y]) +
-              square(a[AXIS_Z] - b[AXIS_Z]) + square(a[AXIS_A] - b[AXIS_A]) +
-              square(a[AXIS_B] - b[AXIS_B]) + square(a[AXIS_C] - b[AXIS_C]));
-}
-
-
-bool axes_get_homed(int axis) {return axes[axis].homed;}
-void axes_set_homed(int axis, bool homed) {axes[axis].homed = homed;}
-
-
-int get_axis_mode(int axis) {return axes[axis].mode;}
-
-
-void set_axis_mode(int axis, int value) {
-  if (value <= AXIS_RADIUS) axes[axis].mode = value;
-}
-
-
-float get_max_velocity(int axis) {return axes[axis].velocity_max;}
-void set_max_velocity(int axis, float value) {axes[axis].velocity_max = value;}
-float get_max_feedrate(int axis) {return axes[axis].feedrate_max;}
-void set_max_feedrate(int axis, float value) {axes[axis].feedrate_max = value;}
-float get_max_jerk(int axis) {return axes[axis].jerk_max;}
-void set_max_jerk(int axis, float value) {axes[axis].jerk_max = value;}
-float get_junction_dev(int axis) {return axes[axis].junction_dev;}
-void set_junction_dev(int axis, float value) {axes[axis].junction_dev = value;}
-float get_travel_min(int axis) {return axes[axis].travel_min;}
-void set_travel_min(int axis, float value) {axes[axis].travel_min = value;}
-float get_travel_max(int axis) {return axes[axis].travel_max;}
-void set_travel_max(int axis, float value) {axes[axis].travel_max = value;}
-float get_jerk_homing(int axis) {return axes[axis].jerk_homing;}
-void set_jerk_homing(int axis, float value) {axes[axis].jerk_homing = value;}
-float get_search_vel(int axis) {return axes[axis].search_velocity;}
-void set_search_vel(int axis, float value) {axes[axis].search_velocity = value;}
-float get_latch_vel(int axis) {return axes[axis].latch_velocity;}
-void set_latch_vel(int axis, float value) {axes[axis].latch_velocity = value;}
-float get_latch_backoff(int axis) {return axes[axis].latch_backoff;}
-
-
-void set_latch_backoff(int axis, float value) {
-  axes[axis].latch_backoff = value;
-}
-
-
-float get_zero_backoff(int axis) {return axes[axis].zero_backoff;}
-void set_zero_backoff(int axis, float value) {axes[axis].zero_backoff = value;}
diff --git a/src/axes.h b/src/axes.h
deleted file mode 100644 (file)
index cdbb130..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-/******************************************************************************\
-
-                This file is part of the Buildbotics firmware.
-
-                  Copyright (c) 2015 - 2016 Buildbotics LLC
-                  Copyright (c) 2010 - 2015 Alden S. Hart, Jr.
-                            All rights reserved.
-
-     This file ("the software") is free software: you can redistribute it
-     and/or modify it under the terms of the GNU General Public License,
-      version 2 as published by the Free Software Foundation. You should
-      have received a copy of the GNU General Public License, version 2
-     along with the software. If not, see <http://www.gnu.org/licenses/>.
-
-     The software is distributed in the hope that it will be useful, but
-          WITHOUT ANY WARRANTY; without even the implied warranty of
-      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-               Lesser General Public License for more details.
-
-       You should have received a copy of the GNU Lesser General Public
-                License along with the software.  If not, see
-                       <http://www.gnu.org/licenses/>.
-
-                For information regarding this software email:
-                  "Joseph Coffland" <joseph@buildbotics.com>
-
-\******************************************************************************/
-
-#pragma once
-
-#include "config.h"
-
-#include <stdbool.h>
-
-
-enum {
-  AXIS_X, AXIS_Y, AXIS_Z,
-  AXIS_A, AXIS_B, AXIS_C,
-  AXIS_U, AXIS_V, AXIS_W // reserved
-};
-
-
-typedef enum {
-  AXIS_DISABLED,         // disabled axis
-  AXIS_STANDARD,         // axis in coordinated motion w/standard behaviors
-  AXIS_RADIUS,           // rotary axis calibrated to circumference
-} axis_mode_t;
-
-
-typedef enum {
-  HOMING_DISABLED,
-  HOMING_STALL_MIN,
-  HOMING_STALL_MAX,
-  HOMING_SWITCH_MIN,
-  HOMING_SWITCH_MAX,
-} homing_mode_t;
-
-
-typedef struct {
-  axis_mode_t mode;
-  float feedrate_max;    // max velocity in mm/min or deg/min
-  float velocity_max;    // max velocity in mm/min or deg/min
-  float travel_max;      // max work envelope for soft limits
-  float travel_min;      // min work envelope for soft limits
-  float jerk_max;        // max jerk (Jm) in mm/min^3 divided by 1 million
-  float jerk_homing;     // homing jerk (Jh) in mm/min^3 divided by 1 million
-  float recip_jerk;      // reciprocal of current jerk value - with million
-  float junction_dev;    // aka cornering delta
-  float radius;          // radius in mm for rotary axis modes
-  float search_velocity; // homing search velocity
-  float latch_velocity;  // homing latch velocity
-  float latch_backoff;   // backoff from switches prior to homing latch movement
-  float zero_backoff;    // backoff from switches for machine zero
-  homing_mode_t homing_mode;
-  bool homed;
-} axis_t;
-
-
-extern axis_t axes[AXES];
-
-char axis_get_char(int axis);
-float axes_get_jerk(int axis);
-void axes_set_jerk(int axis, float jerk);
-int axes_get_motor(int axis);
-float axes_get_vector_length(const float a[], const float b[]);
-bool axes_get_homed(int axis);
-void axes_set_homed(int axis, bool homed);
diff --git a/src/axis.c b/src/axis.c
new file mode 100644 (file)
index 0000000..b01f99b
--- /dev/null
@@ -0,0 +1,214 @@
+/******************************************************************************\
+
+                This file is part of the Buildbotics firmware.
+
+                  Copyright (c) 2015 - 2016 Buildbotics LLC
+                            All rights reserved.
+
+     This file ("the software") is free software: you can redistribute it
+     and/or modify it under the terms of the GNU General Public License,
+      version 2 as published by the Free Software Foundation. You should
+      have received a copy of the GNU General Public License, version 2
+     along with the software. If not, see <http://www.gnu.org/licenses/>.
+
+     The software is distributed in the hope that it will be useful, but
+          WITHOUT ANY WARRANTY; without even the implied warranty of
+      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+               Lesser General Public License for more details.
+
+       You should have received a copy of the GNU Lesser General Public
+                License along with the software.  If not, see
+                       <http://www.gnu.org/licenses/>.
+
+                For information regarding this software email:
+                  "Joseph Coffland" <joseph@buildbotics.com>
+
+\******************************************************************************/
+
+
+#include "axis.h"
+#include "motor.h"
+#include "plan/planner.h"
+
+#include <math.h>
+#include <string.h>
+
+
+int motor_map[AXES] = {-1, -1, -1, -1, -1, -1};
+
+
+typedef struct {
+  float velocity_max;    // max velocity in mm/min or deg/min
+  float feedrate_max;    // max velocity in mm/min or deg/min
+  float travel_max;      // max work envelope for soft limits
+  float travel_min;      // min work envelope for soft limits
+  float jerk_max;        // max jerk (Jm) in mm/min^3 divided by 1 million
+  float recip_jerk;      // reciprocal of current jerk value - with million
+  float junction_dev;    // aka cornering delta
+  float radius;          // radius in mm for rotary axes
+  float search_velocity; // homing search velocity
+  float latch_velocity;  // homing latch velocity
+  float latch_backoff;   // backoff from switches prior to homing latch movement
+  float zero_backoff;    // backoff from switches for machine zero
+  homing_mode_t homing_mode;
+  bool homed;
+} axis_t;
+
+
+axis_t axes[MOTORS] = {
+  {
+    .velocity_max    = X_VELOCITY_MAX,
+    .feedrate_max    = X_FEEDRATE_MAX,
+    .travel_min      = X_TRAVEL_MIN,
+    .travel_max      = X_TRAVEL_MAX,
+    .jerk_max        = X_JERK_MAX,
+    .junction_dev    = X_JUNCTION_DEVIATION,
+    .search_velocity = X_SEARCH_VELOCITY,
+    .latch_velocity  = X_LATCH_VELOCITY,
+    .latch_backoff   = X_LATCH_BACKOFF,
+    .zero_backoff    = X_ZERO_BACKOFF,
+    .homing_mode     = X_HOMING_MODE,
+  }, {
+    .velocity_max    = Y_VELOCITY_MAX,
+    .feedrate_max    = Y_FEEDRATE_MAX,
+    .travel_min      = Y_TRAVEL_MIN,
+    .travel_max      = Y_TRAVEL_MAX,
+    .jerk_max        = Y_JERK_MAX,
+    .junction_dev    = Y_JUNCTION_DEVIATION,
+    .search_velocity = Y_SEARCH_VELOCITY,
+    .latch_velocity  = Y_LATCH_VELOCITY,
+    .latch_backoff   = Y_LATCH_BACKOFF,
+    .zero_backoff    = Y_ZERO_BACKOFF,
+    .homing_mode     = Y_HOMING_MODE,
+  }, {
+    .velocity_max    = Z_VELOCITY_MAX,
+    .feedrate_max    = Z_FEEDRATE_MAX,
+    .travel_min      = Z_TRAVEL_MIN,
+    .travel_max      = Z_TRAVEL_MAX,
+    .jerk_max        = Z_JERK_MAX,
+    .junction_dev    = Z_JUNCTION_DEVIATION,
+    .search_velocity = Z_SEARCH_VELOCITY,
+    .latch_velocity  = Z_LATCH_VELOCITY,
+    .latch_backoff   = Z_LATCH_BACKOFF,
+    .zero_backoff    = Z_ZERO_BACKOFF,
+    .homing_mode     = Z_HOMING_MODE,
+  }, {
+    .velocity_max    = A_VELOCITY_MAX,
+    .feedrate_max    = A_FEEDRATE_MAX,
+    .travel_min      = A_TRAVEL_MIN,
+    .travel_max      = A_TRAVEL_MAX,
+    .jerk_max        = A_JERK_MAX,
+    .junction_dev    = A_JUNCTION_DEVIATION,
+    .radius          = A_RADIUS,
+    .search_velocity = A_SEARCH_VELOCITY,
+    .latch_velocity  = A_LATCH_VELOCITY,
+    .latch_backoff   = A_LATCH_BACKOFF,
+    .zero_backoff    = A_ZERO_BACKOFF,
+    .homing_mode     = A_HOMING_MODE,
+  }
+};
+
+
+bool axis_is_enabled(int axis) {
+  int motor = axis_get_motor(axis);
+  return motor != -1 && motor_is_enabled(motor);
+}
+
+
+char axis_get_char(int axis) {
+  return (axis < 0 || AXES <= axis) ? '?' : "XYZABCUVW"[axis];
+}
+
+
+int axis_get_id(char axis) {
+  const char *axes = "XYZABCUVW";
+  char *ptr = strchr(axes, axis);
+  return ptr == 0 ? -1 : (ptr - axes);
+}
+
+
+int axis_get_motor(int axis) {return motor_map[axis];}
+
+
+void axis_set_motor(int axis, int motor) {
+  motor_map[axis] = motor;
+  axis_set_jerk_max(axis, axes[motor].jerk_max); // Init 1/jerk
+}
+
+
+float axis_get_vector_length(const float a[], const float b[]) {
+  return sqrt(square(a[AXIS_X] - b[AXIS_X]) + square(a[AXIS_Y] - b[AXIS_Y]) +
+              square(a[AXIS_Z] - b[AXIS_Z]) + square(a[AXIS_A] - b[AXIS_A]) +
+              square(a[AXIS_B] - b[AXIS_B]) + square(a[AXIS_C] - b[AXIS_C]));
+}
+
+
+#define AXIS_VAR_GET(NAME, TYPE)                        \
+  TYPE get_##NAME(int axis) {return axes[axis].NAME;}
+
+
+#define AXIS_VAR_SET(NAME, TYPE)                        \
+  void set_##NAME(int axis, TYPE value) {axes[axis].NAME = value;}
+
+
+#define AXIS_GET(NAME, TYPE, DEFAULT)                   \
+  TYPE axis_get_##NAME(int axis) {                      \
+    int motor = axis_get_motor(axis);                   \
+    return motor == -1 ? DEFAULT : axes[motor].NAME;    \
+  }                                                     \
+  AXIS_VAR_GET(NAME, TYPE)
+
+
+#define AXIS_SET(NAME, TYPE)                            \
+  void axis_set_##NAME(int axis, TYPE value) {          \
+    int motor = axis_get_motor(axis);                   \
+    if (motor != -1) axes[motor].NAME = value;          \
+  }                                                     \
+  AXIS_VAR_SET(NAME, TYPE)
+
+
+AXIS_GET(velocity_max, float, 0)
+AXIS_GET(feedrate_max, float, 0)
+AXIS_GET(homed, bool, false)
+AXIS_SET(homed, bool)
+AXIS_GET(homing_mode, homing_mode_t, HOMING_DISABLED)
+AXIS_SET(homing_mode, homing_mode_t)
+AXIS_GET(radius, float, 0)
+AXIS_GET(travel_min, float, DISABLE_SOFT_LIMIT)
+AXIS_GET(travel_max, float, DISABLE_SOFT_LIMIT)
+AXIS_GET(search_velocity, float, 0)
+AXIS_GET(latch_velocity, float, 0)
+AXIS_GET(zero_backoff, float, 0)
+AXIS_GET(latch_backoff, float, 0)
+AXIS_GET(junction_dev, float, 0)
+AXIS_GET(recip_jerk, 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.
+ */
+AXIS_GET(jerk_max, float, 0)
+
+
+/// Sets jerk and its reciprocal for axis
+void axis_set_jerk_max(int axis, float jerk) {
+  axes[axis].jerk_max = jerk;
+  axes[axis].recip_jerk = 1 / (jerk * JERK_MULTIPLIER);
+}
+
+
+AXIS_VAR_SET(velocity_max, float)
+AXIS_VAR_SET(feedrate_max, float)
+AXIS_VAR_SET(radius, float)
+AXIS_VAR_SET(travel_min, float)
+AXIS_VAR_SET(travel_max, float)
+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(junction_dev, float)
+AXIS_VAR_SET(jerk_max, float)
diff --git a/src/axis.h b/src/axis.h
new file mode 100644 (file)
index 0000000..505cca1
--- /dev/null
@@ -0,0 +1,76 @@
+/******************************************************************************\
+
+                This file is part of the Buildbotics firmware.
+
+                  Copyright (c) 2015 - 2016 Buildbotics LLC
+                  Copyright (c) 2010 - 2015 Alden S. Hart, Jr.
+                            All rights reserved.
+
+     This file ("the software") is free software: you can redistribute it
+     and/or modify it under the terms of the GNU General Public License,
+      version 2 as published by the Free Software Foundation. You should
+      have received a copy of the GNU General Public License, version 2
+     along with the software. If not, see <http://www.gnu.org/licenses/>.
+
+     The software is distributed in the hope that it will be useful, but
+          WITHOUT ANY WARRANTY; without even the implied warranty of
+      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+               Lesser General Public License for more details.
+
+       You should have received a copy of the GNU Lesser General Public
+                License along with the software.  If not, see
+                       <http://www.gnu.org/licenses/>.
+
+                For information regarding this software email:
+                  "Joseph Coffland" <joseph@buildbotics.com>
+
+\******************************************************************************/
+
+#pragma once
+
+#include "config.h"
+
+#include <stdbool.h>
+
+
+enum {
+  AXIS_X, AXIS_Y, AXIS_Z,
+  AXIS_A, AXIS_B, AXIS_C,
+  AXIS_U, AXIS_V, AXIS_W // reserved
+};
+
+
+typedef enum {
+  HOMING_DISABLED,
+  HOMING_STALL_MIN,
+  HOMING_STALL_MAX,
+  HOMING_SWITCH_MIN,
+  HOMING_SWITCH_MAX,
+} homing_mode_t;
+
+
+bool axis_is_enabled(int axis);
+char axis_get_char(int axis);
+int axis_get_id(char axis);
+int axis_get_motor(int axis);
+void axis_set_motor(int axis, int motor);
+float axis_get_vector_length(const float a[], const float b[]);
+
+float axis_get_velocity_max(int axis);
+float axis_get_feedrate_max(int axis);
+float axis_get_jerk_max(int axis);
+void axis_set_jerk_max(int axis, float jerk);
+bool axis_get_homed(int axis);
+void axis_set_homed(int axis, bool homed);
+homing_mode_t axis_get_homing_mode(int axis);
+void axis_set_homing_mode(int axis, homing_mode_t mode);
+float axis_get_radius(int axis);
+float axis_get_travel_min(int axis);
+float axis_get_travel_max(int axis);
+float axis_get_search_velocity(int axis);
+float axis_get_latch_velocity(int axis);
+float axis_get_zero_backoff(int axis);
+float axis_get_latch_backoff(int axis);
+float axis_get_junction_dev(int axis);
+float axis_get_recip_jerk(int axis);
+float axis_get_jerk_max(int axis);
index c358004299ef7beffe5b1153bd9c1a206707b808..936878a9d624d6b132bd17996187c4fe034b2fc7 100644 (file)
@@ -163,6 +163,7 @@ int command_exec(int argc, char *argv[]) {
     return STAT_OK;
   }
 
+  STATUS_ERROR(STAT_UNRECOGNIZED_NAME, "'%s'", argv[0]);
   return STAT_UNRECOGNIZED_NAME;
 }
 
index a1feda3519d09c975906d015e1f17057d63ee325..8183ad563cc0dc42d6d65712908c1db42d07f5aa 100644 (file)
@@ -106,6 +106,8 @@ enum {
 #define SWITCHES                 9 // number of supported limit switches
 #define PWMS                     2 // number of supported PWM channels
 
+#define DISABLE_SOFT_LIMIT       -1000000
+
 
 // Motor settings.  See motor.c
 #define MOTOR_MAX_CURRENT        1.0  // 1.0 is full power
@@ -116,32 +118,32 @@ enum {
 #define MOTOR_POWER_MODE         MOTOR_POWERED_ONLY_WHEN_MOVING
 #define MOTOR_IDLE_TIMEOUT       0.25  // secs, motor off after this time
 
-#define M1_MOTOR_MAP             AXIS_X
+#define M1_AXIS                  AXIS_X
 #define M1_STEP_ANGLE            1.8
 #define M1_TRAVEL_PER_REV        6.35
 #define M1_MICROSTEPS            MOTOR_MICROSTEPS
-#define M1_POLARITY              MOTOR_POLARITY_NORMAL
+#define M1_REVERSE               false
 #define M1_POWER_MODE            MOTOR_POWER_MODE
 
-#define M2_MOTOR_MAP             AXIS_Y
+#define M2_AXIS                  AXIS_Y
 #define M2_STEP_ANGLE            1.8
 #define M2_TRAVEL_PER_REV        6.35
 #define M2_MICROSTEPS            MOTOR_MICROSTEPS
-#define M2_POLARITY              MOTOR_POLARITY_NORMAL
+#define M2_REVERSE               false
 #define M2_POWER_MODE            MOTOR_POWER_MODE
 
-#define M3_MOTOR_MAP             AXIS_Z
+#define M3_AXIS                  AXIS_Z
 #define M3_STEP_ANGLE            1.8
 #define M3_TRAVEL_PER_REV        (25.4 / 6.0)
 #define M3_MICROSTEPS            MOTOR_MICROSTEPS
-#define M3_POLARITY              MOTOR_POLARITY_NORMAL
+#define M3_REVERSE               false
 #define M3_POWER_MODE            MOTOR_POWER_MODE
 
-#define M4_MOTOR_MAP             AXIS_A
+#define M4_AXIS                  AXIS_A
 #define M4_STEP_ANGLE            1.8
 #define M4_TRAVEL_PER_REV        360 // degrees per motor rev
 #define M4_MICROSTEPS            MOTOR_MICROSTEPS
-#define M4_POLARITY              MOTOR_POLARITY_NORMAL
+#define M4_REVERSE               false
 #define M4_POWER_MODE            MOTOR_POWER_MODE
 
 
@@ -166,57 +168,49 @@ enum {
 #define VELOCITY_MAX             10000         // mm/min
 #define FEEDRATE_MAX             VELOCITY_MAX
 
-#define X_AXIS_MODE              AXIS_STANDARD // See machine.h
 #define X_VELOCITY_MAX           VELOCITY_MAX  // G0 max velocity in mm/min
 #define X_FEEDRATE_MAX           FEEDRATE_MAX  // G1 max feed rate in mm/min
 #define X_TRAVEL_MIN             0             // minimum travel for soft limits
-#define X_TRAVEL_MAX             300           // between switches or crashes
+#define X_TRAVEL_MAX             350           // between switches or crashes
 #define X_JERK_MAX               JERK_MAX
-#define X_JERK_HOMING            (X_JERK_MAX * 2)
 #define X_JUNCTION_DEVIATION     JUNCTION_DEVIATION
-#define X_SEARCH_VELOCITY        3000          // move in negative direction
+#define X_SEARCH_VELOCITY        2400          // move in negative direction
 #define X_LATCH_VELOCITY         100           // mm/min
 #define X_LATCH_BACKOFF          5             // mm
 #define X_ZERO_BACKOFF           1             // mm
-#define X_HOMING_MODE            HOMING_STALL_MIN
+#define X_HOMING_MODE            HOMING_STALL_MAX
 
-#define Y_AXIS_MODE              AXIS_STANDARD
 #define Y_VELOCITY_MAX           VELOCITY_MAX
 #define Y_FEEDRATE_MAX           FEEDRATE_MAX
 #define Y_TRAVEL_MIN             0
-#define Y_TRAVEL_MAX             300
+#define Y_TRAVEL_MAX             350
 #define Y_JERK_MAX               JERK_MAX
-#define Y_JERK_HOMING            (Y_JERK_MAX * 2)
 #define Y_JUNCTION_DEVIATION     JUNCTION_DEVIATION
 #define Y_SEARCH_VELOCITY        3000
 #define Y_LATCH_VELOCITY         100
 #define Y_LATCH_BACKOFF          5
 #define Y_ZERO_BACKOFF           1
-#define Y_HOMING_MODE            HOMING_STALL_MIN
+#define Y_HOMING_MODE            HOMING_STALL_MAX
 
-#define Z_AXIS_MODE              AXIS_STANDARD
 #define Z_VELOCITY_MAX           2000 // VELOCITY_MAX
 #define Z_FEEDRATE_MAX           FEEDRATE_MAX
 #define Z_TRAVEL_MIN             0
 #define Z_TRAVEL_MAX             75
 #define Z_JERK_MAX               JERK_MAX
-#define Z_JERK_HOMING            (Z_JERK_MAX * 2)
 #define Z_JUNCTION_DEVIATION     JUNCTION_DEVIATION
-#define Z_SEARCH_VELOCITY        800
+#define Z_SEARCH_VELOCITY        400
 #define Z_LATCH_VELOCITY         100
 #define Z_LATCH_BACKOFF          5
 #define Z_ZERO_BACKOFF           1
-#define Z_HOMING_MODE            HOMING_DISABLED //STALL_MAX
+#define Z_HOMING_MODE            HOMING_STALL_MAX
 
 // A values are chosen to make the A motor react the same as X for testing
 // set to the same speed as X axis
-#define A_AXIS_MODE              AXIS_RADIUS
 #define A_VELOCITY_MAX           (X_VELOCITY_MAX / M1_TRAVEL_PER_REV * 360)
 #define A_FEEDRATE_MAX           A_VELOCITY_MAX
 #define A_TRAVEL_MIN             -1
 #define A_TRAVEL_MAX             -1 // same value means infinite
 #define A_JERK_MAX               (X_JERK_MAX * 360 / M1_TRAVEL_PER_REV)
-#define A_JERK_HOMING            (A_JERK_MAX * 2)
 #define A_JUNCTION_DEVIATION     JUNCTION_DEVIATION
 #define A_RADIUS                 (M1_TRAVEL_PER_REV / 2 / M_PI)
 #define A_SEARCH_VELOCITY        600
@@ -225,34 +219,6 @@ enum {
 #define A_ZERO_BACKOFF           2
 #define A_HOMING_MODE            HOMING_DISABLED
 
-#define B_AXIS_MODE              AXIS_DISABLED
-#define B_VELOCITY_MAX           3600
-#define B_FEEDRATE_MAX           B_VELOCITY_MAX
-#define B_TRAVEL_MIN             -1
-#define B_TRAVEL_MAX             -1
-#define B_JERK_MAX               JERK_MAX
-#define B_JERK_HOMING            (B_JERK_MAX * 2)
-#define B_JUNCTION_DEVIATION     JUNCTION_DEVIATION
-#define B_RADIUS                 1
-#define B_SEARCH_VELOCITY        600
-#define B_LATCH_VELOCITY         100
-#define B_LATCH_BACKOFF          5
-#define B_ZERO_BACKOFF           2
-
-#define C_AXIS_MODE              AXIS_DISABLED
-#define C_VELOCITY_MAX           3600
-#define C_FEEDRATE_MAX           C_VELOCITY_MAX
-#define C_TRAVEL_MIN             -1
-#define C_TRAVEL_MAX             -1
-#define C_JERK_MAX               JERK_MAX
-#define C_JERK_HOMING            (C_JERK_MAX * 2)
-#define C_JUNCTION_DEVIATION     JUNCTION_DEVIATION
-#define C_RADIUS                 1
-#define C_SEARCH_VELOCITY        600
-#define C_LATCH_VELOCITY         100
-#define C_LATCH_BACKOFF          5
-#define C_ZERO_BACKOFF           2
-
 
 // Spindle settings
 #define SPINDLE_TYPE             SPINDLE_TYPE_HUANYANG
@@ -261,7 +227,7 @@ enum {
 #define SPINDLE_MAX_RPM          24000
 #define SPINDLE_MIN_DUTY         0.05
 #define SPINDLE_MAX_DUTY         0.99
-#define SPINDLE_POLARITY         0 // 0 = normal, 1 = reverse
+#define SPINDLE_REVERSE          false
 
 
 // Gcode defaults
index f4b82356f50869154e6d9d4f02229c97098637f8..0ed4bfa76df579c22fc9950d4527139328489793 100644 (file)
@@ -234,7 +234,7 @@ static void _init_spi_commands() {
     // Set STALL
     commands[spi.ncmds++] =
       DRV8711_WRITE(DRV8711_STALL_REG,
-                    DRV8711_STALL_SDCNT_2 | DRV8711_STALL_VDIV_16 | 133);
+                    DRV8711_STALL_SDCNT_2 | DRV8711_STALL_VDIV_8 | 200);
 
     // Set DRIVE
     commands[spi.ncmds++] =
index e6095ea96cceba289df37ba303274738c2ddbfe9..080350701ad36507a0a2a4f7364b95b40a179b47 100644 (file)
@@ -32,7 +32,7 @@
 #include "plan/arc.h"
 #include "probing.h"
 #include "homing.h"
-#include "axes.h"
+#include "axis.h"
 #include "util.h"
 
 #include <stdbool.h>
index 99fed3f644cee4ba2fbdebea454cc51eaf93b899..a8b89868f8d26b35c0f69a74f67ef816fd5c482f 100644 (file)
@@ -31,7 +31,7 @@
 #include "plan/line.h"
 #include "plan/state.h"
 #include "plan/exec.h"
-#include "axes.h"
+#include "axis.h"
 #include "motor.h"
 #include "util.h"
 #include "config.h"
@@ -82,15 +82,16 @@ void home_callback() {
       !mp_queue_is_empty()) return;
 
   while (true) {
-    axis_t *axis = &axes[home.axis];
-    int motor = axes_get_motor(home.axis);
-    int direction = (axis->homing_mode == HOMING_STALL_MIN ||
-                     axis->homing_mode == HOMING_SWITCH_MIN) ? -1 : 1;
+    int motor = axis_get_motor(home.axis);
+    homing_mode_t mode = axis_get_homing_mode(home.axis);
+    int direction =
+      (mode == HOMING_STALL_MIN || mode == HOMING_SWITCH_MIN) ? -1 : 1;
+    float min = axis_get_travel_min(home.axis);
+    float max = axis_get_travel_max(home.axis);
 
     switch (home.state) {
     case STATE_INIT: {
-      if (motor == -1 || axis->mode == AXIS_DISABLED ||
-          axis->homing_mode == HOMING_DISABLED || !motor_is_enabled(motor)) {
+      if (motor == -1 || mode == HOMING_DISABLED) {
         home.state = STATE_DONE;
         break;
       }
@@ -106,11 +107,11 @@ void home_callback() {
       home.microsteps = motor_get_microsteps(motor);
       motor_set_microsteps(motor, 8);
       motor_set_stall_callback(motor, _stall_callback);
-      //home.velocity = motor_get_stall_homing_velocity(motor);
-      home.velocity = axis->search_velocity;
+      //home.velocity = axis_get_stall_homing_velocity(home.axis);
+      home.velocity = axis_get_search_velocity(home.axis);
 
       // Move in home direction
-      float travel = axis->travel_max - axis->travel_min;
+      float travel = max - min; // TODO consider ramping distance
       _move_axis(travel * direction);
 
       home.state = STATE_HOMING;
@@ -130,9 +131,8 @@ void home_callback() {
 
       } else {
         STATUS_INFO("Backing off %c axis", axis_get_char(home.axis));
-        mach_set_axis_position(home.axis, direction < 0 ? axis->travel_min :
-                               axis->travel_max);
-        _move_axis(axis->zero_backoff * direction * -1);
+        mach_set_axis_position(home.axis, direction < 0 ? min : max);
+        _move_axis(axis_get_zero_backoff(home.axis) * direction * -1);
         home.state = STATE_BACKOFF;
       }
       return;
@@ -141,7 +141,7 @@ void home_callback() {
       STATUS_INFO("Homed %c axis", axis_get_char(home.axis));
 
       // Set axis position & homed
-      mach_set_axis_position(home.axis, axis->travel_min);
+      mach_set_axis_position(home.axis, min);
       home.homed[home.axis] = true;
       home.state = STATE_DONE;
       break;
index 22d9dd1fc74938e2ca87427d032c314bd04905e0..fda66c9b1873d958c4bb2cc35a3d586499f6d55a 100644 (file)
@@ -28,7 +28,7 @@
 
 #include "homing.h"
 
-#include "axes.h"
+#include "axis.h"
 #include "machine.h"
 #include "switch.h"
 #include "gcode_parser.h"
@@ -214,7 +214,7 @@ static void _homing_axis_move(int8_t axis, float target, float velocity) {
 
 /// End homing cycle in progress
 static void _homing_abort(int8_t axis) {
-  axes_set_jerk(axis, hm.saved_jerk); // restore the max jerk value
+  axis_set_jerk_max(axis, hm.saved_jerk); // restore the max jerk value
 
   // homing state remains HOMING_NOT_HOMED
   _homing_error_exit(STAT_HOMING_CYCLE_FAILED);
@@ -232,7 +232,7 @@ static void _homing_axis_set_zero(int8_t axis) {
   } else // do not set axis if in G28.4 cycle
     mach_set_axis_position(axis, mp_runtime_get_work_position(axis));
 
-  axes_set_jerk(axis, hm.saved_jerk); // restore the max jerk value
+  axis_set_jerk_max(axis, hm.saved_jerk); // restore the max jerk value
 
   hm.func = _homing_axis_start;
 }
@@ -261,7 +261,6 @@ static void _homing_axis_latch(int8_t axis) {
 /// Fast search for switch, closes switch
 static void _homing_axis_search(int8_t axis) {
   // use the homing jerk for search onward
-  axes_set_jerk(axis, axes[axis].jerk_homing);
   _homing_axis_move(axis, hm.search_travel, hm.search_velocity);
   hm.func = _homing_axis_latch;
 }
@@ -299,25 +298,25 @@ static void _homing_axis_start(int8_t axis) {
   hm.homed[axis] = false;
 
   // trap axis mis-configurations
-  if (fp_ZERO(axes[axis].search_velocity))
+  if (fp_ZERO(axis_get_search_velocity(axis)))
     return _homing_error_exit(STAT_HOMING_ERROR_ZERO_SEARCH_VELOCITY);
-  if (fp_ZERO(axes[axis].latch_velocity))
+  if (fp_ZERO(axis_get_latch_velocity(axis)))
     return _homing_error_exit(STAT_HOMING_ERROR_ZERO_LATCH_VELOCITY);
-  if (axes[axis].latch_backoff < 0)
+  if (axis_get_latch_backoff(axis) < 0)
     return _homing_error_exit(STAT_HOMING_ERROR_NEGATIVE_LATCH_BACKOFF);
 
   // calculate and test travel distance
   float travel_distance =
-    fabs(axes[axis].travel_max - axes[axis].travel_min) +
-    axes[axis].latch_backoff;
+    fabs(axis_get_travel_max(axis) - axis_get_travel_min(axis)) +
+    axis_get_latch_backoff(axis);
   if (fp_ZERO(travel_distance))
     return _homing_error_exit(STAT_HOMING_ERROR_TRAVEL_MIN_MAX_IDENTICAL);
 
   hm.axis = axis; // persist the axis
   // search velocity is always positive
-  hm.search_velocity = fabs(axes[axis].search_velocity);
+  hm.search_velocity = fabs(axis_get_search_velocity(axis));
   // latch velocity is always positive
-  hm.latch_velocity = fabs(axes[axis].latch_velocity);
+  hm.latch_velocity = fabs(axis_get_latch_velocity(axis));
 
   // determine which switch to use
   bool min_enabled = switch_is_enabled(MIN_SWITCH(axis));
@@ -328,16 +327,16 @@ static void _homing_axis_start(int8_t axis) {
     hm.homing_switch = MIN_SWITCH(axis);         // min is the homing switch
     hm.limit_switch = MAX_SWITCH(axis);          // max would be limit switch
     hm.search_travel = -travel_distance;         // in negative direction
-    hm.latch_backoff = axes[axis].latch_backoff; // in positive direction
-    hm.zero_backoff = axes[axis].zero_backoff;
+    hm.latch_backoff = axis_get_latch_backoff(axis); // in positive direction
+    hm.zero_backoff = axis_get_zero_backoff(axis);
 
   } else if (max_enabled) {
     // setup parameters for positive travel (homing to the maximum switch)
     hm.homing_switch = MAX_SWITCH(axis);          // max is homing switch
     hm.limit_switch = MIN_SWITCH(axis);           // min would be limit switch
     hm.search_travel = travel_distance;           // in positive direction
-    hm.latch_backoff = -axes[axis].latch_backoff; // in negative direction
-    hm.zero_backoff = -axes[axis].zero_backoff;
+    hm.latch_backoff = -axis_get_latch_backoff(axis); // in negative direction
+    hm.zero_backoff = -axis_get_zero_backoff(axis);
 
   } else {
     // if homing is disabled for the axis then skip to the next axis
@@ -346,7 +345,7 @@ static void _homing_axis_start(int8_t axis) {
     return;
   }
 
-  hm.saved_jerk = axes_get_jerk(axis); // save the max jerk value
+  hm.saved_jerk = axis_get_jerk_max(axis); // save the max jerk value
   hm.func = _homing_axis_clear; // start the clear
 }
 
index 75e0d756c99773cdcef406074f3f22598764ef08..49c6349abbd06038f1398cd7ee34d17a687b3252 100644 (file)
@@ -62,7 +62,7 @@
 #include "machine.h"
 
 #include "config.h"
-#include "axes.h"
+#include "axis.h"
 #include "gcode_parser.h"
 #include "spindle.h"
 #include "coolant.h"
@@ -76,8 +76,6 @@
 #include "plan/state.h"
 
 
-#define DISABLE_SOFT_LIMIT -1000000
-
 typedef struct { // struct to manage mach globals and cycles
   float offset[COORDS + 1][AXES];      // coordinate systems & offsets G53-G59
   float origin_offset[AXES];           // G92 offsets
@@ -296,12 +294,7 @@ float mach_get_axis_position(uint8_t axis) {return mach.position[axis];}
  *    - conversion of relative mode to absolute (internal canonical form)
  *    - translation of work coordinates to machine coordinates (internal
  *      canonical form)
- *    - application of axis modes:
- *
- *      DISABLED - Incoming value is ignored.
- *      ENABLED  - Convert axis values to canonical format.
- *      RADIUS   - ABC axis value is provided in Gcode block in linear units.
- *               - Target is set to degrees based on axis' Radius value.
+ *    - application of axis radius mode
  *
  *  Target coordinates are provided in @param values.
  *  Axes that need processing are signaled in @param flags.
@@ -310,24 +303,17 @@ void mach_calc_target(float target[], const float values[],
                       const bool flags[]) {
   for (int axis = 0; axis < AXES; axis++) {
     target[axis] = mach.position[axis];
-    if (!flags[axis]) continue;
+    if (!flags[axis] || !axis_is_enabled(axis)) continue;
 
-    const float offset = mach.gm.distance_mode == ABSOLUTE_MODE ?
+    target[axis] = mach.gm.distance_mode == ABSOLUTE_MODE ?
       mach_get_active_coord_offset(axis) : mach.position[axis];
 
-    switch (axes[axis].mode) {
-    case AXIS_DISABLED: break;
-    case AXIS_STANDARD:
-      // For ABC axes no mm conversion - it's already in degrees
-      target[axis] =
-        offset + (AXIS_Z < axis ? values[axis] : TO_MM(values[axis]));
-      break;
-
-    case AXIS_RADIUS:
-      target[axis] =
-        offset + TO_MM(values[axis]) * 360 / (2 * M_PI * axes[axis].radius);
-      break;
-    }
+    float radius = axis_get_radius(axis);
+    if (radius) // Handle radius mode if radius is non-zero
+      target[axis] += TO_MM(values[axis]) * 360 / (2 * M_PI * radius);
+    // For ABC axes no mm conversion - it's already in degrees
+    else if (AXIS_Z < axis) target[axis] += values[axis];
+    else target[axis] += TO_MM(values[axis]);
   }
 }
 
@@ -345,16 +331,16 @@ void mach_calc_target(float target[], const float values[],
  */
 stat_t mach_test_soft_limits(float target[]) {
   for (int axis = 0; axis < AXES; axis++) {
-    if (!mach_get_homed(axis)) continue; // don't test axes that arent homed
+    if (!axis_get_homed(axis)) continue; // don't test axes that arent homed
 
-    if (fp_EQ(axes[axis].travel_min, axes[axis].travel_max)) continue;
+    float min = axis_get_travel_min(axis);
+    float max = axis_get_travel_max(axis);
 
-    if (axes[axis].travel_min > DISABLE_SOFT_LIMIT &&
-        target[axis] < axes[axis].travel_min)
-      return STAT_SOFT_LIMIT_EXCEEDED;
+    // min == max means no soft limits
+    if (fp_EQ(min, max)) continue;
 
-    if (axes[axis].travel_max > DISABLE_SOFT_LIMIT &&
-        target[axis] > axes[axis].travel_max)
+    if ((min > DISABLE_SOFT_LIMIT && target[axis] < min) ||
+        (max > DISABLE_SOFT_LIMIT && target[axis] > max))
       return STAT_SOFT_LIMIT_EXCEEDED;
   }
 
@@ -373,10 +359,6 @@ stat_t mach_test_soft_limits(float target[]) {
 // Initialization and Termination (4.3.2)
 
 void machine_init() {
-  // Init 1/jerk
-  for (int axis = 0; axis < AXES; axis++)
-    axes_set_jerk(axis, axes[axis].jerk_max);
-
   // Set gcode defaults
   mach_set_units(GCODE_DEFAULT_UNITS);
   mach_set_coord_system(GCODE_DEFAULT_COORD_SYSTEM);
index 73f76f69d6ec0efbb62feb4a69b833be35dfaa76..43221aec85576c3be6cf209dad44ac9a1564819b 100644 (file)
@@ -35,7 +35,7 @@
 #include "drv8711.h"
 #include "estop.h"
 #include "gcode_state.h"
-#include "axes.h"
+#include "axis.h"
 #include "util.h"
 
 #include "plan/runtime.h"
@@ -61,7 +61,7 @@ typedef struct {
   // Config
   uint8_t axis;                  // map motor to axis
   uint16_t microsteps;           // microsteps per full step
-  motor_polarity_t polarity;
+  bool reverse;
   motor_power_mode_t power_mode;
   float step_angle;              // degrees per whole step
   float travel_rev;              // mm or deg of travel per motor revolution
@@ -97,54 +97,54 @@ typedef struct {
 
 static motor_t motors[MOTORS] = {
   {
-    .axis        = M1_MOTOR_MAP,
-    .step_angle  = M1_STEP_ANGLE,
-    .travel_rev  = M1_TRAVEL_PER_REV,
-    .microsteps  = M1_MICROSTEPS,
-    .polarity    = M1_POLARITY,
-    .power_mode  = M1_POWER_MODE,
-    .step_pin    = STEP_X_PIN,
-    .dir_pin     = DIR_X_PIN,
-    .timer       = &M1_TIMER,
-    .dma         = &M1_DMA_CH,
-    .dma_trigger = M1_DMA_TRIGGER,
+    .axis            = M1_AXIS,
+    .step_angle      = M1_STEP_ANGLE,
+    .travel_rev      = M1_TRAVEL_PER_REV,
+    .microsteps      = M1_MICROSTEPS,
+    .reverse         = M1_REVERSE,
+    .power_mode      = M1_POWER_MODE,
+    .step_pin        = STEP_X_PIN,
+    .dir_pin         = DIR_X_PIN,
+    .timer           = &M1_TIMER,
+    .dma             = &M1_DMA_CH,
+    .dma_trigger     = M1_DMA_TRIGGER,
   }, {
-    .axis        = M2_MOTOR_MAP,
-    .step_angle  = M2_STEP_ANGLE,
-    .travel_rev  = M2_TRAVEL_PER_REV,
-    .microsteps  = M2_MICROSTEPS,
-    .polarity    = M2_POLARITY,
-    .power_mode  = M2_POWER_MODE,
-    .step_pin    = STEP_Y_PIN,
-    .dir_pin     = DIR_Y_PIN,
-    .timer       = &M2_TIMER,
-    .dma         = &M2_DMA_CH,
-    .dma_trigger = M2_DMA_TRIGGER,
+    .axis            = M2_AXIS,
+    .step_angle      = M2_STEP_ANGLE,
+    .travel_rev      = M2_TRAVEL_PER_REV,
+    .microsteps      = M2_MICROSTEPS,
+    .reverse         = M2_REVERSE,
+    .power_mode      = M2_POWER_MODE,
+    .step_pin        = STEP_Y_PIN,
+    .dir_pin         = DIR_Y_PIN,
+    .timer           = &M2_TIMER,
+    .dma             = &M2_DMA_CH,
+    .dma_trigger     = M2_DMA_TRIGGER,
   }, {
-    .axis        = M3_MOTOR_MAP,
-    .step_angle  = M3_STEP_ANGLE,
-    .travel_rev  = M3_TRAVEL_PER_REV,
-    .microsteps  = M3_MICROSTEPS,
-    .polarity    = M3_POLARITY,
-    .power_mode  = M3_POWER_MODE,
-    .step_pin    = STEP_Z_PIN,
-    .dir_pin     = DIR_Z_PIN,
-    .timer       = &M3_TIMER,
-    .dma         = &M3_DMA_CH,
-    .dma_trigger = M3_DMA_TRIGGER,
+    .axis            = M3_AXIS,
+    .step_angle      = M3_STEP_ANGLE,
+    .travel_rev      = M3_TRAVEL_PER_REV,
+    .microsteps      = M3_MICROSTEPS,
+    .reverse         = M3_REVERSE,
+    .power_mode      = M3_POWER_MODE,
+    .step_pin        = STEP_Z_PIN,
+    .dir_pin         = DIR_Z_PIN,
+    .timer           = &M3_TIMER,
+    .dma             = &M3_DMA_CH,
+    .dma_trigger     = M3_DMA_TRIGGER,
   }, {
-    .axis        = M4_MOTOR_MAP,
-    .step_angle  = M4_STEP_ANGLE,
-    .travel_rev  = M4_TRAVEL_PER_REV,
-    .microsteps  = M4_MICROSTEPS,
-    .polarity    = M4_POLARITY,
-    .power_mode  = M4_POWER_MODE,
-    .step_pin    = STEP_A_PIN,
-    .dir_pin     = DIR_A_PIN,
-    .timer       = (TC0_t *)&M4_TIMER,
-    .dma         = &M4_DMA_CH,
-    .dma_trigger = M4_DMA_TRIGGER,
-  }
+    .axis            = M4_AXIS,
+    .step_angle      = M4_STEP_ANGLE,
+    .travel_rev      = M4_TRAVEL_PER_REV,
+    .microsteps      = M4_MICROSTEPS,
+    .reverse         = M4_REVERSE,
+    .power_mode      = M4_POWER_MODE,
+    .step_pin        = STEP_A_PIN,
+    .dir_pin         = DIR_A_PIN,
+    .timer           = (TC0_t *)&M4_TIMER,
+    .dma             = &M4_DMA_CH,
+    .dma_trigger     = M4_DMA_TRIGGER,
+    }
 };
 
 
@@ -164,6 +164,8 @@ void motor_init() {
   for (int motor = 0; motor < MOTORS; motor++) {
     motor_t *m = &motors[motor];
 
+    axis_set_motor(m->axis, motor);
+
     // IO pins
     DIRSET_PIN(m->step_pin);   // Output
     DIRSET_PIN(m->dir_pin);    // Output
@@ -242,7 +244,7 @@ float motor_get_units_per_step(int motor) {
 
 float _get_max_velocity(int motor) {
   return
-    axes[motors[motor].axis].velocity_max * motor_get_steps_per_unit(motor);
+    axis_get_velocity_max(motors[motor].axis) * motor_get_steps_per_unit(motor);
 }
 
 
@@ -288,49 +290,49 @@ int32_t motor_get_position(int motor) {return motors[motor].position;}
 
 
 /// returns true if motor is in an error state
-bool motor_error(int motor) {
-  uint8_t flags = motors[motor].flags;
+bool motor_error(int m) {
+  uint8_t flags = motors[m].flags;
   if (calibrate_busy()) flags &= ~MOTOR_FLAG_STALLED_bm;
   return flags & MOTOR_FLAG_ERROR_bm;
 }
 
 
-bool motor_stalled(int motor) {
-  return motors[motor].flags & MOTOR_FLAG_STALLED_bm;
+bool motor_stalled(int m) {
+  return motors[m].flags & MOTOR_FLAG_STALLED_bm;
 }
 
 
-void motor_reset(int motor) {
-  motors[motor].flags = 0;
+void motor_reset(int m) {
+  motors[m].flags = 0;
 }
 
 
 /// Remove power from a motor
-static void _deenergize(int motor) {
-  if (motors[motor].power_state == MOTOR_ACTIVE) {
-    motors[motor].power_state = MOTOR_IDLE;
-    drv8711_disable(motor);
+static void _deenergize(int m) {
+  if (motors[m].power_state == MOTOR_ACTIVE) {
+    motors[m].power_state = MOTOR_IDLE;
+    drv8711_disable(m);
   }
 }
 
 
 /// Apply power to a motor
-static void _energize(int motor) {
-  if (motors[motor].power_state == MOTOR_IDLE && !motor_error(motor)) {
-    motors[motor].power_state = MOTOR_ENERGIZING;
-    drv8711_enable(motor);
+static void _energize(int m) {
+  if (motors[m].power_state == MOTOR_IDLE && !motor_error(m)) {
+    motors[m].power_state = MOTOR_ENERGIZING;
+    drv8711_enable(m);
 
-    motor_driver_callback(motor); // TODO Shouldn't call this directly
+    motor_driver_callback(m); // TODO Shouldn't call this directly
   }
 
   // Reset timeout, regardless
-  motors[motor].timeout = rtc_get_time() + MOTOR_IDLE_TIMEOUT * 1000;
+  motors[m].timeout = rtc_get_time() + MOTOR_IDLE_TIMEOUT * 1000;
 }
 
 
 bool motor_energizing() {
-  for (int motor = 0; motor < MOTORS; motor++)
-    if (motors[motor].power_state == MOTOR_ENERGIZING)
+  for (int m = 0; m < MOTORS; m++)
+    if (motors[m].power_state == MOTOR_ENERGIZING)
       return true;
 
   return false;
@@ -456,8 +458,8 @@ stat_t motor_prep_move(int motor, int32_t clocks, float target, int32_t error,
 
   // Setup the direction, compensating for polarity.
   m->negative = travel < 0;
-  if (m->negative) m->direction = DIRECTION_CCW ^ m->polarity;
-  else m->direction = DIRECTION_CW ^ m->polarity;
+  if (m->negative) m->direction = DIRECTION_CCW ^ m->reverse;
+  else m->direction = DIRECTION_CW ^ m->reverse;
 
   // Find the clock rate that will fit the required number of steps
   if (ticks_per_step <= 0xffff) m->timer_clock = TC_CLKSEL_DIV1_gc;
@@ -508,6 +510,15 @@ stat_t motor_prep_move(int motor, int32_t clocks, float target, int32_t error,
 
 
 // Var callbacks
+char get_axis_name(int motor) {return axis_get_char(motors[motor].axis);}
+
+
+void set_axis_name(int motor, char axis) {
+  int id = axis_get_id(axis);
+  if (id != -1) motors[motor].axis = id;
+}
+
+
 float get_step_angle(int motor) {return motors[motor].step_angle;}
 void set_step_angle(int motor, float value) {motors[motor].step_angle = value;}
 float get_travel(int motor) {return motors[motor].travel_rev;}
@@ -521,25 +532,28 @@ void set_microstep(int motor, uint16_t value) {
 }
 
 
-uint8_t get_polarity(int motor) {
+bool get_reverse(int motor) {
   if (motor < 0 || MOTORS <= motor) return 0;
-  return motors[motor].polarity;
+  return motors[motor].reverse;
 }
 
 
-void set_polarity(int motor, uint8_t value) {motors[motor].polarity = value;}
+void set_reverse(int motor, bool value) {motors[motor].reverse = value;}
 uint8_t get_motor_axis(int motor) {return motors[motor].axis;}
 
 
-void set_motor_axis(int motor, uint16_t value) {
-  if (value < AXES) motors[motor].axis = value;
+void set_motor_axis(int motor, uint8_t value) {
+  if (MOTORS <= motor || AXES <= value || value == motors[motor].axis) return;
+  axis_set_motor(motors[motor].axis, -1);
+  motors[motor].axis = value;
+  axis_set_motor(value, motor);
 }
 
 
 uint8_t get_power_mode(int motor) {return motors[motor].power_mode;}
 
 
-void set_power_mode(int motor, uint16_t value) {
+void set_power_mode(int motor, uint8_t value) {
   if (value < MOTOR_POWER_MODE_MAX_VALUE)
     motors[motor].power_mode = value;
 }
@@ -592,18 +606,18 @@ void print_status_flags(uint8_t flags) {
 }
 
 
-uint8_t get_status_strings(int motor) {return get_status_flags(motor);}
+uint8_t get_status_strings(int m) {return get_status_flags(m);}
 
 
 // Command callback
 void command_mreset(int argc, char *argv[]) {
   if (argc == 1)
-    for (int motor = 0; motor < MOTORS; motor++)
-      motor_reset(motor);
+    for (int m = 0; m < MOTORS; m++)
+      motor_reset(m);
 
   else {
-    int motor = atoi(argv[1]);
-    if (motor < MOTORS) motor_reset(motor);
+    int m = atoi(argv[1]);
+    if (m < MOTORS) motor_reset(m);
   }
 
   report_request();
index 2d2b2defb92429d0a66666fc990dcf9d3103cfa9..3575afcd63f711b1446d9350f23c5194e208db87 100644 (file)
@@ -58,12 +58,6 @@ typedef enum {
 } motor_power_mode_t;
 
 
-typedef enum {
-  MOTOR_POLARITY_NORMAL,
-  MOTOR_POLARITY_REVERSED
-} motor_polarity_t;
-
-
 typedef void (*stall_callback_t)(int motor);
 
 
@@ -82,6 +76,7 @@ int32_t motor_get_encoder(int motor);
 void motor_set_encoder(int motor, float encoder);
 int32_t motor_get_error(int motor);
 int32_t motor_get_position(int motor);
+
 bool motor_error(int motor);
 bool motor_stalled(int motor);
 void motor_reset(int motor);
index bc149ff9501ed9b5dc606602239234cf00cb6099..957a6177a5aa0920be5398a3ee103e7abfe08b6f 100644 (file)
@@ -33,7 +33,7 @@
 
 #include "arc.h"
 
-#include "axes.h"
+#include "axis.h"
 #include "buffer.h"
 #include "line.h"
 #include "gcode_parser.h"
@@ -89,9 +89,9 @@ static float _estimate_arc_time(float length, float linear_travel,
   time /= mach_get_feed_override();
 
   // Downgrade the time if there is a rate-limiting axis
-  return max4(time, planar_travel / axes[arc.plane_axis_0].feedrate_max,
-              planar_travel / axes[arc.plane_axis_1].feedrate_max,
-              fabs(linear_travel) / axes[arc.linear_axis].feedrate_max);
+  return max4(time, planar_travel / axis_get_feedrate_max(arc.plane_axis_0),
+              planar_travel / axis_get_feedrate_max(arc.plane_axis_1),
+              fabs(linear_travel) / axis_get_feedrate_max(arc.linear_axis));
 }
 
 
index d9f006e8bed0cd86da856af3d44b8b34f5b43118..3ae0e03b459d60edca71cbb0cbb773a88195041e 100644 (file)
@@ -29,7 +29,7 @@
 
 #include "planner.h"
 #include "buffer.h"
-#include "axes.h"
+#include "axis.h"
 #include "runtime.h"
 #include "state.h"
 #include "forward_dif.h"
@@ -210,7 +210,7 @@ static void _plan_hold() {
 
   // Examine and process current buffer and compute length left for decel
   float available_length =
-    axes_get_vector_length(ex.final_target, mp_runtime_get_position());
+    axis_get_vector_length(ex.final_target, mp_runtime_get_position());
   // Compute next_segment velocity, velocity left to shed to brake to zero
   float braking_velocity = _compute_next_segment_velocity();
   // Distance to brake to zero from braking_velocity, bf is OK to use here
index 8a7f297425773bc7fc16a8b0669283b890284d6d..18c5278af577210344a9d69ce14718f589591383 100644 (file)
@@ -27,7 +27,7 @@
 
 #include "jog.h"
 
-#include "axes.h"
+#include "axis.h"
 #include "planner.h"
 #include "buffer.h"
 #include "line.h"
@@ -67,7 +67,7 @@ static stat_t _exec_jog(mp_buffer_t *bf) {
   bool done = true;
   if (!jr.writing)
     for (int axis = 0; axis < AXES; axis++) {
-      float Vn = jr.next_velocity[axis] * axes[axis].velocity_max;
+      float Vn = jr.next_velocity[axis] * axis_get_velocity_max(axis);
       float Vi = jr.velocity[axis];
       float Vt = jr.target_velocity[axis];
 
@@ -98,7 +98,7 @@ static stat_t _exec_jog(mp_buffer_t *bf) {
 
       } else {
         // Compute axis max jerk
-        float jerk = axes[axis].jerk_max * JERK_MULTIPLIER;
+        float jerk = axis_get_jerk_max(axis) * JERK_MULTIPLIER;
 
         // Compute length to velocity given max jerk
         float length = mp_get_target_length(Vi, Vt, jerk * JOG_JERK_MULT);
index 06527e10c6e0908f430ec33c948d899342fe81ac..6e0c0e3c586406697539c3663d10b7bdd32df7c2 100644 (file)
@@ -29,7 +29,7 @@
 
 #include "line.h"
 
-#include "axes.h"
+#include "axis.h"
 #include "planner.h"
 #include "exec.h"
 #include "buffer.h"
@@ -120,8 +120,8 @@ static float _get_junction_vmax(const float a_unit[], const float b_unit[]) {
   float b_delta = 0;
 
   for (int axis = 0; axis < AXES; axis++) {
-    a_delta += square(a_unit[axis] * axes[axis].junction_dev);
-    b_delta += square(b_unit[axis] * axes[axis].junction_dev);
+    a_delta += square(a_unit[axis] * axis_get_junction_dev(axis));
+    b_delta += square(b_unit[axis] * axis_get_junction_dev(axis));
   }
 
   if (!a_delta || !b_delta) return 0; // One or both unit vectors are null
@@ -197,7 +197,7 @@ int mp_find_jerk_axis(const float axis_square[]) {
   for (int axis = 0; axis < AXES; axis++)
     if (axis_square[axis]) { // Do not use fp_ZERO here
       // Squaring axis_length ensures it's positive
-      C = axis_square[axis] * axes[axis].recip_jerk;
+      C = axis_square[axis] * axis_get_recip_jerk(axis);
 
       if (maxC < C) {
         maxC = C;
@@ -211,14 +211,14 @@ int mp_find_jerk_axis(const float axis_square[]) {
 
 /// Determine jerk value to use for the block.
 static float _calc_jerk(const float axis_square[], const float unit[]) {
-  int jerk_axis = mp_find_jerk_axis(axis_square);
+  int axis = mp_find_jerk_axis(axis_square);
 
   // Finally, the selected jerk term needs to be scaled by the
-  // reciprocal of the absolute value of the jerk_axis's unit
+  // reciprocal of the absolute value of the axis's unit
   // vector term.  This way when the move is finally decomposed into
   // its constituent axes for execution the jerk for that axis will be
   // at it's maximum value.
-  return axes[jerk_axis].jerk_max * JERK_MULTIPLIER / fabs(unit[jerk_axis]);
+  return axis_get_jerk_max(axis) * JERK_MULTIPLIER / fabs(unit[axis]);
 }
 
 
@@ -334,7 +334,7 @@ static float _calc_move_time(const float axis_length[],
   // Compute time required for rate-limiting axis
   for (int axis = 0; axis < AXES; axis++) {
     float time = fabs(axis_length[axis]) /
-      (rapid ? axes[axis].velocity_max : axes[axis].feedrate_max);
+      (rapid ? axis_get_velocity_max(axis) : axis_get_feedrate_max(axis));
 
     if (max_time < time) max_time = time;
   }
index 3e0ff1e39618addbdd1baa857f9e5344b21b8435..56966a632d66cf9b12646433234039e125928da5 100644 (file)
@@ -58,7 +58,7 @@
 
 #include "planner.h"
 
-#include "axes.h"
+#include "axis.h"
 #include "buffer.h"
 #include "machine.h"
 #include "stepper.h"
index 1bf26f261cbe0b66dbd50804097895d609c8cf79..5085847808bea93d148f5982e42e6419acb2e62a 100644 (file)
@@ -27,7 +27,7 @@
 \******************************************************************************/
 
 #include "machine.h"
-#include "axes.h"
+#include "axis.h"
 #include "spindle.h"
 #include "switch.h"
 #include "util.h"
@@ -63,7 +63,6 @@ typedef struct {
   // state saved from gcode model
   uint8_t saved_distance_mode;    // G90, G91 global setting
   uint8_t saved_coord_system;     // G54 - G59 setting
-  float saved_jerk[AXES];         // saved and restored for each axis
 
   // probe destination
   float start_position[AXES];
@@ -90,10 +89,6 @@ static void _probe_restore_settings() {
   // we should be stopped now, but in case of switch closure
   mp_flush_planner();
 
-  // restore axis jerk
-  for (int axis = 0; axis < AXES; axis++ )
-    axes_set_jerk(axis, pb.saved_jerk[axis]);
-
   // restore coordinate system and distance mode
   mach_set_coord_system(pb.saved_coord_system);
   mach_set_distance_mode(pb.saved_distance_mode);
@@ -155,17 +150,12 @@ static void _probing_init() {
   pb.state = PROBE_FAILED;
   mp_set_cycle(CYCLE_PROBING);
 
-  // initialize the axes - save the jerk settings & switch to the jerk_homing
-  // settings
-  for (int axis = 0; axis < AXES; axis++) {
-    pb.saved_jerk[axis] = axes_get_jerk(axis);   // save the max jerk value
-    // use homing jerk for probe
-    axes_set_jerk(axis, axes[axis].jerk_homing);
+  // initialize the axes
+  for (int axis = 0; axis < AXES; axis++)
     pb.start_position[axis] = mach_get_axis_position(axis);
-  }
 
   // error if the probe target is too close to the current position
-  if (axes_get_vector_length(pb.start_position, pb.target) <
+  if (axis_get_vector_length(pb.start_position, pb.target) <
       MINIMUM_PROBE_TRAVEL)
     _probing_error_exit(STAT_PROBE_INVALID_DEST);
 
index e7801d7f1ea73ee19ca133512632bffb1acce555..25d40eb3758bc393831af7e5f06f9bf674e96901 100644 (file)
@@ -49,7 +49,7 @@ static pwm_spindle_t spindle = {
   .max_rpm       = SPINDLE_MAX_RPM,
   .min_duty      = SPINDLE_MIN_DUTY,
   .max_duty      = SPINDLE_MAX_DUTY,
-  .reverse       = SPINDLE_POLARITY,
+  .reverse       = SPINDLE_REVERSE,
   .enable_invert = false,
   .estop         = false,
 };
@@ -144,8 +144,8 @@ float get_spin_min_pulse(int index) {return spindle.min_duty;}
 void set_spin_min_pulse(int axis, float value) {spindle.min_duty = value;}
 float get_spin_max_pulse(int index) {return spindle.max_duty;}
 void set_spin_max_pulse(int axis, float value) {spindle.max_duty = value;}
-uint8_t get_spin_polarity(int index) {return spindle.reverse;}
-void set_spin_polarity(int axis, uint8_t value) {spindle.reverse = value;}
+uint8_t get_spin_reverse(int index) {return spindle.reverse;}
+void set_spin_reverse(int axis, uint8_t value) {spindle.reverse = value;}
 float get_spin_up(int index) {return 0;}
 void set_spin_up(int axis, float value) {}
 float get_spin_down(int index) {return 0;}
index eae7d865c0ae367856f150f8223b2a336a52ebda..6896ee670d49ee40e5707494771d25af56588826 100644 (file)
@@ -58,7 +58,7 @@ static const char indexed_code_fmt[] PROGMEM = "\"%c%s\":";
 static const char bool_name [] PROGMEM = "<bool>";
 #define TYPE_NAME(TYPE) static const char TYPE##_name [] PROGMEM = "<" #TYPE ">"
 MAP(TYPE_NAME, SEMI, flags_t, string, pstring, float, uint8_t, uint16_t,
-    int32_t);
+    int32_t, char);
 
 
 // String
@@ -117,7 +117,6 @@ static bool var_parse_bool(const char *value) {
 }
 
 
-#if 0
 static uint8_t eeprom_read_bool(bool *addr) {
   return eeprom_read_byte((uint8_t *)addr);
 }
@@ -126,7 +125,21 @@ static uint8_t eeprom_read_bool(bool *addr) {
 static void eeprom_update_bool(bool *addr, bool value) {
   eeprom_update_byte((uint8_t *)addr, value);
 }
-#endif
+
+
+// Char
+static void var_print_char(char x) {putchar('"'); putchar(x); putchar('"');}
+static char var_parse_char(const char *value) {return value[0];}
+
+
+static uint8_t eeprom_read_char(char *addr) {
+  return eeprom_read_byte((uint8_t *)addr);
+}
+
+
+static void eeprom_update_char(char *addr, char value) {
+  eeprom_update_byte((uint8_t *)addr, value);
+}
 
 
 // int8
@@ -269,7 +282,7 @@ void vars_report(bool full) {
                                                                 \
       printf_P                                                  \
         (IF_ELSE(INDEX)(indexed_code_fmt, code_fmt),            \
-         IF(INDEX)(INDEX##_LABEL[i],) CODE);                    \
+         IF(INDEX)(INDEX##_LABEL[i],) #CODE);                   \
                                                                 \
       var_print_##TYPE(value);                                  \
     }                                                           \
@@ -293,7 +306,7 @@ int vars_find(const char *name) {
   if (!len) return -1;
 
 #define VAR(NAME, CODE, TYPE, INDEX, ...)                               \
-  if (!strcmp(IF_ELSE(INDEX)(name + 1, name), CODE)) {                  \
+  if (!strcmp(IF_ELSE(INDEX)(name + 1, name), #CODE)) {                 \
     IF(INDEX)                                                           \
       (i = strchr(INDEX##_LABEL, name[0]) - INDEX##_LABEL;              \
        if (INDEX <= i) return -1);                                      \
@@ -315,7 +328,7 @@ bool vars_print(const char *name) {
   if (!len) return false;
 
 #define VAR(NAME, CODE, TYPE, INDEX, ...)                               \
-  if (!strcmp(IF_ELSE(INDEX)(name + 1, name), CODE)) {                  \
+  if (!strcmp(IF_ELSE(INDEX)(name + 1, name), #CODE)) {                 \
     IF(INDEX)                                                           \
       (i = strchr(INDEX##_LABEL, name[0]) - INDEX##_LABEL;              \
        if (INDEX <= i) return false);                                   \
@@ -323,7 +336,7 @@ bool vars_print(const char *name) {
     putchar('{');                                                       \
     printf_P                                                            \
       (IF_ELSE(INDEX)(indexed_code_fmt, code_fmt),                      \
-       IF(INDEX)(INDEX##_LABEL[i],) CODE);                              \
+       IF(INDEX)(INDEX##_LABEL[i],) #CODE);                             \
     var_print_##TYPE(get_##NAME(IF(INDEX)(i)));                         \
     putchar('}');                                                       \
                                                                         \
@@ -345,7 +358,7 @@ bool vars_set(const char *name, const char *value) {
 
 #define VAR(NAME, CODE, TYPE, INDEX, SET, ...)                          \
   IF(SET)                                                               \
-    (if (!strcmp(IF_ELSE(INDEX)(name + 1, name), CODE)) {               \
+    (if (!strcmp(IF_ELSE(INDEX)(name + 1, name), #CODE)) {              \
       IF(INDEX)                                                         \
         (i = strchr(INDEX##_LABEL, name[0]) - INDEX##_LABEL;            \
          if (INDEX <= i) return false);                                 \
@@ -404,7 +417,7 @@ void vars_print_help() {
   uint8_t wd_state = hw_disable_watchdog();
 
 #define VAR(NAME, CODE, TYPE, ...)                               \
-  printf_P(fmt, CODE, NAME##_name, TYPE##_name, NAME##_help);
+  printf_P(fmt, #CODE, NAME##_name, TYPE##_name, NAME##_help);
 #include "vars.def"
 #undef VAR
 
index e2c8d6092f068cb289889b5e7fb3708c145340d9..c7f9dee6e94e86cad065ec0e7261efe28b994970 100644 (file)
 // VAR(name,        code, type,  index, settable, save, help)
 
 // Motor
-VAR(motor_axis,     "ma", uint8_t,  MOTORS, 1, 1, "Motor to axis mapping")
-VAR(step_angle,     "sa", float,    MOTORS, 1, 1, "In degrees per full step")
-VAR(travel,         "tr", float,    MOTORS, 1, 1, "Travel in mm per revolution")
-VAR(microstep,      "mi", uint16_t, MOTORS, 1, 1, "Microsteps per full step")
-VAR(polarity,       "po", uint8_t,  MOTORS, 1, 1, "Normal or reversed")
-
-VAR(power_mode,     "pm", uint8_t,  MOTORS, 1, 1, "Motor power mode")
-VAR(drive_power,    "dp", float,    MOTORS, 1, 1, "Motor drive power")
-VAR(idle_power,     "ip", float,    MOTORS, 1, 1, "Motor idle power")
-VAR(current_power,  "cp", float,    MOTORS, 0, 0, "Motor power now")
-VAR(status_flags,   "mf", uint8_t,  MOTORS, 0, 0, "Motor status flags")
-VAR(status_strings, "ms", flags_t,  MOTORS, 0, 0, "Motor status strings")
-VAR(motor_fault,    "mf", bool,     0,      0, 0, "Motor fault status")
+VAR(axis_name,      an, char,     MOTORS, 1, 1, "Maps motor to axis name")
+VAR(step_angle,     sa, float,    MOTORS, 1, 1, "In degrees per full step")
+VAR(travel,         tr, float,    MOTORS, 1, 1, "Travel in mm per revolution")
+VAR(microstep,      mi, uint16_t, MOTORS, 1, 1, "Microsteps per full step")
+VAR(reverse,        rv, uint8_t,  MOTORS, 1, 1, "Reverse motor polarity")
+
+VAR(power_mode,     pm, uint8_t,  MOTORS, 1, 1, "Motor power mode")
+VAR(drive_power,    dp, float,    MOTORS, 1, 1, "Motor drive power")
+VAR(idle_power,     ip, float,    MOTORS, 1, 1, "Motor idle power")
+VAR(current_power,  cp, float,    MOTORS, 0, 0, "Motor power now")
+VAR(status_flags,   mf, uint8_t,  MOTORS, 0, 0, "Motor status flags")
+VAR(status_strings, ms, flags_t,  MOTORS, 0, 0, "Motor status strings")
+
+VAR(motor_fault,    mf, bool,     0,      0, 0, "Motor fault status")
+
+VAR(velocity_max,   vm, float,    MOTORS, 1, 1, "Maxium velocity in mm/min")
+VAR(feedrate_max,   fr, float,    MOTORS, 1, 1, "Maxium feedrate in mm/min")
+VAR(jerk_max,       jm, float,    MOTORS, 1, 1, "Maxium jerk in mm/min^3")
+VAR(junction_dev,   jd, float,    MOTORS, 1, 1, "Junction deviation")
+VAR(radius,         ra, float,    MOTORS, 1, 1, "Axis radius or zero")
+
+// Homing
+VAR(homing_mode,    hm, uint8_t,  MOTORS, 1, 1, "Homing type")
+VAR(travel_min,     tn, float,    MOTORS, 1, 1, "Minimum soft limit")
+VAR(travel_max,     tm, float,    MOTORS, 1, 1, "Maximum soft limit")
+VAR(search_velocity,sv, float,    MOTORS, 1, 1, "Homing search velocity")
+VAR(latch_velocity, lv, float,    MOTORS, 1, 1, "Homing latch velocity")
+VAR(latch_backoff,  lb, float,    MOTORS, 1, 1, "Homing latch backof")
+VAR(zero_backoff,   zb, float,    MOTORS, 1, 1, "Homing zero backof")
 
 // Axis
-VAR(position,        "p", float,    AXES,   0, 0, "Current axis position")
-VAR(axis_mode,      "am", uint8_t,  AXES,   1, 1, "Axis mode")
-VAR(max_velocity,   "vm", float,    AXES,   1, 1, "Maxium velocity in mm/min")
-VAR(max_feedrate,   "fr", float,    AXES,   1, 1, "Maxium feedrate in mm/min")
-VAR(max_jerk,       "jm", float,    AXES,   1, 1, "Maxium jerk in mm/min^3")
-VAR(junction_dev,   "jd", float,    AXES,   1, 1, "Junction deviation")
-VAR(travel_min,     "tn", float,    AXES,   1, 1, "Minimum soft limit")
-VAR(travel_max,     "tm", float,    AXES,   1, 1, "Maximum soft limit")
-VAR(jerk_homing,    "jh", float,    AXES,   1, 1, "Maxium homing jerk")
-VAR(search_vel,     "sv", float,    AXES,   1, 1, "Homing search velocity")
-VAR(latch_vel,      "lv", float,    AXES,   1, 1, "Homing latch velocity")
-VAR(latch_backoff,  "lb", float,    AXES,   1, 1, "Homing latch backof")
-VAR(zero_backoff,   "zb", float,    AXES,   1, 1, "Homing zero backof")
+VAR(position,        p, float,    AXES,   0, 0, "Current axis position")
 
 // Spindle
-VAR(max_spin,       "sx", float,    0,      1, 1, "Maximum spindle speed")
-VAR(min_spin,       "sm", float,    0,      1, 1, "Minimum spindle speed")
-VAR(spindle_type,   "st", uint8_t,  0,      1, 1, "PWM=0 or HUANYANG=1")
-VAR(spin_min_pulse, "np", float,    0,      1, 1, "Minimum pulse width")
-VAR(spin_max_pulse, "mp", float,    0,      1, 1, "Maximum pulse width")
-VAR(spin_polarity,  "sp", uint8_t,  0,      1, 1, "Normal or reversed")
-VAR(spin_up,        "su", float,    0,      1, 1, "Spin up velocity")
-VAR(spin_down,      "sd", float,    0,      1, 1, "Spin down velocity")
+VAR(spindle_type,   st, uint8_t,  0,      1, 1, "PWM=0 or HUANYANG=1")
+VAR(spin_reverse,   sr, bool,     0,      1, 1, "Reverse spin")
+VAR(max_spin,       sx, float,    0,      1, 1, "Maximum spindle speed")
+VAR(min_spin,       sm, float,    0,      1, 1, "Minimum spindle speed")
+VAR(spin_min_pulse, np, float,    0,      1, 1, "Minimum pulse width")
+VAR(spin_max_pulse, mp, float,    0,      1, 1, "Maximum pulse width")
+VAR(spin_up,        su, float,    0,      1, 1, "Spin up velocity")
+VAR(spin_down,      sd, float,    0,      1, 1, "Spin down velocity")
 
 // Huanyang spindle
-VAR(huanyang_id,        "hi", uint8_t,  0,  1, 1, "Huanyang ID")
-VAR(huanyang_freq,      "hz", float,    0,  0, 0, "Huanyang actual freq")
-VAR(huanyang_current,   "hc", float,    0,  0, 0, "Huanyang actual current")
-VAR(huanyang_rpm,       "hr", uint16_t, 0,  0, 0, "Huanyang actual RPM")
-//VAR(huanyang_dcv,       "hd", uint16_t, 0,  0, 0, "Huanyang DC voltage")
-//VAR(huanyang_acv,       "ha", uint16_t, 0,  0, 0, "Huanyang AC voltage")
-VAR(huanyang_temp,      "ht", uint16_t, 0,  0, 0, "Huanyang temperature")
-VAR(huanyang_max_freq,  "hx", float,    0,  0, 0, "Huanyang max freq")
-VAR(huanyang_min_freq,  "hm", float,    0,  0, 0, "Huanyang min freq")
-VAR(huanyang_rated_rpm, "hq", uint16_t, 0,  0, 0, "Huanyang rated RPM")
-VAR(huanyang_status,    "hs", uint8_t,  0,  0, 0, "Huanyang status flags")
-VAR(huanyang_debug,     "hb", bool,     0,  1, 0, "Huanyang debugging")
-VAR(huanyang_connected, "he", bool,     0,  0, 0, "Huanyang connected")
+VAR(huanyang_id,        hi, uint8_t,  0,  1, 1, "Huanyang ID")
+VAR(huanyang_freq,      hz, float,    0,  0, 0, "Huanyang actual freq")
+VAR(huanyang_current,   hc, float,    0,  0, 0, "Huanyang actual current")
+VAR(huanyang_rpm,       hr, uint16_t, 0,  0, 0, "Huanyang actual RPM")
+//VAR(huanyang_dcv,       hd, uint16_t, 0,  0, 0, "Huanyang DC voltage")
+//VAR(huanyang_acv,       ha, uint16_t, 0,  0, 0, "Huanyang AC voltage")
+VAR(huanyang_temp,      ht, uint16_t, 0,  0, 0, "Huanyang temperature")
+VAR(huanyang_max_freq,  hx, float,    0,  0, 0, "Huanyang max freq")
+VAR(huanyang_min_freq,  hm, float,    0,  0, 0, "Huanyang min freq")
+VAR(huanyang_rated_rpm, hq, uint16_t, 0,  0, 0, "Huanyang rated RPM")
+VAR(huanyang_status,    hs, uint8_t,  0,  0, 0, "Huanyang status flags")
+VAR(huanyang_debug,     hb, bool,     0,  1, 0, "Huanyang debugging")
+VAR(huanyang_connected, he, bool,     0,  0, 0, "Huanyang connected")
 
 // Switches
-VAR(switch_type,    "sw", uint8_t,  SWITCHES, 1, 1, "Normally open or closed")
+VAR(switch_type,    sw, uint8_t,  SWITCHES, 1, 1, "Normally open or closed")
 
 // GCode
-VAR(line,           "ln", int32_t,  0,      0, 0, "Last GCode line executed")
-VAR(unit,            "u", pstring,  0,      0, 0, "Current unit of measure")
-VAR(speed,           "s", float,    0,      0, 0, "Current spindle speed")
-VAR(feed,            "f", float,    0,      0, 0, "Current feed rate")
-VAR(tool,            "t", uint8_t,  0,      0, 0, "Current tool")
-VAR(feed_mode,      "fm", pstring,  0,      0, 0, "Current feed rate mode")
-VAR(plane,          "pa", pstring,  0,      0, 0, "Current plane")
-VAR(coord_system,   "cs", pstring,  0,      0, 0, "Current coordinate system")
-VAR(abs_override,   "ao", bool,     0,      0, 0, "Absolute override enabled")
-VAR(path_mode,      "pc", pstring,  0,      0, 0, "Current path control mode")
-VAR(distance_mode,  "dm", pstring,  0,      0, 0, "Current distance mode")
-VAR(arc_dist_mode,  "ad", pstring,  0,      0, 0, "Current arc distance mode")
-VAR(mist_coolant,   "mc", bool,     0,      0, 0, "Mist coolant enabled")
-VAR(flood_coolant,  "fc", bool,     0,      0, 0, "Flood coolant enabled")
-VAR(feed_override,  "fo", float,    0,      0, 0, "Feed rate override")
-VAR(speed_override, "so", float,    0,      0, 0, "Spindle speed override")
+VAR(line,           ln, int32_t,  0,      0, 0, "Last GCode line executed")
+VAR(unit,            u, pstring,  0,      0, 0, "Current unit of measure")
+VAR(speed,           s, float,    0,      0, 0, "Current spindle speed")
+VAR(feed,            f, float,    0,      0, 0, "Current feed rate")
+VAR(tool,            t, uint8_t,  0,      0, 0, "Current tool")
+VAR(feed_mode,      fm, pstring,  0,      0, 0, "Current feed rate mode")
+VAR(plane,          pa, pstring,  0,      0, 0, "Current plane")
+VAR(coord_system,   cs, pstring,  0,      0, 0, "Current coordinate system")
+VAR(abs_override,   ao, bool,     0,      0, 0, "Absolute override enabled")
+VAR(path_mode,      pc, pstring,  0,      0, 0, "Current path control mode")
+VAR(distance_mode,  dm, pstring,  0,      0, 0, "Current distance mode")
+VAR(arc_dist_mode,  ad, pstring,  0,      0, 0, "Current arc distance mode")
+VAR(mist_coolant,   mc, bool,     0,      0, 0, "Mist coolant enabled")
+VAR(flood_coolant,  fc, bool,     0,      0, 0, "Flood coolant enabled")
+VAR(feed_override,  fo, float,    0,      0, 0, "Feed rate override")
+VAR(speed_override, so, float,    0,      0, 0, "Spindle speed override")
 
 // System
-VAR(velocity,        "v", float,    0,      0, 0, "Current velocity")
-VAR(hw_id,          "id", string,   0,      0, 0, "Hardware ID")
-VAR(echo,           "ec", bool,     0,      1, 0, "Enable or disable echo")
-VAR(estop,          "es", bool,     0,      1, 0, "Emergency stop")
-VAR(estop_reason,   "er", pstring,  0,      0, 0, "Emergency stop reason")
-VAR(state,           "x", pstring,  0,      0, 0, "Machine state")
-VAR(cycle,           "c", pstring,  0,      0, 0, "Machine cycle")
-VAR(hold_reason,    "pr", pstring,  0,      0, 0, "Machine pause reason")
+VAR(velocity,        v, float,    0,      0, 0, "Current velocity")
+VAR(hw_id,          id, string,   0,      0, 0, "Hardware ID")
+VAR(echo,           ec, bool,     0,      1, 0, "Enable or disable echo")
+VAR(estop,          es, bool,     0,      1, 0, "Emergency stop")
+VAR(estop_reason,   er, pstring,  0,      0, 0, "Emergency stop reason")
+VAR(state,           x, pstring,  0,      0, 0, "Machine state")
+VAR(cycle,           c, pstring,  0,      0, 0, "Machine cycle")
+VAR(hold_reason,    pr, pstring,  0,      0, 0, "Machine pause reason")