From ab1f0068c6f5603db5ec16fff8d38fea9750ec0d Mon Sep 17 00:00:00 2001 From: Joseph Coffland Date: Mon, 11 Mar 2019 12:15:17 -0700 Subject: [PATCH] Refer to motor channel number rather than axis --- src/avr/src/axis.c | 12 ----------- src/avr/src/axis.h | 2 -- src/avr/src/config.h | 48 +++++++++++++++++++++---------------------- src/avr/src/drv8711.c | 16 +++++++-------- src/avr/src/exec.c | 2 +- src/avr/src/motor.c | 16 +++++++-------- src/avr/src/switch.c | 24 +++++++++++----------- src/avr/src/switch.h | 12 +++++------ 8 files changed, 59 insertions(+), 73 deletions(-) diff --git a/src/avr/src/axis.c b/src/avr/src/axis.c index 0dea287..d85c002 100644 --- a/src/avr/src/axis.c +++ b/src/avr/src/axis.c @@ -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;} diff --git a/src/avr/src/axis.h b/src/avr/src/axis.h index e825a93..50aae9b 100644 --- a/src/avr/src/axis.h +++ b/src/avr/src/axis.h @@ -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); diff --git a/src/avr/src/config.h b/src/avr/src/config.h index b25aefb..791996e 100644 --- a/src/avr/src/config.h +++ b/src/avr/src/config.h @@ -34,23 +34,23 @@ // 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, diff --git a/src/avr/src/drv8711.c b/src/avr/src/drv8711.c index ad3893d..4ff98bc 100644 --- a/src/avr/src/drv8711.c +++ b/src/avr/src/drv8711.c @@ -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; } } diff --git a/src/avr/src/exec.c b/src/avr/src/exec.c index b4ad445..95979e8 100644 --- a/src/avr/src/exec.c +++ b/src/avr/src/exec.c @@ -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); } diff --git a/src/avr/src/motor.c b/src/avr/src/motor.c index 41113d1..a6172b8 100644 --- a/src/avr/src/motor.c +++ b/src/avr/src/motor.c @@ -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, diff --git a/src/avr/src/switch.c b/src/avr/src/switch.c index 3156a17..01233bc 100644 --- a/src/avr/src/switch.c +++ b/src/avr/src/switch.c @@ -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}, }; diff --git a/src/avr/src/switch.h b/src/avr/src/switch.h index f3d85e1..fb3a9d7 100644 --- a/src/avr/src/switch.h +++ b/src/avr/src/switch.h @@ -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; -- 2.27.0