diff --git a/Grbl_Esp32/Custom/polar_coaster.cpp b/Grbl_Esp32/Custom/polar_coaster.cpp
index 1cd00c05..f5fbd5e2 100644
--- a/Grbl_Esp32/Custom/polar_coaster.cpp
+++ b/Grbl_Esp32/Custom/polar_coaster.cpp
@@ -68,7 +68,7 @@ bool kinematics_pre_homing(uint8_t cycle_mask) {
// cycle mask not used for polar coaster
// zero the axes that are not homed
sys_position[Y_AXIS] = 0.0f;
- sys_position[Z_AXIS] = SERVO_Z_RANGE_MAX * settings.steps_per_mm[Z_AXIS]; // Move pen up.
+ sys_position[Z_AXIS] = Z_SERVO_RANGE_MAX * settings.steps_per_mm[Z_AXIS]; // Move pen up.
return false; // finish normal homing cycle
}
diff --git a/Grbl_Esp32/Grbl_Esp32.ino b/Grbl_Esp32/Grbl_Esp32.ino
index 2ccbbd10..0fb364f5 100644
--- a/Grbl_Esp32/Grbl_Esp32.ino
+++ b/Grbl_Esp32/Grbl_Esp32.ino
@@ -69,9 +69,7 @@ void setup() {
#ifdef USE_PEN_SERVO
servo_init();
#endif
-#ifdef USE_SERVO_AXES
- init_servos();
-#endif
+
#ifdef USE_PEN_SOLENOID
solenoid_init();
#endif
diff --git a/Grbl_Esp32/Machines/3axis_v4.h b/Grbl_Esp32/Machines/3axis_v4.h
index 58439a23..b3d4be90 100644
--- a/Grbl_Esp32/Machines/3axis_v4.h
+++ b/Grbl_Esp32/Machines/3axis_v4.h
@@ -62,10 +62,9 @@
#define FLOOD_PIN GPIO_NUM_25 // labeled Flood
#define PROBE_PIN GPIO_NUM_32 // labeled Probe
-/*
#define CONTROL_SAFETY_DOOR_PIN GPIO_NUM_35 // labeled Door, needs external pullup
#define CONTROL_RESET_PIN GPIO_NUM_34 // labeled Reset, needs external pullup
#define CONTROL_FEED_HOLD_PIN GPIO_NUM_36 // labeled Hold, needs external pullup
#define CONTROL_CYCLE_START_PIN GPIO_NUM_39 // labeled Start, needs external pullup
-*/
+
diff --git a/Grbl_Esp32/Machines/foo_6axis.h b/Grbl_Esp32/Machines/foo_6axis.h
index d2222f79..7ba84e96 100644
--- a/Grbl_Esp32/Machines/foo_6axis.h
+++ b/Grbl_Esp32/Machines/foo_6axis.h
@@ -49,20 +49,17 @@
// C is a servo
// servos
-#define USE_SERVO_AXES
-#define SERVO_Z_PIN GPIO_NUM_22
-#define SERVO_Z_RANGE_MIN 0.0
-#define SERVO_Z_RANGE_MAX 5.0
-#define SERVO_Z_HOMING_TYPE SERVO_HOMING_TARGET // during homing it will instantly move to a target value
-#define SERVO_Z_HOME_POS SERVO_Z_RANGE_MAX // move to max during homing
-#define SERVO_Z_MPOS false // will not use mpos, uses work coordinates
-#define SERVO_C_PIN GPIO_NUM_2
-#define SERVO_C_RANGE_MIN 0.0
-#define SERVO_C_RANGE_MAX 5.0
-#define SERVO_C_HOMING_TYPE SERVO_HOMING_TARGET // during homing it will instantly move to a target value
-#define SERVO_C_HOME_POS SERVO_C_RANGE_MAX // move to max during homing
-#define SERVO_C_MPOS false // will not use mpos, uses work coordinates
+#define Z_SERVO
+#define Z_SERVO_PIN GPIO_NUM_22
+#define Z_SERVO_RANGE_MIN 0.0
+#define Z_SERVO_RANGE_MAX 5.0
+
+
+#define C_SERVO
+#define C_SERVO_PIN GPIO_NUM_2
+#define C_SERVO_RANGE_MIN 0.0
+#define C_SERVO_RANGE_MAX 5.0
// limit switches
#define X_LIMIT_PIN GPIO_NUM_21
diff --git a/Grbl_Esp32/Machines/midtbot.h b/Grbl_Esp32/Machines/midtbot.h
index c7249897..cd4190de 100644
--- a/Grbl_Esp32/Machines/midtbot.h
+++ b/Grbl_Esp32/Machines/midtbot.h
@@ -42,14 +42,10 @@
#define Y_LIMIT_PIN GPIO_NUM_4
#define LIMIT_MASK B11
-#define USE_SERVO_AXES
-
-#define SERVO_Z_PIN GPIO_NUM_27
-#define SERVO_Z_RANGE_MIN 0.0
-#define SERVO_Z_RANGE_MAX 5.0
-#define SERVO_Z_HOMING_TYPE SERVO_HOMING_TARGET // during homing it will instantly move to a target value
-#define SERVO_Z_HOME_POS SERVO_Z_RANGE_MAX // move to max during homing
-#define SERVO_Z_MPOS false // will not use mpos, uses work coordinates
+#define Z_SERVO
+#define Z_SERVO_PIN GPIO_NUM_27
+#define Z_SERVO_RANGE_MIN 0.0
+#define Z_SERVO_RANGE_MAX 5.0
// redefine some stuff from config.h
#ifdef HOMING_CYCLE_0
diff --git a/Grbl_Esp32/Machines/mpcnc_v1p1.h b/Grbl_Esp32/Machines/mpcnc_v1p1.h
index 37eb3bf6..6e116093 100644
--- a/Grbl_Esp32/Machines/mpcnc_v1p1.h
+++ b/Grbl_Esp32/Machines/mpcnc_v1p1.h
@@ -27,20 +27,23 @@
#define MACHINE_NAME "MPCNC_V1P1"
-#define USE_GANGED_AXES // allow two motors on an axis
+#define USE_GANGED_AXES // allow two motors on an axis
-#define X_STEP_PIN GPIO_NUM_12
-#define X2_STEP_PIN GPIO_NUM_22 // ganged motor
+#define X_STEP_PIN GPIO_NUM_12
+#define X_DIRECTION_PIN GPIO_NUM_26
+#define X2_STEP_PIN GPIO_NUM_22 // ganged motor
+#define X2_DIRECTION_PIN X_DIRECTION_PIN
#define X_AXIS_SQUARING
-#define Y_STEP_PIN GPIO_NUM_14
-#define Y2_STEP_PIN GPIO_NUM_21 // ganged motor
+
+#define Y_STEP_PIN GPIO_NUM_14
+#define Y_DIRECTION_PIN GPIO_NUM_25
+#define Y2_STEP_PIN GPIO_NUM_21 // ganged motor
+#define Y2_DIRECTION_PIN Y_DIRECTION_PIN
#define Y_AXIS_SQUARING
#define Z_STEP_PIN GPIO_NUM_27
-#define X_DIRECTION_PIN GPIO_NUM_26
-#define Y_DIRECTION_PIN GPIO_NUM_25
#define Z_DIRECTION_PIN GPIO_NUM_33
// OK to comment out to use pin for other features
diff --git a/Grbl_Esp32/Machines/pen_laser.h b/Grbl_Esp32/Machines/pen_laser.h
index adf297d6..6ca6f2e4 100644
--- a/Grbl_Esp32/Machines/pen_laser.h
+++ b/Grbl_Esp32/Machines/pen_laser.h
@@ -53,10 +53,10 @@
//#define USING_SOLENOID // uncomment to use this feature
#ifdef USING_SERVO
- #define USE_SERVO_AXES
- #define SERVO_Z_PIN GPIO_NUM_27
- #define SERVO_Z_RANGE_MIN 0.0
- #define SERVO_Z_RANGE_MAX 10.0
+ #define Z_SERVO
+ #define Z_SERVO_PIN GPIO_NUM_27
+ #define Z_SERVO_RANGE_MIN 0.0
+ #define Z_SERVO_RANGE_MAX 10.0
#endif
#ifdef USING_SOLENOID
diff --git a/Grbl_Esp32/Machines/polar_coaster.h b/Grbl_Esp32/Machines/polar_coaster.h
index 125fbcf4..dcfa50f6 100644
--- a/Grbl_Esp32/Machines/polar_coaster.h
+++ b/Grbl_Esp32/Machines/polar_coaster.h
@@ -45,14 +45,10 @@
#define STEPPERS_DISABLE_PIN GPIO_NUM_17
-#define USE_SERVO_AXES
-
-#define SERVO_Z_PIN GPIO_NUM_16
-#define SERVO_Z_RANGE_MIN 0.0
-#define SERVO_Z_RANGE_MAX 5.0
-#define SERVO_Z_HOMING_TYPE SERVO_HOMING_TARGET // during homing it will instantly move to a target value
-#define SERVO_Z_HOME_POS SERVO_Z_RANGE_MAX // move to max during homing
-#define SERVO_Z_MPOS false // will not use mpos, uses work coordinates
+#define Z_SERVO
+#define Z_SERVO_PIN GPIO_NUM_16
+#define Z_SERVO_RANGE_MIN 0.0
+#define Z_SERVO_RANGE_MAX 5.0
#define X_LIMIT_PIN GPIO_NUM_4
#define LIMIT_MASK B1
diff --git a/Grbl_Esp32/Machines/servo_axis.h b/Grbl_Esp32/Machines/servo_axis.h
deleted file mode 100644
index 792c9c53..00000000
--- a/Grbl_Esp32/Machines/servo_axis.h
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- servo_axis.h
- Part of Grbl_ESP32
-
- Pin assignments for the Buildlog.net pen laser controller V1
- using servos.
-
- For pen mode be sure to uncomment #define USE_PEN_SERVO in config.h
- For solenoid mode be sure to uncomment #define USE_PEN_SERVO in config.h
- For laser mode, you do not need to change anything
- Note: You can use all 3 modes at the same time if you want
-
- 2018 - Bart Dring
- 2020 - Mitch Bradley
-
- 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 "MACHINE_SERVO_AXIS"
-
-// Pick a board version
-//#define PEN_LASER_V1
-#define PEN_LASER_V2
-
-#define X_STEP_PIN GPIO_NUM_12
-#define X_DIRECTION_PIN GPIO_NUM_26
-
-#define STEPPERS_DISABLE_PIN GPIO_NUM_13
-
-#ifdef PEN_LASER_V1
- #define X_LIMIT_PIN GPIO_NUM_2
-#endif
-
-#ifdef PEN_LASER_V2
- #define X_LIMIT_PIN GPIO_NUM_15
-#endif
-
-#define Y_LIMIT_PIN GPIO_NUM_4
-#define LIMIT_MASK B11
-
-// If SPINDLE_OUTPUT_PIN is commented out, this frees up the pin, but Grbl will still
-// use a virtual spindle. Do not comment out the other parameters for the spindle.
-#define SPINDLE_OUTPUT_PIN GPIO_NUM_17 // Laser PWM
-// PWM Generator is based on 80,000,000 Hz counter
-// Therefor the freq determines the resolution
-// 80,000,000 / freq = max resolution
-// For 5000 that is 80,000,000 / 5000 = 16000
-// round down to nearest bit count for SPINDLE_PWM_MAX_VALUE
-//#define SPINDLE_PWM_BASE_FREQ 5000 // Hz
-#define SPINDLE_PWM_OFF_VALUE 0
-
-#ifndef SPINDLE_PWM_MIN_VALUE
- #define SPINDLE_PWM_MIN_VALUE 1 // Must be greater than zero.
-#endif
-
-#define SERVO_Y_PIN GPIO_NUM_14
-#define SERVO_Y_RANGE_MIN 0.0
-#define SERVO_Y_RANGE_MAX 30.0
-
-#define SERVO_Z_PIN GPIO_NUM_27
-#define SERVO_Z_RANGE_MIN 0.0
-#define SERVO_Z_RANGE_MAX 20.0
-
-// defaults
-#define DEFAULT_STEP_PULSE_MICROSECONDS 3
-#define DEFAULT_STEPPER_IDLE_LOCK_TIME 250 // stay on
-
-#define DEFAULT_STEPPING_INVERT_MASK 0 // uint8_t
-#define DEFAULT_DIRECTION_INVERT_MASK 0 // uint8_t
-#define DEFAULT_INVERT_ST_ENABLE 0 // boolean
-#define DEFAULT_INVERT_LIMIT_PINS 1 // boolean
-#define DEFAULT_INVERT_PROBE_PIN 0 // boolean
-
-#define DEFAULT_STATUS_REPORT_MASK 1
-
-#define DEFAULT_JUNCTION_DEVIATION 0.01 // mm
-#define DEFAULT_ARC_TOLERANCE 0.002 // mm
-#define DEFAULT_REPORT_INCHES 0 // false
-
-#define DEFAULT_SOFT_LIMIT_ENABLE 0 // false
-#define DEFAULT_HARD_LIMIT_ENABLE 0 // false
-
-#define DEFAULT_HOMING_ENABLE 0
-#define DEFAULT_HOMING_DIR_MASK 0 // move positive dir Z, negative X,Y
-#define DEFAULT_HOMING_FEED_RATE 200.0 // mm/min
-#define DEFAULT_HOMING_SEEK_RATE 1000.0 // mm/min
-#define DEFAULT_HOMING_DEBOUNCE_DELAY 250 // msec (0-65k)
-#define DEFAULT_HOMING_PULLOFF 3.0 // mm
-
-#define DEFAULT_SPINDLE_RPM_MAX 1000.0 // rpm
-#define DEFAULT_SPINDLE_RPM_MIN 0.0 // rpm
-
-#define DEFAULT_LASER_MODE 0 // false
-
-#define DEFAULT_X_STEPS_PER_MM 40 // half turn on a stepper
-#define DEFAULT_Y_STEPS_PER_MM 100.0 // default calibration value
-#define DEFAULT_Z_STEPS_PER_MM 100.0 // default calibration value
-
-#define DEFAULT_X_MAX_RATE 2000.0 // mm/min
-#define DEFAULT_Y_MAX_RATE 2000.0 // mm/min
-#define DEFAULT_Z_MAX_RATE 2000.0 // mm/min
-
-#define DEFAULT_X_ACCELERATION (50.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2
-#define DEFAULT_Y_ACCELERATION (50.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2
-#define DEFAULT_Z_ACCELERATION (50.0*60*60)
-
-#define DEFAULT_X_MAX_TRAVEL 300.0 // mm NOTE: Must be a positive value.
-#define DEFAULT_Y_MAX_TRAVEL 100.0 // default calibration value
-#define DEFAULT_Z_MAX_TRAVEL 100.0 // default calibration value
diff --git a/Grbl_Esp32/Machines/spi_daisy_4axis_xyyz.h b/Grbl_Esp32/Machines/spi_daisy_4axis_xyyz.h
index e57ba105..d4ba728d 100644
--- a/Grbl_Esp32/Machines/spi_daisy_4axis_xyyz.h
+++ b/Grbl_Esp32/Machines/spi_daisy_4axis_xyyz.h
@@ -41,37 +41,33 @@
#define USE_GANGED_AXES
// Y motor connects to the 1st driver
-#define X_TRINAMIC_DRIVER_TMC2130 // Which Driver Type?
-#define X_RSENSE TMC2130_RSENSE_DEFAULT
+#define X_TRINAMIC_DRIVER 2130 // Which Driver Type?
+#define X_RSENSE TMC2130_RSENSE_DEFAULT
#define X_STEP_PIN GPIO_NUM_12
#define X_DIRECTION_PIN GPIO_NUM_14
-#define X_TRINAMIC // using SPI control
#define X_CS_PIN GPIO_NUM_17 // Daisy Chain, all share same CS pin
// Y motor connects to the 2nd driver
-#define Y_TRINAMIC_DRIVER_TMC2130 // Which Driver Type?
+#define Y_TRINAMIC_DRIVER 2130 // Which Driver Type?
#define Y_RSENSE TMC2130_RSENSE_DEFAULT
#define Y_STEP_PIN GPIO_NUM_27
#define Y_DIRECTION_PIN GPIO_NUM_26
-#define Y_TRINAMIC // using SPI control
#define Y_CS_PIN X_CS_PIN // Daisy Chain, all share same CS pin
// Y2 motor connects to the 2nd driver
-#define Y2_TRINAMIC_DRIVER_TMC2130 // Which Driver Type?
+#define Y2_TRINAMIC_DRIVER 2130 // Which Driver Type?
#define Y2_RSENSE TMC2130_RSENSE_DEFAULT
#define Y2_STEP_PIN GPIO_NUM_15 // Z on schem
#define Y2_DIRECTION_PIN GPIO_NUM_2 // Z on schem
-#define Y2_TRINAMIC // using SPI control
#define Y2_CS_PIN X_CS_PIN // Daisy Chain, all share same CS pin
#define Y_AXIS_SQUARING // optional
// Z Axis motor connects to the 4th driver
-#define Z_TRINAMIC_DRIVER_TMC2130 // Which Driver Type?
+#define Z_TRINAMIC_DRIVER 2130 // Which Driver Type?
#define Z_RSENSE TMC2130_RSENSE_DEFAULT
#define Z_STEP_PIN GPIO_NUM_33 // A on schem
#define Z_DIRECTION_PIN GPIO_NUM_32 // A on schem
-#define Z_TRINAMIC // using SPI control
#define Z_CS_PIN X_CS_PIN // Daisy Chain, all share same CS pin
// Mist is a 3.3V output
diff --git a/Grbl_Esp32/Machines/spi_daisy_4axis_xyz.h b/Grbl_Esp32/Machines/spi_daisy_4axis_xyz.h
index db86af75..87662e62 100644
--- a/Grbl_Esp32/Machines/spi_daisy_4axis_xyz.h
+++ b/Grbl_Esp32/Machines/spi_daisy_4axis_xyz.h
@@ -37,25 +37,22 @@
// The hardware enable pin is tied to ground
#define USE_TRINAMIC_ENABLE
-#define X_TRINAMIC_DRIVER_TMC2130 // Which Driver Type?
+#define X_TRINAMIC_DRIVER 2130 // Which Driver Type?
#define X_RSENSE TMC2130_RSENSE_DEFAULT
#define X_STEP_PIN GPIO_NUM_12
#define X_DIRECTION_PIN GPIO_NUM_14
-#define X_TRINAMIC // using SPI control
#define X_CS_PIN GPIO_NUM_17 // Daisy Chain, all share same CS pin
-#define Y_TRINAMIC_DRIVER_TMC2130 // Which Driver Type?
+#define Y_TRINAMIC_DRIVER 2130 // Which Driver Type?
#define Y_RSENSE TMC2130_RSENSE_DEFAULT
#define Y_STEP_PIN GPIO_NUM_27
#define Y_DIRECTION_PIN GPIO_NUM_26
-#define Y_TRINAMIC // using SPI control
#define Y_CS_PIN X_CS_PIN // Daisy Chain, all share same CS pin
-#define Z_TRINAMIC_DRIVER_TMC2130 // Which Driver Type?
+#define Z_TRINAMIC_DRIVER 2130 // Which Driver Type?
#define Z_RSENSE TMC2130_RSENSE_DEFAULT
#define Z_STEP_PIN GPIO_NUM_15
#define Z_DIRECTION_PIN GPIO_NUM_2
-#define Z_TRINAMIC // using SPI control
#define Z_CS_PIN X_CS_PIN // Daisy Chain, all share same CS pin
diff --git a/Grbl_Esp32/Machines/spi_daisy_4axis_xyza.h b/Grbl_Esp32/Machines/spi_daisy_4axis_xyza.h
index 25f7cfe6..5163fd65 100644
--- a/Grbl_Esp32/Machines/spi_daisy_4axis_xyza.h
+++ b/Grbl_Esp32/Machines/spi_daisy_4axis_xyza.h
@@ -37,34 +37,30 @@
// The hardware enable pin is tied to ground
#define USE_TRINAMIC_ENABLE
-#define X_TRINAMIC_DRIVER_TMC2130 // Which Driver Type?
+#define X_TRINAMIC_DRIVER 2130 // Which Driver Type?
#define X_RSENSE TMC2130_RSENSE_DEFAULT
#define X_STEP_PIN GPIO_NUM_12
#define X_DIRECTION_PIN GPIO_NUM_14
-#define X_TRINAMIC // using SPI control
#define X_CS_PIN GPIO_NUM_17 // Daisy Chain, all share same CS pin
-#define Y_TRINAMIC_DRIVER_TMC2130 // Which Driver Type?
+#define Y_TRINAMIC_DRIVER 2130 // Which Driver Type?
#define Y_RSENSE TMC2130_RSENSE_DEFAULT
#define Y_STEP_PIN GPIO_NUM_27
#define Y_DIRECTION_PIN GPIO_NUM_26
-#define Y_TRINAMIC // using SPI control
#define Y_CS_PIN X_CS_PIN // Daisy Chain, all share same CS pin
-#define Z_TRINAMIC_DRIVER_TMC2130 // Which Driver Type?
+#define Z_TRINAMIC_DRIVER 2130 // Which Driver Type?
#define Z_RSENSE TMC2130_RSENSE_DEFAULT
#define Z_STEP_PIN GPIO_NUM_15
#define Z_DIRECTION_PIN GPIO_NUM_2
-#define Z_TRINAMIC // using SPI control
#define Z_CS_PIN X_CS_PIN // Daisy Chain, all share same CS pin
-#define A_TRINAMIC_DRIVER_TMC2130 // Which Driver Type?
-#define A_RSENSE TMC2130_RSENSE_DEFAULT
-#define A_STEP_PIN GPIO_NUM_33
-#define A_DIRECTION_PIN GPIO_NUM_32
-#define A_TRINAMIC // using SPI control
-#define A_CS_PIN X_CS_PIN // Daisy Chain, all share same CS pin
+#define A_TRINAMIC_DRIVER 2130 // Which Driver Type?
+#define A_RSENSE TMC2130_RSENSE_DEFAULT
+#define A_STEP_PIN GPIO_NUM_33
+#define A_DIRECTION_PIN GPIO_NUM_32
+#define A_CS_PIN X_CS_PIN // Daisy Chain, all share same CS pin
// Mist is a 3.3V output
// Turn on with M7 and off with M9
diff --git a/Grbl_Esp32/Machines/template.h b/Grbl_Esp32/Machines/template.h
index 46325bb2..9b668dd7 100644
--- a/Grbl_Esp32/Machines/template.h
+++ b/Grbl_Esp32/Machines/template.h
@@ -237,9 +237,8 @@
// drivers that require software configuration at startup.
// There are several options that control the details of such
// drivers; inspect the code in grbl_triaminic.cpp to see them.
-// #define USE_TRIAMINIC
-// #define X_TRIAMINIC
-// #define X_TRINAMIC_DRIVER_TMC2209
+
+// #define X_TRINAMIC_DRIVE 2130
// #define TRIAMINIC_DAISY_CHAIN
// USE_MACHINE_TRINAMIC_INIT enables the machine_triaminic_setup()
diff --git a/Grbl_Esp32/Machines/tmc2130_pen.h b/Grbl_Esp32/Machines/tmc2130_pen.h
index e293590b..409a1a02 100644
--- a/Grbl_Esp32/Machines/tmc2130_pen.h
+++ b/Grbl_Esp32/Machines/tmc2130_pen.h
@@ -39,15 +39,13 @@
#define X_STEP_PIN GPIO_NUM_12
#define X_DIRECTION_PIN GPIO_NUM_26
-#define X_TRINAMIC // using SPI control
-#define X_TRINAMIC_DRIVER_TMC2130 // Which Driver Type?
+#define X_TRINAMIC_DRIVER 2130 // Which Driver Type?
#define X_CS_PIN GPIO_NUM_17 //chip select
#define X_RSENSE TMC2130_RSENSE_DEFAULT
#define Y_STEP_PIN GPIO_NUM_14
#define Y_DIRECTION_PIN GPIO_NUM_25
-#define Y_TRINAMIC // using SPI control
-#define Y_TRINAMIC_DRIVER_TMC2130 // Which Driver Type?
+#define Y_TRINAMIC_DRIVER 2130 // Which Driver Type?
#define Y_CS_PIN GPIO_NUM_16 //chip select
#define Y_RSENSE TMC2130_RSENSE_DEFAULT
@@ -63,12 +61,10 @@
#ifdef USE_SERVO_AXES
#define SPINDLE_TYPE SPINDLE_TYPE_NONE
- #define SERVO_Z_PIN GPIO_NUM_27 // comment this out if PWM spindle/laser control.
- #define SERVO_Z_RANGE_MIN 0.0
- #define SERVO_Z_RANGE_MAX 5.0
- #define SERVO_Z_HOMING_TYPE SERVO_HOMING_TARGET // during homing it will instantly move to a target value
- #define SERVO_Z_HOME_POS SERVO_Z_RANGE_MAX // move to max during homing
- #define SERVO_Z_MPOS false // will not use mpos, uses work coordinates
+ #define Z_SERVO
+ #define Z_SERVO_PIN GPIO_NUM_27 // comment this out if PWM spindle/laser control.
+ #define Z_SERVO_RANGE_MIN 0.0
+ #define Z_SERVO_RANGE_MAX 5.0
#else
#define SPINDLE_TYPE SPINDLE_TYPE_PWM
diff --git a/Grbl_Esp32/Motors/MotorClass.cpp b/Grbl_Esp32/Motors/MotorClass.cpp
index 2931bd4f..c0bd5e6b 100644
--- a/Grbl_Esp32/Motors/MotorClass.cpp
+++ b/Grbl_Esp32/Motors/MotorClass.cpp
@@ -19,6 +19,7 @@
TODO
Make sure public/private/protected is cleaned up.
Only a few Unipolar axes have been setup in init()
+ Get rid of Z_SERVO, just reply on Z_SERVO_PIN
Deal with custom machine ... machine_trinamic_setup();
Class is ready to deal with non SPI pins, but they have not been needed yet.
@@ -77,7 +78,7 @@ void init_motors() {
myMotor[X_AXIS][1] = new TrinamicDriver(X2_AXIS, X2_STEP_PIN, X2_DIRECTION_PIN, X2_TRINAMIC_DRIVER, X2_RSENSE, X2_CS_PIN, get_next_trinamic_driver_index());
#elif defined(X2_SERVO)
myMotor[X_AXIS][1] = new RcServo(X2_AXIS, X2_SERVO_PIN), X2_SERVO_RANGE_MIN, X2_SERVO_RANGE_MAX;
-#elif defined(X_UNIPOLAR)
+#elif defined(X2_UNIPOLAR)
myMotor[X_AXIS][1] = new UnipolarMotor(X2_AXIS, X2_PIN_PHASE_0, X2_PIN_PHASE_1, X2_PIN_PHASE_2, X2_PIN_PHASE_3);
#elif defined(X2_STEP_PIN)
myMotor[X_AXIS][1] = new StandardStepper(X2_AXIS, X2_STEP_PIN, X2_DIRECTION_PIN);
diff --git a/Grbl_Esp32/Motors/MotorClass.h b/Grbl_Esp32/Motors/MotorClass.h
index 7404e8d0..64000737 100644
--- a/Grbl_Esp32/Motors/MotorClass.h
+++ b/Grbl_Esp32/Motors/MotorClass.h
@@ -80,7 +80,6 @@ void motors_set_homing_mode(bool is_homing);
void motors_set_disable(bool disable);
void motors_set_direction_pins(uint8_t onMask);
void motors_step(uint8_t step_mask, uint8_t dir_mask);
-
void servoUpdateTask(void* pvParameters);
extern bool motor_class_steps; // true if at least one motor class is handling steps
@@ -104,15 +103,16 @@ class Motor {
virtual void update();
motor_class_id_t type_id;
+ uint8_t is_active = false;
+
+ protected:
uint8_t axis_index; // X_AXIS, etc
uint8_t dual_axis_index; // 0 = primary 1=ganged
- uint8_t is_active = false;
+
bool _showError;
bool _use_mpos = true;
-
bool _is_homing;
char _axis_name[10];// this the name to use when reporting like "X" or "X2"
-
};
class Nullmotor : public Motor {
@@ -130,6 +130,8 @@ class StandardStepper : public Motor {
void init_step_dir_pins();
gpio_num_t step_pin;
+
+ protected:
bool _invert_step_pin;
uint8_t dir_pin;
uint8_t enable_pin;
@@ -137,6 +139,8 @@ class StandardStepper : public Motor {
class TrinamicDriver : public StandardStepper {
public:
+ TrinamicDriver(uint8_t axis_index, gpio_num_t step_pin, uint8_t dir_pin, uint16_t driver_part_number, float r_sense, uint8_t cs_pin, int8_t spi_index);
+
void config_message();
void init();
void set_mode();
@@ -148,17 +152,15 @@ class TrinamicDriver : public StandardStepper {
void set_disable(bool disable);
bool test();
+ private:
+ uint32_t calc_tstep(float speed, float percent);
+
+ TMC2130Stepper* tmcstepper; // all other driver types are subclasses of this one
uint8_t _homing_mode;
uint8_t cs_pin = UNDEFINED_PIN; // The chip select pin (can be the same for daisy chain)
-
- TrinamicDriver(uint8_t axis_index, gpio_num_t step_pin, uint8_t dir_pin, uint16_t driver_part_number, float r_sense, uint8_t cs_pin, int8_t spi_index);
-
- private:
- TMC2130Stepper* tmcstepper; // all other driver types are subclasses of this one
uint16_t _driver_part_number; // example: use 2130 for TMC2130
float _r_sense;
int8_t spi_index;
- uint32_t calc_tstep(float speed, float percent);
};
@@ -167,11 +169,11 @@ class UnipolarMotor : public Motor {
UnipolarMotor();
UnipolarMotor(uint8_t axis_index, uint8_t pin_phase0, uint8_t pin_phase1, uint8_t pin_phase2, uint8_t pin_phase3);
void init();
- //void read_settings();
void config_message();
void set_disable(bool disable);
void step(uint8_t step_mask, uint8_t dir_mask); // only used on Unipolar right now
+ private:
uint8_t _pin_phase0;
uint8_t _pin_phase1;
uint8_t _pin_phase2;
@@ -182,7 +184,7 @@ class UnipolarMotor : public Motor {
};
class RcServo : public Motor {
- public:
+ public:
RcServo();
RcServo(uint8_t axis_index, uint8_t pwm_pin, float min, float max);
void config_message();
@@ -192,22 +194,20 @@ class RcServo : public Motor {
void update();
void read_settings();
+ private:
+ void set_location();
+ void _get_calibration();
+
uint8_t _pwm_pin;
uint8_t _channel_num;
uint32_t _current_pwm_duty;
-
+
float _position_min;
float _position_max; // position in millimeters
- float _homing_position;
+ float _homing_position;
float servo_pulse_min;
float servo_pulse_max;
-
- void set_location();
- void _get_calibration();
};
-
-
-
#endif
diff --git a/Grbl_Esp32/Motors/StandardStepperClass.cpp b/Grbl_Esp32/Motors/StandardStepperClass.cpp
index b65418e1..a2ab97ed 100644
--- a/Grbl_Esp32/Motors/StandardStepperClass.cpp
+++ b/Grbl_Esp32/Motors/StandardStepperClass.cpp
@@ -32,15 +32,15 @@ StandardStepper :: StandardStepper(uint8_t axis_index, gpio_num_t step_pin, uint
this->dual_axis_index = axis_index < MAX_AXES ? 0 : 1; // 0 = primary 1 = ganged
this->step_pin = step_pin;
this->dir_pin = dir_pin;
- set_axis_name();
init();
- config_message();
}
void StandardStepper :: init() {
- init_step_dir_pins();
_is_homing = false;
- is_active = true; // as opposed to NullMotors, this is a real motor
+ is_active = true; // as opposed to NullMotors, this is a real motor
+ set_axis_name();
+ init_step_dir_pins();
+ config_message();
}
void StandardStepper :: init_step_dir_pins() {
diff --git a/Grbl_Esp32/grbl.h b/Grbl_Esp32/grbl.h
index 1123665a..62ab1769 100644
--- a/Grbl_Esp32/grbl.h
+++ b/Grbl_Esp32/grbl.h
@@ -83,11 +83,6 @@
#include "solenoid_pen.h"
-#ifdef USE_SERVO_AXES
- #include "servo_axis.h"
-#endif
-
-
#ifdef USE_UNIPOLAR
#include "grbl_unipolar.h"
#endif
diff --git a/Grbl_Esp32/machine.h b/Grbl_Esp32/machine.h
index 27f1d5a7..56fb3959 100644
--- a/Grbl_Esp32/machine.h
+++ b/Grbl_Esp32/machine.h
@@ -16,7 +16,7 @@ PWM
// !!! For initial testing, start with test_drive.h which disables
// all I/O pins
-#include "Machines/motor_class_test.h"
+#include "Machines/tmc2130_pen.h"
// !!! For actual use, change the line above to select a board
// from Machines/, for example:
diff --git a/Grbl_Esp32/servo_axis.cpp b/Grbl_Esp32/servo_axis.cpp
deleted file mode 100644
index 1125f800..00000000
--- a/Grbl_Esp32/servo_axis.cpp
+++ /dev/null
@@ -1,387 +0,0 @@
-/*
- servo_axis.cpp
- Part of Grbl_ESP32
-
- copyright (c) 2018 - Bart Dring. This file was intended for use on the ESP32
- CPU. Do not use this with Grbl for atMega328P
-
- Grbl 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. If not, see .
-
- See servo_axis.h for more details
-
-*/
-
-#include "grbl.h"
-
-#ifdef USE_SERVO_AXES
-
-static TaskHandle_t servosSyncTaskHandle = 0;
-
-#ifdef SERVO_X_PIN
- ServoAxis X_Servo_Axis(X_AXIS, SERVO_X_PIN);
-#endif
-#ifdef SERVO_Y_PIN
- ServoAxis Y_Servo_Axis(Y_AXIS, SERVO_Y_PIN);
-#endif
-#ifdef SERVO_Z_PIN
- ServoAxis Z_Servo_Axis(Z_AXIS, SERVO_Z_PIN);
-#endif
-
-#ifdef SERVO_A_PIN
- ServoAxis A_Servo_Axis(A_AXIS, SERVO_A_PIN);
-#endif
-#ifdef SERVO_B_PIN
- ServoAxis B_Servo_Axis(B_AXIS, SERVO_B_PIN);
-#endif
-#ifdef SERVO_C_PIN
- ServoAxis C_Servo_Axis(C_AXIS, SERVO_C_PIN);
-#endif
-
-void init_servos() {
- // ======================== X Axis ===========================
-#ifdef SERVO_X_PIN
- grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "X Servo range %4.3f to %4.3f", SERVO_X_RANGE_MIN, SERVO_X_RANGE_MAX);
- X_Servo_Axis.init();
- X_Servo_Axis.set_range(SERVO_X_RANGE_MIN, SERVO_X_RANGE_MAX);
-#ifdef SERVO_X_HOMING_TYPE
- X_Servo_Axis.set_homing_type(SERVO_X_HOMING_TYPE);
-#endif
-#ifdef SERVO_X_HOME_POS
- X_Servo_Axis.set_homing_position(SERVO_X_HOME_POS);
-#endif
-#ifdef SERVO_X_MPOS // value should be true or false
- X_Servo_Axis.set_use_mpos(SERVO_X_MPOS);
-#endif
-#ifdef SERVO_X_DISABLE_ON_ALARM
- set_disable_on_alarm(SERVO_X_DISABLE_ON_ALARM);
-#endif
-#ifdef SERVO_X_DISABLE_WITH_STEPPERS
- set_disable_with_steppers(SERVO_X_DISABLE_WITH_STEPPERS);
-#endif
-#endif
- // ======================== Y Axis ===========================
-#ifdef SERVO_Y_PIN
- grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "Y Servo range %4.3f to %4.3f", SERVO_Y_RANGE_MIN, SERVO_Y_RANGE_MAX);
- Y_Servo_Axis.init();
- Y_Servo_Axis.set_range(SERVO_Y_RANGE_MIN, SERVO_Y_RANGE_MAX);
-#ifdef SERVO_Y_HOMING_TYPE
- Y_Servo_Axis.set_homing_type(SERVO_Y_HOMING_TYPE);
-#endif
-#ifdef SERVO_Y_HOME_POS
- Y_Servo_Axis.set_homing_position(SERVO_Y_HOME_POS);
-#endif
-#ifdef SERVO_Y_MPOS // value should be true or false
- Y_Servo_Axis.set_use_mpos(SERVO_Y_MPOS);
-#endif
-#ifdef SERVO_Y_DISABLE_ON_ALARM
- set_disable_on_alarm(SERVO_Y_DISABLE_ON_ALARM);
-#endif
-#ifdef SERVO_Y_DISABLE_WITH_STEPPERS
- set_disable_with_steppers(SERVO_Y_DISABLE_WITH_STEPPERS);
-#endif
-#endif
- // ======================== Z Axis ===========================
-#ifdef SERVO_Z_PIN
- grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "Z Servo range %4.3f to %4.3f", SERVO_Z_RANGE_MIN, SERVO_Z_RANGE_MAX);
- Z_Servo_Axis.init();
- Z_Servo_Axis.set_range(SERVO_Z_RANGE_MIN, SERVO_Z_RANGE_MAX);
-#ifdef SERVO_Z_HOMING_TYPE
- Z_Servo_Axis.set_homing_type(SERVO_Z_HOMING_TYPE);
-#endif
-#ifdef SERVO_Z_HOME_POS
- Z_Servo_Axis.set_homing_position(SERVO_Z_HOME_POS);
-#endif
-#ifdef SERVO_Z_MPOS // value should be true or false
- Z_Servo_Axis.set_use_mpos(SERVO_Z_MPOS);
-#endif
-#ifdef SERVO_Z_DISABLE_ON_ALARM
- set_disable_on_alarm(SERVO_Z_DISABLE_ON_ALARM);
-#endif
-#ifdef SERVO_Z_DISABLE_WITH_STEPPERS
- set_disable_with_steppers(SERVO_Z_DISABLE_WITH_STEPPERS);
-#endif
-#endif
- // ======================== A Axis ===========================
-#ifdef SERVO_A_PIN
- grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "A Servo range %4.3f to %4.3f", SERVO_A_RANGE_MIN, SERVO_A_RANGE_MAX);
- A_Servo_Axis.init();
- A_Servo_Axis.set_range(SERVO_A_RANGE_MIN, SERVO_A_RANGE_MAX);
-#ifdef SERVO_A_HOMING_TYPE
- A_Servo_Axis.set_homing_type(SERVO_A_HOMING_TYPE);
-#endif
-#ifdef SERVO_A_HOME_POS
- A_Servo_Axis.set_homing_position(SERVO_A_HOME_POS);
-#endif
-#ifdef SERVO_A_MPOS // value should be true or false
- A_Servo_Axis.set_use_mpos(SERVO_A_MPOS);
-#endif
-#ifdef SERVO_A_DISABLE_ON_ALARM
- set_disable_on_alarm(SERVO_A_DISABLE_ON_ALARM);
-#endif
-#ifdef SERVO_A_DISABLE_WITH_STEPPERS
- set_disable_with_steppers(SERVO_A_DISABLE_WITH_STEPPERS);
-#endif
-#endif
- // ======================== B Axis ===========================
-#ifdef SERVO_B_PIN
- grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "B Servo range %4.3f to %4.3f", SERVO_B_RANGE_MIN, SERVO_B_RANGE_MAX);
- B_Servo_Axis.init();
- B_Servo_Axis.set_range(SERVO_B_RANGE_MIN, SERVO_B_RANGE_MAX);
-#ifdef SERVO_B_HOMING_TYPE
- B_Servo_Axis.set_homing_type(SERVO_B_HOMING_TYPE);
-#endif
-#ifdef SERVO_B_HOME_POS
- B_Servo_Axis.set_homing_position(SERVO_B_HOME_POS);
-#endif
-#ifdef SERVO_B_MPOS // value should be true or false
- B_Servo_Axis.set_use_mpos(SERVO_B_MPOS);
-#endif
-#ifdef SERVO_B_DISABLE_ON_ALARM
- set_disable_on_alarm(SERVO_B_DISABLE_ON_ALARM);
-#endif
-#ifdef SERVO_B_DISABLE_WITH_STEPPERS
- set_disable_with_steppers(SERVO_B_DISABLE_WITH_STEPPERS);
-#endif
-#endif
- // ======================== C Axis ===========================
-#ifdef SERVO_C_PIN
- grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "C Servo range %4.3f to %4.3f", SERVO_C_RANGE_MIN, SERVO_C_RANGE_MAX);
- C_Servo_Axis.init();
- C_Servo_Axis.set_range(SERVO_C_RANGE_MIN, SERVO_C_RANGE_MAX);
-#ifdef SERVO_C_HOMING_TYPE
- C_Servo_Axis.set_homing_type(SERVO_C_HOMING_TYPE);
-#endif
-#ifdef SERVO_C_HOME_POS
- C_Servo_Axis.set_homing_position(SERVO_C_HOME_POS);
-#endif
-#ifdef SERVO_C_MPOS // value should be true or false
- C_Servo_Axis.set_use_mpos(SERVO_C_MPOS);
-#endif
-#ifdef SERVO_C_DISABLE_ON_ALARM
- set_disable_on_alarm(SERVO_C_DISABLE_ON_ALARM);
-#endif
-#ifdef SERVO_C_DISABLE_WITH_STEPPERS
- set_disable_with_steppers(SERVO_C_DISABLE_WITH_STEPPERS);
-#endif
-#endif
- // setup a task that will calculate the determine and set the servo positions
- xTaskCreatePinnedToCore(servosSyncTask, // task
- "servosSyncTask", // name for task
- 4096, // size of task stack
- NULL, // parameters
- 1, // priority
- &servosSyncTaskHandle,
- 0 // core
- );
-}
-
-
-// this is the task
-void servosSyncTask(void* pvParameters) {
- TickType_t xLastWakeTime;
- const TickType_t xServoFrequency = SERVO_TIMER_INT_FREQ; // in ticks (typically ms)
- xLastWakeTime = xTaskGetTickCount(); // Initialise the xLastWakeTime variable with the current time.
- while (true) { // don't ever return from this or the task dies
-#ifdef SERVO_X_PIN
- X_Servo_Axis.set_location();
-#endif
-#ifdef SERVO_Y_PIN
- Y_Servo_Axis.set_location();
-#endif
-#ifdef SERVO_Z_PIN
- Z_Servo_Axis.set_location();
-#endif
-#ifdef SERVO_A_PIN
- A_Servo_Axis.set_location();
-#endif
-#ifdef SERVO_B_PIN
- B_Servo_Axis.set_location();
-#endif
-#ifdef SERVO_C_PIN
- C_Servo_Axis.set_location();
-#endif
- vTaskDelayUntil(&xLastWakeTime, xServoFrequency);
- }
-}
-
-// =============================== Class Stuff ================================= //
-
-ServoAxis::ServoAxis(uint8_t axis, uint8_t pin_num) { // constructor
- _axis = axis;
- _pin_num = pin_num;
- _channel_num = sys_get_next_PWM_chan_num();
- _showError = true; // this will be used to show calibration error only once
- _use_mpos = true; // default is to use the machine position rather than work position
-}
-
-void ServoAxis::init() {
- _cal_is_valid();
- ledcSetup(_channel_num, _pwm_freq, _pwm_resolution_bits);
- ledcAttachPin(_pin_num, _channel_num);
- disable();
-}
-
-void ServoAxis::set_location() {
- // These are the pulse lengths for the minimum and maximum positions
- // Note: Some machines will have the physical max/min inverted with pulse length max/min due to invert setting $3=...
- float servo_pulse_min, servo_pulse_max;
- float min_pulse_cal, max_pulse_cal; // calibration values in percent 110% = 1.1
- uint32_t servo_pulse_len;
- float servo_pos, mpos, offset;
- // skip location if we are in alarm mode
- if (_disable_on_alarm && (sys.state == STATE_ALARM)) {
- disable();
- return;
- }
- // track the disable status of the steppers if desired.
- /* TODO Fix in MotorClass
- if (_disable_with_steppers && get_stepper_disable()) {
- disable();
- return;
- }
- */
- if ((_homing_type == SERVO_HOMING_TARGET) && (sys.state == STATE_HOMING)) {
- servo_pos = _homing_position; // go to servos home position
- } else {
- mpos = system_convert_axis_steps_to_mpos(sys_position, _axis); // get the axis machine position in mm
- if (_use_mpos)
- servo_pos = mpos;
- else {
- offset = gc_state.coord_system[_axis] + gc_state.coord_offset[_axis]; // get the current axis work offset
- servo_pos = mpos - offset; // determine the current work position
- }
- }
- // 1. Get the pulse ranges of the servos
- // 2. Invert if selected in the settings
- // 3. Get the calibration values from the settings
- // 4. Adjust the calibration offset direction of the cal based on the direction
- // 5. Apply the calibrarion
- servo_pulse_min = SERVO_MIN_PULSE;
- servo_pulse_max = SERVO_MAX_PULSE;
- if (bit_istrue(settings.dir_invert_mask, bit(_axis))) // this allows the user to change the direction via settings
- swap(servo_pulse_min, servo_pulse_max);
- // get the calibration values
- if (_cal_is_valid()) { // if calibration settings are OK then apply them
- // apply a calibration
- // the cals apply differently if the direction is reverse (i.e. longer pulse is lower position)
- if (bit_isfalse(settings.dir_invert_mask, bit(_axis))) { // normal direction
- min_pulse_cal = 2.0 - (settings.steps_per_mm[_axis] / 100.0);
- max_pulse_cal = (settings.max_travel[_axis] / -100.0);
- } else { // inverted direction
- min_pulse_cal = (settings.steps_per_mm[_axis] / 100.0);
- max_pulse_cal = 2.0 - (settings.max_travel[_axis] / -100.0);
- }
- } else { // settings are not valid so don't apply any calibration
- min_pulse_cal = 1.0;
- max_pulse_cal = 1.0;
- }
- // apply the calibrations
- servo_pulse_min *= min_pulse_cal;
- servo_pulse_max *= max_pulse_cal;
- // determine the pulse length
- servo_pulse_len = (uint32_t)mapConstrain(servo_pos, _position_min, _position_max, servo_pulse_min, servo_pulse_max);
- _write_pwm(servo_pulse_len);
-}
-
-void ServoAxis::_write_pwm(uint32_t duty) {
- if (ledcRead(_channel_num) != duty) // only write if it is changing
- ledcWrite(_channel_num, duty);
-}
-
-// sets the PWM to zero. This allows most servos to be manually moved
-void ServoAxis::disable() {
- _write_pwm(0);
-}
-
-// checks to see if calibration values are in an acceptable range
-// vebose = true if you want an error sent to serial port
-bool ServoAxis::_cal_is_valid() {
- bool settingsOK = true;
- if ((settings.steps_per_mm[_axis] < SERVO_CAL_MIN) || (settings.steps_per_mm[_axis] > SERVO_CAL_MAX)) {
- if (_showError) {
- grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "Servo calibration ($10%d) value error. Reset to 100", _axis);
- settings.steps_per_mm[_axis] = 100;
- write_global_settings();
- }
- settingsOK = false;
- }
- // Note: Max travel is set positive via $$, but stored as a negative number
- if ((settings.max_travel[_axis] < -SERVO_CAL_MAX) || (settings.max_travel[_axis] > -SERVO_CAL_MIN)) {
- if (_showError) {
- grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "Servo calibration ($13%d) value error. Reset to 100", _axis);
- settings.max_travel[_axis] = -100;
- write_global_settings();
- }
- settingsOK = false;
- }
- _showError = false; // to show error once
- if (! settingsOK) {
- write_global_settings(); // they were changed so write them to
- }
- return settingsOK;
-}
-
-/*
- Use this to set the max and min position in mm of the servo
- This is used when mapping pulse length to the position
-*/
-void ServoAxis::set_range(float min, float max) {
- if (min < max) {
- _position_min = min;
- _position_max = max;
- } else
- grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "Error setting range. Min not smaller than max");
-}
-
-/*
- Sets the mode the servo will be in during homing
- See servo_axis.h for SERVO_HOMING_xxxxx types
-*/
-void ServoAxis::set_homing_type(uint8_t homing_type) {
- if (homing_type <= SERVO_HOMING_TARGET)
- _homing_type = homing_type;
-}
-
-/*
- Use this to set the homing position the servo will be commanded to go if
- the current homing mode is SERVO_HOMING_TARGET
-*/
-void ServoAxis::set_homing_position(float homing_position) {
- _homing_position = homing_position;
-}
-
-/*
- Use this to set the disable on alarm feature. If true, then hobby servo PWM
- will be disable in Grbl alarm mode (like before homing). Typical hobby servo
- can be moved by hand in this mode
-*/
-void ServoAxis::set_disable_on_alarm(bool disable_on_alarm) {
- _disable_on_alarm = disable_on_alarm;
-}
-
-void ServoAxis::set_disable_with_steppers(bool disable_with_steppers) {
- _disable_with_steppers = disable_with_steppers;
-}
-
-/*
- If true, servo position will alway be calculated in machine position
- Offsets will not be applied
-*/
-void ServoAxis::set_use_mpos(bool use_mpos) {
- _use_mpos = use_mpos;
-}
-
-
-
-#endif
diff --git a/Grbl_Esp32/servo_axis.h b/Grbl_Esp32/servo_axis.h
deleted file mode 100644
index 75d4bb35..00000000
--- a/Grbl_Esp32/servo_axis.h
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- solenoid_pen.h
- Part of Grbl_ESP32
-
- copyright (c) 2019 - Bart Dring. This file was intended for use on the ESP32
- CPU. Do not use this with Grbl for atMega328P
-
- Grbl 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. If not, see .
-
- Servo Axis Class
-
- The Servo axis feature allows you to use a hobby servo on any axis.
- This is done using a repeating RTOS task. Grbl continues to calculate
- the position of the axis in real time. The task looks at the current position of
- the axis and calculates the required PWM value to go to that location. You define the travel
- of the servo in millimeters.
-
- Grbl still uses the acceleration and speed values you have in the settings, so it
- will coordinate servo axes with stepper motor axes. This assumes these values are within the
- capabilities of the servo
-
- Usage
-
- 1. In config.h un-comment #define USE_SERVO_AXES
-
- 2. In the machine definition file in Machines/, define servo pins and PWM channels like this ....
- #define SERVO_Y_PIN GPIO_NUM_14
-
- undefine any step and direction pins associated with that axis
-
- 3. In servo_axis.cpp init_servos() function, configure servos like this ....
- X_Servo_Axis.set_range(0.0, 20.0); // millimeter
- X_Servo_Axis.set_homing_type(SERVO_HOMING_OFF);
- X_Servo_Axis.set_disable_on_alarm(true);
-
-
- The positions can be calibrated using the settings. $10x (resolution) settings adjust the minimum
- position and $13x (max travel) settings adjust the maximum position. If the servo is traveling
- backwards from what you want, you can use the $3 direction setting to compensate.
-
-*/
-
-#ifndef servo_axis_h
-#define servo_axis_h
-
-
-
-// this is the pulse range of a the servo. Typical servos are 0.001 to 0.002 seconds
-// some servos have a wider range. You can adjust this here or in the calibration feature
-#define SERVO_MIN_PULSE_SEC 0.001 // min pulse in seconds
-#define SERVO_MAX_PULSE_SEC 0.002 // max pulse in seconds
-
-#define SERVO_POSITION_MIN_DEFAULT 0.0 // mm
-#define SERVO_POSITION_MAX_DEFAULT 20.0 // mm
-
-#define SERVO_PULSE_FREQ 50 // 50Hz ...This is a standard analog servo value. Digital ones can repeat faster
-
-#define SERVO_PULSE_RES_BITS 16 // bits of resolution of PWM (16 is max)
-#define SERVO_PULSE_RES_COUNT 65535 // see above TODO...do the math here 2^SERVO_PULSE_RES_BITS
-
-#define SERVO_TIME_PER_BIT ((1.0 / (float)SERVO_PULSE_FREQ) / ((float)SERVO_PULSE_RES_COUNT) ) // seconds
-
-#define SERVO_MIN_PULSE (uint16_t)(SERVO_MIN_PULSE_SEC / SERVO_TIME_PER_BIT) // in timer counts
-#define SERVO_MAX_PULSE (uint16_t)(SERVO_MAX_PULSE_SEC / SERVO_TIME_PER_BIT) // in timer counts
-
-#define SERVO_PULSE_RANGE (SERVO_MAX_PULSE-SERVO_MIN_PULSE)
-
-#define SERVO_CAL_MIN 20.0 // Percent: the minimum allowable calibration value
-#define SERVO_CAL_MAX 180.0 // Percent: the maximum allowable calibration value
-
-#define SERVO_TIMER_INT_FREQ 20.0 // Hz This is the task frequency
-
-#define SERVO_HOMING_OFF 0 // servo is off during homing
-#define SERVO_HOMING_TARGET 1 // servo is send to a location during homing
-
-extern float my_location;
-
-void init_servos();
-void servosSyncTask(void* pvParameters);
-
-
-class ServoAxis {
- public:
- ServoAxis(uint8_t axis, uint8_t pin_num); // constructor
- void init();
- void set_location();
- void disable(); // sets PWM to 0% duty cycle. Most servos can be manually moved in this state
- void set_range(float min, float max);
- void set_homing_type(uint8_t homing_type);
- void set_homing_position(float homing_position);
- void set_disable_on_alarm(bool disable_on_alarm);
- void set_disable_with_steppers(bool disable_with_steppers);
- void set_use_mpos(bool use_mpos);
-
- private:
- int _axis; // these should be assign in constructor using Grbl X_AXIS type values
- int _pin_num; // The GPIO pin being used
- int _channel_num; // The PWM channel
- bool _showError;
-
- uint32_t _pwm_freq = SERVO_PULSE_FREQ;
- uint32_t _pwm_resolution_bits = SERVO_PULSE_RES_BITS;
- float _pulse_min = SERVO_MIN_PULSE; // in pwm counts
- float _pulse_max = SERVO_MAX_PULSE; // in pwm counts
- float _position_min = SERVO_POSITION_MIN_DEFAULT; // position in millimeters
- float _position_max = SERVO_POSITION_MAX_DEFAULT; // position in millimeters
-
-
- uint8_t _homing_type = SERVO_HOMING_OFF;
- float _homing_position = SERVO_POSITION_MAX_DEFAULT;
- bool _disable_on_alarm = true;
- bool _disable_with_steppers = false;
- bool _use_mpos = true;
-
- bool _validate_cal_settings();
- void _write_pwm(uint32_t duty);
- bool _cal_is_valid(); // checks to see if calibration values are in acceptable range
-
-};
-
-#endif
diff --git a/Grbl_Esp32/stepper.cpp b/Grbl_Esp32/stepper.cpp
index 2cf689fe..92f47738 100644
--- a/Grbl_Esp32/stepper.cpp
+++ b/Grbl_Esp32/stepper.cpp
@@ -563,8 +563,8 @@ inline IRAM_ATTR static void stepperRMT_Outputs() {
RMT.conf_ch[rmt_chan_num[Z_AXIS][PRIMARY_MOTOR]].conf1.tx_start = 1;
}
if ((ganged_mode == SQUARING_MODE_DUAL) || (ganged_mode == SQUARING_MODE_B)) {
- RMT.conf_ch[Z2_rmt_chan_num].conf1.mem_rd_rst = 1;
- RMT.conf_ch[Z2_rmt_chan_num].conf1.tx_start = 1;
+ RMT.conf_ch[rmt_chan_num[Z_AXIS][GANGED_MOTOR]].conf1.mem_rd_rst = 1;
+ RMT.conf_ch[rmt_chan_num[Z_AXIS][GANGED_MOTOR]].conf1.tx_start = 1;
}
#endif
}