Refer to motor channel number rather than axis
authorJoseph Coffland <joseph@cauldrondevelopment.com>
Mon, 11 Mar 2019 19:15:17 +0000 (12:15 -0700)
committerJoseph Coffland <joseph@cauldrondevelopment.com>
Mon, 11 Mar 2019 19:15:17 +0000 (12:15 -0700)
src/avr/src/axis.c
src/avr/src/axis.h
src/avr/src/config.h
src/avr/src/drv8711.c
src/avr/src/exec.c
src/avr/src/motor.c
src/avr/src/switch.c
src/avr/src/switch.h

index 0dea287f5704bc0d1099af48f80df1eeab13628b..d85c002f8d85104a97f43479cadfb116b5dd7108 100644 (file)
@@ -55,11 +55,6 @@ bool axis_is_enabled(int axis) {
 }
 
 
-char axis_get_char(int axis) {
-  return (axis < 0 || AXES <= axis) ? '?' : "XYZABCUVW"[axis];
-}
-
-
 int axis_get_id(char axis) {
   const char *axes = "XYZABCUVW";
   const char *ptr = strchr(axes, toupper(axis));
@@ -92,13 +87,6 @@ void axis_map_motors() {
 }
 
 
-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;}
 
index e825a93a071ecfc2519db65ac63c347245eb512a..50aae9bc1516ab628ec00570ccc04f6baefad54d 100644 (file)
@@ -39,13 +39,11 @@ enum {
 
 
 bool axis_is_enabled(int axis);
-char axis_get_char(int axis);
 int axis_get_id(char axis);
 int axis_get_motor(int axis);
 bool axis_get_homed(int axis);
 float axis_get_soft_limit(int axis, bool min);
 void axis_map_motors();
-float axis_get_vector_length(const float a[], const float b[]);
 
 float axis_get_velocity_max(int axis);
 float axis_get_accel_max(int axis);
index b25aefb366fcc470554d793b0126e1a06d0bf0aa..791996e79e9e64371a2d6d4fd9b52fade0400305 100644 (file)
 
 // Pins
 enum {
-  STALL_X_PIN = PIN_ID(PORT_A, 0),
-  STALL_Y_PIN,
-  STALL_Z_PIN,
-  STALL_A_PIN,
+  STALL_0_PIN = PIN_ID(PORT_A, 0),
+  STALL_1_PIN,
+  STALL_2_PIN,
+  STALL_3_PIN,
   TOOL_DIR_PIN,
   TOOL_ENABLE_PIN,
   ANALOG_1_PIN,
   ANALOG_2_PIN,
 
-  MIN_X_PIN = PIN_ID(PORT_B, 0),
-  MAX_X_PIN,
-  MIN_A_PIN,
-  MAX_A_PIN,
-  MIN_Y_PIN,
-  MAX_Y_PIN,
-  MIN_Z_PIN,
-  MAX_Z_PIN,
+  MIN_0_PIN = PIN_ID(PORT_B, 0),
+  MAX_0_PIN,
+  MIN_3_PIN,
+  MAX_3_PIN,
+  MIN_1_PIN,
+  MAX_1_PIN,
+  MIN_2_PIN,
+  MAX_2_PIN,
 
   SDA_PIN = PIN_ID(PORT_C, 0),
   SCL_PIN,
@@ -61,25 +61,25 @@ enum {
   SPI_MISO_PIN,
   SPI_MOSI_PIN,
 
-  STEP_X_PIN = PIN_ID(PORT_D, 0),
-  SPI_CS_X_PIN,
-  SPI_CS_A_PIN,
-  SPI_CS_Z_PIN,
+  STEP_0_PIN = PIN_ID(PORT_D, 0),
+  SPI_CS_0_PIN,
+  SPI_CS_3_PIN,
+  SPI_CS_2_PIN,
   PWM_PIN,
   SWITCH_2_PIN,
   RS485_RO_PIN,
   RS485_DI_PIN,
 
-  STEP_Y_PIN = PIN_ID(PORT_E, 0),
-  SPI_CS_Y_PIN,
-  DIR_X_PIN,
-  DIR_Y_PIN,
-  STEP_A_PIN,
+  STEP_1_PIN = PIN_ID(PORT_E, 0),
+  SPI_CS_1_PIN,
+  DIR_0_PIN,
+  DIR_1_PIN,
+  STEP_3_PIN,
   SWITCH_1_PIN,
-  DIR_Z_PIN,
-  DIR_A_PIN,
+  DIR_2_PIN,
+  DIR_3_PIN,
 
-  STEP_Z_PIN = PIN_ID(PORT_F, 0),
+  STEP_2_PIN = PIN_ID(PORT_F, 0),
   RS485_RW_PIN,
   FAULT_PIN,
   ESTOP_PIN,
index ad3893d373a24b3d845af44a483bb6d9da12b5a2..4ff98bc07cc1e0cab48e12c8d155f464e48bb1d4 100644 (file)
@@ -77,10 +77,10 @@ typedef struct {
 
 
 static drv8711_driver_t drivers[DRIVERS] = {
-  {.cs_pin = SPI_CS_X_PIN, .stall_sw = SW_STALL_X},
-  {.cs_pin = SPI_CS_Y_PIN, .stall_sw = SW_STALL_Y},
-  {.cs_pin = SPI_CS_Z_PIN, .stall_sw = SW_STALL_Z},
-  {.cs_pin = SPI_CS_A_PIN, .stall_sw = SW_STALL_A},
+  {.cs_pin = SPI_CS_0_PIN, .stall_sw = SW_STALL_0},
+  {.cs_pin = SPI_CS_1_PIN, .stall_sw = SW_STALL_1},
+  {.cs_pin = SPI_CS_2_PIN, .stall_sw = SW_STALL_2},
+  {.cs_pin = SPI_CS_3_PIN, .stall_sw = SW_STALL_3},
 };
 
 
@@ -330,10 +330,10 @@ static void _stall_change(int driver, bool stalled) {
 
 static void _stall_switch_cb(switch_id_t sw, bool active) {
   switch (sw) {
-  case SW_STALL_X: _stall_change(0, active); break;
-  case SW_STALL_Y: _stall_change(1, active); break;
-  case SW_STALL_Z: _stall_change(2, active); break;
-  case SW_STALL_A: _stall_change(3, active); break;
+  case SW_STALL_0: _stall_change(0, active); break;
+  case SW_STALL_1: _stall_change(1, active); break;
+  case SW_STALL_2: _stall_change(2, active); break;
+  case SW_STALL_3: _stall_change(3, active); break;
   default: break;
   }
 }
index b4ad4450a143093cc06452572e795ecab2d15e64..95979e83755e3f1d138e123fed8d7938eea6397c 100644 (file)
@@ -77,7 +77,7 @@ void exec_init() {
   ex.feed_override = 1; // TODO implement feed override
 
   // Set callback for limit switches
-  for (int sw = SW_MIN_X; sw <= SW_MAX_A; sw++)
+  for (int sw = SW_MIN_0; sw <= SW_MAX_3; sw++)
     switch_set_callback((switch_id_t)sw, _limit_switch_cb);
 }
 
index 41113d13808005191d41257a1cf02cff115a59cf..a6172b811bf5221ab71d8a413d2d3ec0625d244c 100644 (file)
@@ -88,29 +88,29 @@ typedef struct {
 static motor_t motors[MOTORS] = {
   {
     .axis            = AXIS_X,
-    .step_pin        = STEP_X_PIN,
-    .dir_pin         = DIR_X_PIN,
+    .step_pin        = STEP_0_PIN,
+    .dir_pin         = DIR_0_PIN,
     .timer           = &TCD0,
     .dma             = &DMA.CH0,
     .dma_trigger     = DMA_CH_TRIGSRC_TCD0_CCA_gc,
   }, {
     .axis            = AXIS_Y,
-    .step_pin        = STEP_Y_PIN,
-    .dir_pin         = DIR_Y_PIN,
+    .step_pin        = STEP_1_PIN,
+    .dir_pin         = DIR_1_PIN,
     .timer           = &TCE0,
     .dma             = &DMA.CH1,
     .dma_trigger     = DMA_CH_TRIGSRC_TCE0_CCA_gc,
   }, {
     .axis            = AXIS_Z,
-    .step_pin        = STEP_Z_PIN,
-    .dir_pin         = DIR_Z_PIN,
+    .step_pin        = STEP_2_PIN,
+    .dir_pin         = DIR_2_PIN,
     .timer           = &TCF0,
     .dma             = &DMA.CH2,
     .dma_trigger     = DMA_CH_TRIGSRC_TCF0_CCA_gc,
   }, {
     .axis            = AXIS_A,
-    .step_pin        = STEP_A_PIN,
-    .dir_pin         = DIR_A_PIN,
+    .step_pin        = STEP_3_PIN,
+    .dir_pin         = DIR_3_PIN,
     .timer           = (TC0_t *)&TCE1,
     .dma             = &DMA.CH3,
     .dma_trigger     = DMA_CH_TRIGSRC_TCE1_CCA_gc,
index 3156a17c0e9b6c62c068703ea8f302d51aa34c55..01233bcfc277e27f20e7753010d66b2df270e0d2 100644 (file)
@@ -48,18 +48,18 @@ typedef struct {
 static switch_t switches[] = {
   {.pin = ESTOP_PIN,       .type = SW_DISABLED},
   {.pin = PROBE_PIN,       .type = SW_DISABLED},
-  {.pin = MIN_X_PIN,       .type = SW_DISABLED},
-  {.pin = MAX_X_PIN,       .type = SW_DISABLED},
-  {.pin = MIN_Y_PIN,       .type = SW_DISABLED},
-  {.pin = MAX_Y_PIN,       .type = SW_DISABLED},
-  {.pin = MIN_Z_PIN,       .type = SW_DISABLED},
-  {.pin = MAX_Z_PIN,       .type = SW_DISABLED},
-  {.pin = MIN_A_PIN,       .type = SW_DISABLED},
-  {.pin = MAX_A_PIN,       .type = SW_DISABLED},
-  {.pin = STALL_X_PIN,     .type = SW_DISABLED},
-  {.pin = STALL_Y_PIN,     .type = SW_DISABLED},
-  {.pin = STALL_Z_PIN,     .type = SW_DISABLED},
-  {.pin = STALL_A_PIN,     .type = SW_DISABLED},
+  {.pin = MIN_0_PIN,       .type = SW_DISABLED},
+  {.pin = MAX_0_PIN,       .type = SW_DISABLED},
+  {.pin = MIN_1_PIN,       .type = SW_DISABLED},
+  {.pin = MAX_1_PIN,       .type = SW_DISABLED},
+  {.pin = MIN_2_PIN,       .type = SW_DISABLED},
+  {.pin = MAX_2_PIN,       .type = SW_DISABLED},
+  {.pin = MIN_3_PIN,       .type = SW_DISABLED},
+  {.pin = MAX_3_PIN,       .type = SW_DISABLED},
+  {.pin = STALL_0_PIN,     .type = SW_DISABLED},
+  {.pin = STALL_1_PIN,     .type = SW_DISABLED},
+  {.pin = STALL_2_PIN,     .type = SW_DISABLED},
+  {.pin = STALL_3_PIN,     .type = SW_DISABLED},
   {.pin = MOTOR_FAULT_PIN, .type = SW_DISABLED},
 };
 
index f3d85e17a5e0b92a1d373540259b2af1b77257a8..fb3a9d7e62a1472bce6c04fca810bff4ac094c66 100644 (file)
@@ -50,12 +50,12 @@ typedef enum {
 typedef enum {
   SW_INVALID = -1,
   SW_ESTOP, SW_PROBE,
-  SW_MIN_X, SW_MAX_X,
-  SW_MIN_Y, SW_MAX_Y,
-  SW_MIN_Z, SW_MAX_Z,
-  SW_MIN_A, SW_MAX_A,
-  SW_STALL_X, SW_STALL_Y,
-  SW_STALL_Z, SW_STALL_A,
+  SW_MIN_0, SW_MAX_0,
+  SW_MIN_1, SW_MAX_1,
+  SW_MIN_2, SW_MAX_2,
+  SW_MIN_3, SW_MAX_3,
+  SW_STALL_0, SW_STALL_1,
+  SW_STALL_2, SW_STALL_3,
   SW_MOTOR_FAULT,
 } switch_id_t;