diff --git a/Grbl_Esp32/cpu_map.h b/Grbl_Esp32/cpu_map.h index 70dcf8a8..9bb957d0 100644 --- a/Grbl_Esp32/cpu_map.h +++ b/Grbl_Esp32/cpu_map.h @@ -462,136 +462,8 @@ #endif -#ifdef CPU_MAP_POLAR_COASTER // The Buildlog.net pen polar coaster controller V1 - #define CPU_MAP_NAME "CPU_MAP_POLAR_COASTER" - - #define USE_KINEMATICS - #define FWD_KINEMATICS_REPORTING // report in cartesian - #include "polar_coaster.h" - - #define USE_RMT_STEPS - - #define X_STEP_PIN GPIO_NUM_15 - #define X_RMT_CHANNEL 0 - #define Y_STEP_PIN GPIO_NUM_2 - #define Y_RMT_CHANNEL 1 - #define X_DIRECTION_PIN GPIO_NUM_25 - #define Y_DIRECTION_PIN GPIO_NUM_26 - - #define STEPPERS_DISABLE_PIN GPIO_NUM_17 - - #ifndef USE_SERVO_AXES // maybe set in config.h - #define USE_SERVO_AXES - #endif - - #define SERVO_Z_PIN GPIO_NUM_16 - #define SERVO_Z_CHANNEL_NUM 5 - #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 X_LIMIT_PIN GPIO_NUM_4 - #define LIMIT_MASK B1 - - #ifdef IGNORE_CONTROL_PINS // maybe set in config.h - #undef IGNORE_CONTROL_PINS - #endif - - #ifndef ENABLE_CONTROL_SW_DEBOUNCE - #define ENABLE_CONTROL_SW_DEBOUNCE - #endif - - #define MACRO_BUTTON_0_PIN GPIO_NUM_13 - #define MACRO_BUTTON_1_PIN GPIO_NUM_12 - #define MACRO_BUTTON_2_PIN GPIO_NUM_14 - - // If SPINDLE_PWM_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_PWM_PIN GPIO_NUM_17 - #define SPINDLE_PWM_CHANNEL 0 - // 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 = 13bits (8192) - //#define SPINDLE_PWM_BASE_FREQ 5000 // Hz - #define SPINDLE_PWM_BIT_PRECISION 8 // be sure to match this with SPINDLE_PWM_MAX_VALUE - #define SPINDLE_PWM_OFF_VALUE 0 - #define SPINDLE_PWM_MAX_VALUE 255 // (2^SPINDLE_PWM_BIT_PRECISION) - - #ifndef SPINDLE_PWM_MIN_VALUE - #define SPINDLE_PWM_MIN_VALUE 1 // Must be greater than zero. - #endif - - - //#define USE_PEN_SERVO - //#define SERVO_PEN_PIN GPIO_NUM_16 - - // redefine some stuff from config.h - #ifdef HOMING_CYCLE_0 - #undef HOMING_CYCLE_0 - #endif - #define HOMING_CYCLE_0 (1< #include diff --git a/Grbl_Esp32/motion_control.cpp b/Grbl_Esp32/motion_control.cpp index 440f091a..fa23fcaa 100644 --- a/Grbl_Esp32/motion_control.cpp +++ b/Grbl_Esp32/motion_control.cpp @@ -240,9 +240,10 @@ void mc_homing_cycle(uint8_t cycle_mask) // This give kinematics a chance to do something before normal homing // if it returns true, the homing is canceled. - #ifdef USE_KINEMATICS - if (!kinematics_homing(cycle_mask)) - return; + #ifdef USE_KINEMATICS + if (kinematics_pre_homing(cycle_mask)) { + return; + } #endif // Check and abort homing cycle, if hard limits are already enabled. Helps prevent problems @@ -330,6 +331,11 @@ void mc_homing_cycle(uint8_t cycle_mask) gc_sync_position(); plan_sync_position(); + #ifdef USE_KINEMATICS + // This give kinematics a chance to do something after normal homing + kinematics_post_homing(); + #endif + // If hard limits feature enabled, re-enable hard limits pin change register after homing cycle. limits_init(); } diff --git a/Grbl_Esp32/polar_coaster.cpp b/Grbl_Esp32/polar_coaster.cpp index 25135ccf..b0766495 100644 --- a/Grbl_Esp32/polar_coaster.cpp +++ b/Grbl_Esp32/polar_coaster.cpp @@ -53,18 +53,27 @@ #ifdef CPU_MAP_POLAR_COASTER #ifdef USE_KINEMATICS +static float last_angle = 0; +static float last_radius = 0; + // this get called before homing -// return true to complete normal home -// return false to exit normal homing -bool kinematics_homing(uint8_t cycle_mask) -{ +// return false to complete normal home +// return true to exit normal homing +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] = 0.0f; + sys_position[Z_AXIS] = SERVO_Z_RANGE_MAX * settings.steps_per_mm[Z_AXIS]; // Move pen up. - return true; // finish normal homing cycle + return false; // finish normal homing cycle +} + +void kinematics_post_homing() { + // sync the X axis (do not need sync but make it for the fail safe) + last_radius = sys_position[X_AXIS]; + // reset the internal angle value + last_angle = 0; } /* @@ -80,8 +89,8 @@ bool kinematics_homing(uint8_t cycle_mask) */ void inverse_kinematics(float *target, plan_line_data_t *pl_data, float *position) { - static float last_angle = 0; - static float last_radius = 0; + //static float last_angle = 0; + //static float last_radius = 0; float dx, dy, dz; // distances in each cartesian axis float p_dx, p_dy, p_dz; // distances in each polar axis @@ -279,5 +288,13 @@ void user_defined_macro(uint8_t index) break; } } + +// handle the M30 command +void user_m30() { + char gcode_line[20]; + sprintf(gcode_line, "G53G0X-%3.2f\r", settings.homing_pulloff); // go to the homing pulloff location to move pen out of the way + inputBuffer.push(gcode_line); +} + #endif diff --git a/Grbl_Esp32/polar_coaster.h b/Grbl_Esp32/polar_coaster.h index 3e98cbe1..f53faa79 100644 --- a/Grbl_Esp32/polar_coaster.h +++ b/Grbl_Esp32/polar_coaster.h @@ -23,17 +23,125 @@ #define POLAR_AXIS 1 #define SEGMENT_LENGTH 0.5 // segment length in mm +#define USE_KINEMATICS +#define FWD_KINEMATICS_REPORTING // report in cartesian +#define USE_M30 + +// ============= Begin CPU MAP ================ +#define CPU_MAP_NAME "CPU_MAP_POLAR_COASTER" + +#define USE_RMT_STEPS + +#define X_STEP_PIN GPIO_NUM_15 +#define X_RMT_CHANNEL 0 +#define Y_STEP_PIN GPIO_NUM_2 +#define Y_RMT_CHANNEL 1 +#define X_DIRECTION_PIN GPIO_NUM_25 +#define Y_DIRECTION_PIN GPIO_NUM_26 + +#define STEPPERS_DISABLE_PIN GPIO_NUM_17 + +#ifndef USE_SERVO_AXES // maybe set in config.h + #define USE_SERVO_AXES +#endif + +#define SERVO_Z_PIN GPIO_NUM_16 +#define SERVO_Z_CHANNEL_NUM 5 +#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 X_LIMIT_PIN GPIO_NUM_4 +#define LIMIT_MASK B1 + +#ifdef IGNORE_CONTROL_PINS // maybe set in config.h + #undef IGNORE_CONTROL_PINS +#endif + +#ifndef ENABLE_CONTROL_SW_DEBOUNCE + #define ENABLE_CONTROL_SW_DEBOUNCE +#endif + +#define MACRO_BUTTON_0_PIN GPIO_NUM_13 +#define MACRO_BUTTON_1_PIN GPIO_NUM_12 +#define MACRO_BUTTON_2_PIN GPIO_NUM_14 + +// redefine some stuff from config.h +#ifdef HOMING_CYCLE_0 + #undef HOMING_CYCLE_0 +#endif +#define HOMING_CYCLE_0 (1<