From 639b6c13452f9810ad704e4ebd4b7861e448abb3 Mon Sep 17 00:00:00 2001 From: bdring Date: Mon, 21 Sep 2020 08:58:23 -0500 Subject: [PATCH] Devt (#609) * Fixed various small bugs (#605) * Fixed various small bugs * Fixed potential cast bug * Fixed double reporting of errors Co-authored-by: Stefan de Bruijn * Stallguard tuning (#607) * Devt (#571) * Handles Tranimic drivers errors better - If an unsupported driver is specified, it will give a message and not crash. * Cleaned up unused files Got rid of old unipolar files Got rid of servo axis feature - it is a motor class now Got rid of solenoid pen feature - never really used and it should be a motor class if it is. * Fix ENABLE_AUTHENTICATION (#569) * Fixed authentication code. * Removed another const cast Co-authored-by: Stefan de Bruijn * Fix step leakage with inverted steps (#570) * Fix step leakage with inverted steps * Update build date for merge Co-authored-by: Bart Dring Co-authored-by: Stefan de Bruijn Co-authored-by: Stefan de Bruijn Co-authored-by: Mitch Bradley Co-authored-by: Bart Dring * Update platformio.ini Per PR 583 * Created an enum for mode * Removing some unused machine defs * Added test machine definition * Clean up for PR * Remove test machine def. Co-authored-by: Stefan de Bruijn Co-authored-by: Stefan de Bruijn Co-authored-by: Mitch Bradley Co-authored-by: Bart Dring Co-authored-by: Stefan de Bruijn Co-authored-by: Stefan de Bruijn Co-authored-by: Mitch Bradley Co-authored-by: Bart Dring --- Grbl_Esp32/src/Grbl.h | 2 +- Grbl_Esp32/src/Machines/6_pack_trinamic_V1.h | 140 ------------------ .../src/Machines/6_pack_trinamic_stallguard.h | 19 +-- .../src/Machines/i2s_out_xyzabc_trinamic.h | 4 +- .../src/Machines/spi_daisy_4axis_xyyz.h | 4 +- Grbl_Esp32/src/Machines/spi_daisy_4axis_xyz.h | 4 +- .../src/Machines/spi_daisy_4axis_xyza.h | 2 +- Grbl_Esp32/src/Machines/tmc2130_pen.h | 4 +- Grbl_Esp32/src/Motors/TrinamicDriver.cpp | 14 +- Grbl_Esp32/src/Motors/TrinamicDriver.h | 23 ++- 10 files changed, 43 insertions(+), 173 deletions(-) delete mode 100644 Grbl_Esp32/src/Machines/6_pack_trinamic_V1.h diff --git a/Grbl_Esp32/src/Grbl.h b/Grbl_Esp32/src/Grbl.h index 1fb409dd..332a4f62 100644 --- a/Grbl_Esp32/src/Grbl.h +++ b/Grbl_Esp32/src/Grbl.h @@ -23,7 +23,7 @@ // Grbl versioning system const char* const GRBL_VERSION = "1.3a"; -const char* const GRBL_VERSION_BUILD = "20200910"; +const char* const GRBL_VERSION_BUILD = "20200919"; //#include #include diff --git a/Grbl_Esp32/src/Machines/6_pack_trinamic_V1.h b/Grbl_Esp32/src/Machines/6_pack_trinamic_V1.h deleted file mode 100644 index 9959dd1e..00000000 --- a/Grbl_Esp32/src/Machines/6_pack_trinamic_V1.h +++ /dev/null @@ -1,140 +0,0 @@ -#pragma once -// clang-format off - -/* - 6_pack_trinamic_V1.h - Part of Grbl_ESP32 - Pin assignments for the ESP32 SPI 6-axis board - 2018 - Bart Dring - 2020 - Mitch Bradley - 2020 - Michiyasu Odaki - Grbl_ESP32 is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - Grbl 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 General Public License for more details. - You should have received a copy of the GNU General Public License - along with Grbl_ESP32. If not, see . -*/ -#define MACHINE_NAME "6 Pack Controller V1 (Trinamic)" - -#define N_AXIS 6 - -// I2S (steppers & other output-only pins) -#define USE_I2S_OUT -#define USE_I2S_STEPS -//#define DEFAULT_STEPPER ST_I2S_STATIC - -#define I2S_OUT_BCK GPIO_NUM_22 -#define I2S_OUT_WS GPIO_NUM_17 -#define I2S_OUT_DATA GPIO_NUM_21 - - -#define TRINAMIC_RUN_MODE TRINAMIC_MODE_COOLSTEP -#define TRINAMIC_HOMING_MODE TRINAMIC_MODE_COOLSTEP - - -#define X_TRINAMIC_DRIVER 2130 -#define X_DISABLE_PIN I2SO(0) -#define X_DIRECTION_PIN I2SO(1) -#define X_STEP_PIN I2SO(2) -#define X_CS_PIN I2SO(3) -#define X_RSENSE TMC2130_RSENSE_DEFAULT - -#define Y_TRINAMIC_DRIVER X_TRINAMIC_DRIVER -#define Y_DIRECTION_PIN I2SO(4) -#define Y_STEP_PIN I2SO(5) -#define Y_DISABLE_PIN I2SO(7) -#define Y_CS_PIN I2SO(6) -#define Y_RSENSE X_RSENSE - -#define Z_TRINAMIC_DRIVER X_TRINAMIC_DRIVER -#define Z_DISABLE_PIN I2SO(8) -#define Z_DIRECTION_PIN I2SO(9) -#define Z_STEP_PIN I2SO(10) -#define Z_CS_PIN I2SO(11) -#define Z_RSENSE X_RSENSE - -#define A_TRINAMIC_DRIVER X_TRINAMIC_DRIVER -#define A_DIRECTION_PIN I2SO(12) -#define A_STEP_PIN I2SO(13) -#define A_DISABLE_PIN I2SO(15) -#define A_CS_PIN I2SO(14) -#define A_RSENSE X_RSENSE - -#define B_TRINAMIC_DRIVER X_TRINAMIC_DRIVER -#define B_DISABLE_PIN I2SO(16) -#define B_DIRECTION_PIN I2SO(17) -#define B_STEP_PIN I2SO(18) -#define B_CS_PIN I2SO(19) -#define B_RSENSE X_RSENSE - -#define C_TRINAMIC_DRIVER X_TRINAMIC_DRIVER -#define C_DIRECTION_PIN I2SO(20) -#define C_STEP_PIN I2SO(21) -#define C_DISABLE_PIN I2SO(23) -#define C_CS_PIN I2SO(22) -#define C_RSENSE X_RSENSE - -/* - Socket I/O reference - The list of modules is here... - https://github.com/bdring/6-Pack_CNC_Controller/wiki/CNC-I-O-Module-List - Click on each module to get example for using the modules in the sockets - -Socket #1 -#1 GPIO_NUM_33 -#2 GPIO_NUM_32 -#3 GPIO_NUM_35 (input only) -#4 GPIO_NUM_34 (input only) - -Socket #2 -#1 GPIO_NUM_2 -#2 GPIO_NUM_25 -#3 GPIO_NUM_39 (input only) -#4 GPIO_NUM_36 (input only) - -Socket #3 -#1 GPIO_NUM_26 -#2 GPIO_NUM_4 -#3 GPIO_NUM_16 -#4 GPIO_NUM_27 - -Socket #4 -#1 GPIO_NUM_14 -#2 GPIO_NUM_13 -#3 GPIO_NUM_15 -#4 GPIO_NUM_12 - -Socket #5 -#1 I2SO(24) (output only) -#2 I2SO(25) (output only) -#3 I2SO26) (output only) - -*/ - -// 4x Input Module in Socket #1 -// https://github.com/bdring/6-Pack_CNC_Controller/wiki/4x-Switch-Input-module -#define X_LIMIT_PIN GPIO_NUM_33 -#define Y_LIMIT_PIN GPIO_NUM_32 -#define Z_LIMIT_PIN GPIO_NUM_35 -#define A_LIMIT_PIN GPIO_NUM_34 - -// 4x Input Module in Socket #2 -// https://github.com/bdring/6-Pack_CNC_Controller/wiki/4x-Switch-Input-module -#define B_LIMIT_PIN GPIO_NUM_2 -#define C_LIMIT_PIN GPIO_NUM_25 -#define PROBE_PIN GPIO_NUM_39 - -// 0-10v CNC Module in Socket #3 -// https://github.com/bdring/6-Pack_CNC_Controller/wiki/0-10V-Output-Module -#define SPINDLE_TYPE SpindleType::PWM -#define SPINDLE_OUTPUT_PIN GPIO_NUM_26 -#define SPINDLE_ENABLE_PIN GPIO_NUM_4 -#define SPINDLE_DIR_PIN GPIO_NUM_16 - -// === Default settings -#define DEFAULT_STEP_PULSE_MICROSECONDS I2S_OUT_USEC_PER_PULSE diff --git a/Grbl_Esp32/src/Machines/6_pack_trinamic_stallguard.h b/Grbl_Esp32/src/Machines/6_pack_trinamic_stallguard.h index f5a9be34..83518936 100644 --- a/Grbl_Esp32/src/Machines/6_pack_trinamic_stallguard.h +++ b/Grbl_Esp32/src/Machines/6_pack_trinamic_stallguard.h @@ -32,9 +32,8 @@ #define I2S_OUT_WS GPIO_NUM_17 #define I2S_OUT_DATA GPIO_NUM_21 - -#define TRINAMIC_RUN_MODE TRINAMIC_MODE_COOLSTEP -#define TRINAMIC_HOMING_MODE TRINAMIC_MODE_STALLGUARD +#define TRINAMIC_RUN_MODE Motors::TrinamicMode::CoolStep +#define TRINAMIC_HOMING_MODE Motors::TrinamicMode::StallGuard // Motor Socket #1 #define X_TRINAMIC_DRIVER 2130 @@ -91,16 +90,16 @@ Click on each module to get example for using the modules in the sockets Socket #1 -#1 GPIO_NUM_33 -#2 GPIO_NUM_32 -#3 GPIO_NUM_35 (input only) -#4 GPIO_NUM_34 (input only) +#1 GPIO_NUM_33 (Sg1) +#2 GPIO_NUM_32 (Sg2) +#3 GPIO_NUM_35 (Sg3) (input only) +#4 GPIO_NUM_34 (Sg4) (input only) Socket #2 #1 GPIO_NUM_2 #2 GPIO_NUM_25 -#3 GPIO_NUM_39 (input only) -#4 GPIO_NUM_36 (input only) +#3 GPIO_NUM_39 (Sg5) (input only) +#4 GPIO_NUM_36 (Sg6) (input only) Socket #3 #1 GPIO_NUM_26 @@ -122,12 +121,14 @@ Socket #5 */ // Socket #1 (Empty) +// Install StallGuard Jumpers #define X_LIMIT_PIN GPIO_NUM_33 // Sg1 #define Y_LIMIT_PIN GPIO_NUM_32 // Sg2 #define Z_LIMIT_PIN GPIO_NUM_35 // Sg3 #define A_LIMIT_PIN GPIO_NUM_34 // Sg4 // Socket #2 (Empty) +// Install StallGuard Jumpers #define B_LIMIT_PIN GPIO_NUM_39 // Sg5 #define C_LIMIT_PIN GPIO_NUM_36 // Sg6 diff --git a/Grbl_Esp32/src/Machines/i2s_out_xyzabc_trinamic.h b/Grbl_Esp32/src/Machines/i2s_out_xyzabc_trinamic.h index cce3fa6c..3d5cffb7 100644 --- a/Grbl_Esp32/src/Machines/i2s_out_xyzabc_trinamic.h +++ b/Grbl_Esp32/src/Machines/i2s_out_xyzabc_trinamic.h @@ -37,8 +37,8 @@ #define I2S_OUT_WS GPIO_NUM_17 #define I2S_OUT_DATA GPIO_NUM_21 -#define TRINAMIC_RUN_MODE TRINAMIC_MODE_COOLSTEP -#define TRINAMIC_HOMING_MODE TRINAMIC_MODE_COOLSTEP +#define TRINAMIC_RUN_MODE TrinamicMode :: CoolStep +#define TRINAMIC_HOMING_MODE TrinamicMode :: CoolStep #define X_TRINAMIC_DRIVER 2130 #define X_DISABLE_PIN I2SO(0) diff --git a/Grbl_Esp32/src/Machines/spi_daisy_4axis_xyyz.h b/Grbl_Esp32/src/Machines/spi_daisy_4axis_xyyz.h index 1286b702..1bd15efd 100644 --- a/Grbl_Esp32/src/Machines/spi_daisy_4axis_xyyz.h +++ b/Grbl_Esp32/src/Machines/spi_daisy_4axis_xyyz.h @@ -35,8 +35,8 @@ #define TRINAMIC_DAISY_CHAIN -#define TRINAMIC_RUN_MODE TRINAMIC_MODE_COOLSTEP -#define TRINAMIC_HOMING_MODE TRINAMIC_MODE_COOLSTEP +#define TRINAMIC_RUN_MODE TrinamicMode :: CoolStep +#define TRINAMIC_HOMING_MODE TrinamicMode :: CoolStep // Use SPI enable instead of the enable pin // The hardware enable pin is tied to ground diff --git a/Grbl_Esp32/src/Machines/spi_daisy_4axis_xyz.h b/Grbl_Esp32/src/Machines/spi_daisy_4axis_xyz.h index 28ef76ea..fc9b45f6 100644 --- a/Grbl_Esp32/src/Machines/spi_daisy_4axis_xyz.h +++ b/Grbl_Esp32/src/Machines/spi_daisy_4axis_xyz.h @@ -35,8 +35,8 @@ #define TRINAMIC_DAISY_CHAIN -#define TRINAMIC_RUN_MODE TRINAMIC_MODE_COOLSTEP -#define TRINAMIC_HOMING_MODE TRINAMIC_MODE_COOLSTEP +#define TRINAMIC_RUN_MODE TrinamicMode :: CoolStep +#define TRINAMIC_HOMING_MODE TrinamicMode :: CoolStep // Use SPI enable instead of the enable pin // The hardware enable pin is tied to ground diff --git a/Grbl_Esp32/src/Machines/spi_daisy_4axis_xyza.h b/Grbl_Esp32/src/Machines/spi_daisy_4axis_xyza.h index 62baebd5..5ca27c61 100644 --- a/Grbl_Esp32/src/Machines/spi_daisy_4axis_xyza.h +++ b/Grbl_Esp32/src/Machines/spi_daisy_4axis_xyza.h @@ -35,7 +35,7 @@ #define TRINAMIC_DAISY_CHAIN -#define TRINAMIC_RUN_MODE TRINAMIC_MODE_STEALTHCHOP +#define TRINAMIC_RUN_MODE TrinamicMode::StealthChop // Use SPI enable instead of the enable pin // The hardware enable pin is tied to ground diff --git a/Grbl_Esp32/src/Machines/tmc2130_pen.h b/Grbl_Esp32/src/Machines/tmc2130_pen.h index c1477abb..8c938015 100644 --- a/Grbl_Esp32/src/Machines/tmc2130_pen.h +++ b/Grbl_Esp32/src/Machines/tmc2130_pen.h @@ -38,8 +38,8 @@ #define X_LIMIT_PIN GPIO_NUM_32 #endif -#define TRINAMIC_RUN_MODE TRINAMIC_MODE_COOLSTEP -#define TRINAMIC_HOMING_MODE TRINAMIC_MODE_COOLSTEP +#define TRINAMIC_RUN_MODE TrinamicMode :: CoolStep +#define TRINAMIC_HOMING_MODE TrinamicMode :: CoolStep #define X_STEP_PIN GPIO_NUM_12 #define X_DIRECTION_PIN GPIO_NUM_26 diff --git a/Grbl_Esp32/src/Motors/TrinamicDriver.cpp b/Grbl_Esp32/src/Motors/TrinamicDriver.cpp index e8ed5d93..f785862c 100644 --- a/Grbl_Esp32/src/Motors/TrinamicDriver.cpp +++ b/Grbl_Esp32/src/Motors/TrinamicDriver.cpp @@ -205,21 +205,21 @@ namespace Motors { _lastMode = _mode; switch (_mode) { - case TRINAMIC_MODE_STEALTHCHOP: - //grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "TRINAMIC_MODE_STEALTHCHOP"); + case TrinamicMode ::StealthChop: + //grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "StealthChop"); tmcstepper->en_pwm_mode(true); tmcstepper->pwm_autoscale(true); tmcstepper->diag1_stall(false); break; - case TRINAMIC_MODE_COOLSTEP: - //grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "TRINAMIC_MODE_COOLSTEP"); + case TrinamicMode :: CoolStep: + //grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Coolstep"); tmcstepper->en_pwm_mode(false); tmcstepper->pwm_autoscale(false); tmcstepper->TCOOLTHRS(NORMAL_TCOOLTHRS); // when to turn on coolstep tmcstepper->THIGH(NORMAL_THIGH); break; - case TRINAMIC_MODE_STALLGUARD: - //grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "TRINAMIC_MODE_STALLGUARD"); + case TrinamicMode ::StallGuard: + //grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Stallguard"); tmcstepper->en_pwm_mode(false); tmcstepper->pwm_autoscale(false); tmcstepper->TCOOLTHRS(calc_tstep(homing_feed_rate->get(), 150.0)); @@ -286,7 +286,7 @@ namespace Motors { if (_disabled) { tmcstepper->toff(TRINAMIC_TOFF_DISABLE); } else { - if (_mode == TRINAMIC_MODE_STEALTHCHOP) { + if (_mode == TrinamicMode::StealthChop) { tmcstepper->toff(TRINAMIC_TOFF_STEALTHCHOP); } else { tmcstepper->toff(TRINAMIC_TOFF_COOLSTEP); diff --git a/Grbl_Esp32/src/Motors/TrinamicDriver.h b/Grbl_Esp32/src/Motors/TrinamicDriver.h index 46475c61..d7e7b681 100644 --- a/Grbl_Esp32/src/Motors/TrinamicDriver.h +++ b/Grbl_Esp32/src/Motors/TrinamicDriver.h @@ -24,9 +24,9 @@ #include // https://github.com/teemuatlut/TMCStepper -#define TRINAMIC_MODE_STEALTHCHOP 0 // very quiet -#define TRINAMIC_MODE_COOLSTEP 1 // everything runs cooler so higher current possible -#define TRINAMIC_MODE_STALLGUARD 2 // coolstep plus generates stall indication +//#define TRINAMIC_MODE_STEALTHCHOP 0 // very quiet +//#define TRINAMIC_MODE_COOLSTEP 1 // everything runs cooler so higher current possible +//#define TRINAMIC_MODE_STALLGUARD 2 // coolstep plus generates stall indication const float TMC2130_RSENSE_DEFAULT = 0.11f; const float TMC5160_RSENSE_DEFAULT = 0.075f; @@ -39,8 +39,9 @@ const int TRINAMIC_SPI_FREQ = 100000; const double TRINAMIC_FCLK = 12700000.0; // Internal clock Approx (Hz) used to calculate TSTEP from homing rate // ==== defaults OK to define them in your machine definition ==== + #ifndef TRINAMIC_RUN_MODE -# define TRINAMIC_RUN_MODE TRINAMIC_MODE_COOLSTEP +# define TRINAMIC_RUN_MODE TrinamicMode ::StealthChop #endif #ifndef TRINAMIC_HOMING_MODE @@ -60,6 +61,14 @@ const double TRINAMIC_FCLK = 12700000.0; // Internal clock Approx (Hz) used to #endif namespace Motors { + + enum class TrinamicMode : uint8_t { + None = 0, // not for machine defs! + StealthChop = 1, + CoolStep = 2, + StallGuard = 3, + }; + class TrinamicDriver : public StandardStepper { public: TrinamicDriver(uint8_t axis_index, @@ -86,14 +95,14 @@ namespace Motors { uint32_t calc_tstep(float speed, float percent); TMC2130Stepper* tmcstepper; // all other driver types are subclasses of this one - uint8_t _homing_mode; + TrinamicMode _homing_mode; uint8_t cs_pin = UNDEFINED_PIN; // The chip select pin (can be the same for daisy chain) uint16_t _driver_part_number; // example: use 2130 for TMC2130 float _r_sense; int8_t spi_index; protected: - uint8_t _mode; - uint8_t _lastMode = 255; + TrinamicMode _mode; + TrinamicMode _lastMode = TrinamicMode::None; }; }