From f887e62320099454963d5cc22285979ce6b316d1 Mon Sep 17 00:00:00 2001 From: odaki Date: Tue, 18 Jun 2019 22:11:27 +0900 Subject: [PATCH 1/7] update dependent lubs in platformio.ini. add serial monitor speed to use PlatformIO serial minitor function. --- platformio.ini | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/platformio.ini b/platformio.ini index 48130d64..0ca16f2d 100644 --- a/platformio.ini +++ b/platformio.ini @@ -5,15 +5,20 @@ data_dir=Grbl_Esp32/data [common_env_data] lib_deps_builtin = - EEPROM + ArduinoOTA BluetoothSerial - WiFi + DNSServer + EEPROM + ESPmDNS FS + Preferences SD SPI - Preferences SPIFFS + Update WebServer + WiFi + WiFiClientSecure [env:nodemcu-32s] platform = espressif32 @@ -21,3 +26,4 @@ board = nodemcu-32s framework = arduino upload_speed = 512000 board_build.partitions = min_spiffs.csv +monitor_speed = 115200 From 6674e07a00753fc24bf6cbca3f9d65d390130b50 Mon Sep 17 00:00:00 2001 From: odaki Date: Tue, 18 Jun 2019 22:16:13 +0900 Subject: [PATCH 2/7] Revert "update dependent lubs in platformio.ini." This reverts commit f887e62320099454963d5cc22285979ce6b316d1. --- platformio.ini | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/platformio.ini b/platformio.ini index 0ca16f2d..48130d64 100644 --- a/platformio.ini +++ b/platformio.ini @@ -5,20 +5,15 @@ data_dir=Grbl_Esp32/data [common_env_data] lib_deps_builtin = - ArduinoOTA - BluetoothSerial - DNSServer EEPROM - ESPmDNS + BluetoothSerial + WiFi FS - Preferences SD SPI + Preferences SPIFFS - Update WebServer - WiFi - WiFiClientSecure [env:nodemcu-32s] platform = espressif32 @@ -26,4 +21,3 @@ board = nodemcu-32s framework = arduino upload_speed = 512000 board_build.partitions = min_spiffs.csv -monitor_speed = 115200 From 5ed974ee681fef9f3cb20f3dab761a752f5bcb2f Mon Sep 17 00:00:00 2001 From: odaki Date: Tue, 18 Jun 2019 22:19:43 +0900 Subject: [PATCH 3/7] Revert "Revert "update dependent lubs in platformio.ini."" This reverts commit 6674e07a00753fc24bf6cbca3f9d65d390130b50. --- platformio.ini | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/platformio.ini b/platformio.ini index 48130d64..0ca16f2d 100644 --- a/platformio.ini +++ b/platformio.ini @@ -5,15 +5,20 @@ data_dir=Grbl_Esp32/data [common_env_data] lib_deps_builtin = - EEPROM + ArduinoOTA BluetoothSerial - WiFi + DNSServer + EEPROM + ESPmDNS FS + Preferences SD SPI - Preferences SPIFFS + Update WebServer + WiFi + WiFiClientSecure [env:nodemcu-32s] platform = espressif32 @@ -21,3 +26,4 @@ board = nodemcu-32s framework = arduino upload_speed = 512000 board_build.partitions = min_spiffs.csv +monitor_speed = 115200 From 3e9327578c72cc3c3035c44fbe3fa3edd35cd086 Mon Sep 17 00:00:00 2001 From: odaki Date: Mon, 8 Jul 2019 00:35:19 +0900 Subject: [PATCH 4/7] Fix the usage of vTaskDelayUntil call correctly ix: prevent reference the uninitialized value at the first delay call. seeAlso https://www.freertos.org/vtaskdelayuntil.html --- Grbl_Esp32/servo_axis.cpp | 6 +++--- Grbl_Esp32/servo_pen.cpp | 9 ++++----- Grbl_Esp32/solenoid_pen.cpp | 7 +++---- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Grbl_Esp32/servo_axis.cpp b/Grbl_Esp32/servo_axis.cpp index c70b776c..a6f1ff1f 100644 --- a/Grbl_Esp32/servo_axis.cpp +++ b/Grbl_Esp32/servo_axis.cpp @@ -74,10 +74,9 @@ void servosSyncTask(void *pvParameters) TickType_t xLastWakeTime; const TickType_t xServoFrequency = SERVO_TIMER_INT_FREQ; // in ticks (typically ms) uint16_t servo_delay_counter = 0; - - while(true) { // don't ever return from this or the task dies - vTaskDelayUntil(&xLastWakeTime, xServoFrequency); + 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(); @@ -88,6 +87,7 @@ void servosSyncTask(void *pvParameters) #ifdef SERVO_Z_PIN Z_Servo_Axis.set_location(); #endif + vTaskDelayUntil(&xLastWakeTime, xServoFrequency); } } diff --git a/Grbl_Esp32/servo_pen.cpp b/Grbl_Esp32/servo_pen.cpp index 6e575bfa..cc45dae3 100644 --- a/Grbl_Esp32/servo_pen.cpp +++ b/Grbl_Esp32/servo_pen.cpp @@ -104,10 +104,8 @@ void servoSyncTask(void *pvParameters) float mpos_z, wpos_z; float z_offset; + xLastWakeTime = xTaskGetTickCount(); // Initialise the xLastWakeTime variable with the current time. while(true) { // don't ever return from this or the task dies - - vTaskDelayUntil(&xLastWakeTime, xServoFrequency); - if (sys.state != STATE_ALARM) { // don't move until alarm is cleared...typically homing if (!servo_pen_enable ) { servo_delay_counter++; @@ -120,6 +118,7 @@ void servoSyncTask(void *pvParameters) calc_pen_servo(wpos_z); // calculate kinematics and move the servos } } + vTaskDelayUntil(&xLastWakeTime, xServoFrequency); } } @@ -169,9 +168,9 @@ void calc_pen_servo(float penZ) // update the PWM value // ledcWrite appears to have issues with interrupts, so make this a critical section portMUX_TYPE myMutex = portMUX_INITIALIZER_UNLOCKED; - taskENTER_CRITICAL(&myMutex); + portENTER_CRITICAL(&myMutex); ledcWrite(SERVO_PEN_CHANNEL_NUM, servo_pen_pulse_len); - taskEXIT_CRITICAL(&myMutex); + portEXIT_CRITICAL(&myMutex); } #endif diff --git a/Grbl_Esp32/solenoid_pen.cpp b/Grbl_Esp32/solenoid_pen.cpp index 6b0b30c5..dc682cd5 100644 --- a/Grbl_Esp32/solenoid_pen.cpp +++ b/Grbl_Esp32/solenoid_pen.cpp @@ -68,11 +68,9 @@ void solenoidSyncTask(void *pvParameters) TickType_t xLastWakeTime; const TickType_t xSolenoidFrequency = SOLENOID_TIMER_INT_FREQ; // in ticks (typically ms) uint16_t solenoid_delay_counter = 0; - + + xLastWakeTime = xTaskGetTickCount(); // Initialise the xLastWakeTime variable with the current time. while(true) { // don't ever return from this or the task dies - - vTaskDelayUntil(&xLastWakeTime, xSolenoidFrequency); - if (!solenoid_pen_enable) { solenoid_delay_counter++; solenoid_pen_enable = (solenoid_delay_counter > SOLENOID_TURNON_DELAY); @@ -82,6 +80,7 @@ void solenoidSyncTask(void *pvParameters) system_convert_array_steps_to_mpos(m_pos,current_position); // convert to millimeters calc_solenoid(m_pos[Z_AXIS]); // calculate kinematics and move the servos } + vTaskDelayUntil(&xLastWakeTime, xSolenoidFrequency); } } From e66b2c13203da5dd3dbd6f608425dc1bd2f19523 Mon Sep 17 00:00:00 2001 From: odaki Date: Mon, 8 Jul 2019 00:47:48 +0900 Subject: [PATCH 5/7] prevent warnings - move static variable from header to cpp - remove unused variable - change deprecated func name in ESP-IDF --- Grbl_Esp32/servo_axis.cpp | 5 +++-- Grbl_Esp32/servo_axis.h | 2 -- Grbl_Esp32/solenoid_pen.cpp | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Grbl_Esp32/servo_axis.cpp b/Grbl_Esp32/servo_axis.cpp index a6f1ff1f..89fd64d3 100644 --- a/Grbl_Esp32/servo_axis.cpp +++ b/Grbl_Esp32/servo_axis.cpp @@ -26,6 +26,8 @@ #ifdef USE_SERVO_AXES +static TaskHandle_t servosSyncTaskHandle = 0; + #ifdef SERVO_X_PIN ServoAxis X_Servo_Axis(X_AXIS, SERVO_X_PIN, SERVO_X_CHANNEL_NUM); #endif @@ -73,7 +75,6 @@ void servosSyncTask(void *pvParameters) { TickType_t xLastWakeTime; const TickType_t xServoFrequency = SERVO_TIMER_INT_FREQ; // in ticks (typically ms) - uint16_t servo_delay_counter = 0; xLastWakeTime = xTaskGetTickCount(); // Initialise the xLastWakeTime variable with the current time. while(true) { // don't ever return from this or the task dies @@ -182,7 +183,7 @@ void ServoAxis::set_location() 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, wpos; + float servo_pos, mpos, offset; // skip location if we are in alarm mode if (_disable_on_alarm && (sys.state == STATE_ALARM)) { diff --git a/Grbl_Esp32/servo_axis.h b/Grbl_Esp32/servo_axis.h index c4d2caf9..da0a478b 100644 --- a/Grbl_Esp32/servo_axis.h +++ b/Grbl_Esp32/servo_axis.h @@ -85,8 +85,6 @@ #define SERVO_HOMING_OFF 0 // servo is off during homing #define SERVO_HOMING_TARGET 1 // servo is send to a location during homing -static TaskHandle_t servosSyncTaskHandle = 0; - extern float my_location; void init_servos(); diff --git a/Grbl_Esp32/solenoid_pen.cpp b/Grbl_Esp32/solenoid_pen.cpp index dc682cd5..3c9e17e5 100644 --- a/Grbl_Esp32/solenoid_pen.cpp +++ b/Grbl_Esp32/solenoid_pen.cpp @@ -114,9 +114,9 @@ void calc_solenoid(float penZ) // update the PWM value // ledcWrite appears to have issues with interrupts, so make this a critical section portMUX_TYPE myMutex = portMUX_INITIALIZER_UNLOCKED; - taskENTER_CRITICAL(&myMutex); + portENTER_CRITICAL(&myMutex); ledcWrite(SOLENOID_CHANNEL_NUM, solenoid_pen_pulse_len); - taskEXIT_CRITICAL(&myMutex); + portEXIT_CRITICAL(&myMutex); } #endif From 08d6f6936d3144ec0a3be550f0619ffa781393c6 Mon Sep 17 00:00:00 2001 From: odaki Date: Mon, 8 Jul 2019 01:07:44 +0900 Subject: [PATCH 6/7] Update Version to today --- Grbl_Esp32/grbl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Grbl_Esp32/grbl.h b/Grbl_Esp32/grbl.h index 34cd3786..b78a1e7e 100644 --- a/Grbl_Esp32/grbl.h +++ b/Grbl_Esp32/grbl.h @@ -20,7 +20,7 @@ // Grbl versioning system #define GRBL_VERSION "1.1f" -#define GRBL_VERSION_BUILD "20190626" +#define GRBL_VERSION_BUILD "20190708" //#include #include From 50246cb1e9f2e1cd96d252861109e17705225f1d Mon Sep 17 00:00:00 2001 From: bdring Date: Fri, 12 Jul 2019 10:44:46 -0500 Subject: [PATCH 7/7] Merged in some chnges I was working on. - cpu_map.h Updated CPU_MAP_PEN_LASER - servo_axis.cpp Fixed some errors and changed the way claibration out of range errors are reported - solenoid_pen.h Moved some features to cpu_map.h --- Grbl_Esp32/cpu_map.h | 33 ++++++++++++++++++++++++++++----- Grbl_Esp32/servo_axis.cpp | 30 +++++++++++++++++++----------- Grbl_Esp32/servo_axis.h | 4 +--- Grbl_Esp32/solenoid_pen.cpp | 2 +- Grbl_Esp32/solenoid_pen.h | 2 -- 5 files changed, 49 insertions(+), 22 deletions(-) diff --git a/Grbl_Esp32/cpu_map.h b/Grbl_Esp32/cpu_map.h index 917b8673..e2077c5a 100644 --- a/Grbl_Esp32/cpu_map.h +++ b/Grbl_Esp32/cpu_map.h @@ -192,14 +192,20 @@ #define CPU_MAP_NAME "CPU_MAP_PEN_LASER" + #define USE_RMT_STEPS + // Pick a board version //#define PEN_LASER_V1 #define PEN_LASER_V2 - #define X_STEP_PIN GPIO_NUM_12 - #define Y_STEP_PIN GPIO_NUM_14 - #define X_DIRECTION_PIN GPIO_NUM_26 - #define Y_DIRECTION_PIN GPIO_NUM_25 + #define X_STEP_PIN GPIO_NUM_12 + #define X_DIRECTION_PIN GPIO_NUM_26 + #define X_RMT_CHANNEL 0 + + + #define Y_STEP_PIN GPIO_NUM_14 + #define Y_DIRECTION_PIN GPIO_NUM_25 + #define Y_RMT_CHANNEL 1 #define STEPPERS_DISABLE_PIN GPIO_NUM_13 @@ -232,7 +238,24 @@ #define SPINDLE_PWM_RANGE (SPINDLE_PWM_MAX_VALUE-SPINDLE_PWM_MIN_VALUE) - #define SERVO_PEN_PIN GPIO_NUM_27 + #define USING_SERVO // uncommewnt to use this feature + #define USING_SOLENOID // uncommewnt to use this feature + + #ifdef USING_SERVO + #define USE_SERVO_AXES + #define SERVO_Z_PIN GPIO_NUM_27 + #define SERVO_Z_CHANNEL_NUM 3 + #define SERVO_Z_RANGE_MIN 0 + #define SERVO_Z_RANGE_MAX 10 + #endif + + #ifdef USING_SOLENOID + #define USE_PEN_SOLENOID + #define SOLENOID_PEN_PIN GPIO_NUM_16 + #define SOLENOID_CHANNEL_NUM 6 + #endif + + #ifdef DEFAULTS_GENERIC #undef DEFAULTS_GENERIC // undefine generic then define each default below diff --git a/Grbl_Esp32/servo_axis.cpp b/Grbl_Esp32/servo_axis.cpp index 89fd64d3..9f520bb8 100644 --- a/Grbl_Esp32/servo_axis.cpp +++ b/Grbl_Esp32/servo_axis.cpp @@ -40,18 +40,22 @@ static TaskHandle_t servosSyncTaskHandle = 0; void init_servos() { + grbl_send(CLIENT_SERIAL, "[MSG: Init Servos]\r\n"); #ifdef SERVO_X_PIN + grbl_send(CLIENT_SERIAL, "[MSG: Init X Servo]\r\n"); X_Servo_Axis.init(); - Y_Servo_Axis.set_range(SERVO_X_RANGE_MIN, SERVO_X_RANGE_MAX); + X_Servo_Axis.set_range(SERVO_X_RANGE_MIN, SERVO_X_RANGE_MAX); X_Servo_Axis.set_homing_type(SERVO_HOMING_OFF); - X_Servo_Axis.set_disable_on_alarm(true); + X_Servo_Axis.set_disable_on_alarm(false); X_Servo_Axis.set_disable_with_steppers(false); #endif #ifdef SERVO_Y_PIN + grbl_send(CLIENT_SERIAL, "[MSG: Init Y Servo]\r\n"); Y_Servo_Axis.init(); Y_Servo_Axis.set_range(SERVO_Y_RANGE_MIN, SERVO_Y_RANGE_MAX); #endif #ifdef SERVO_Z_PIN + grbl_send(CLIENT_SERIAL, "[MSG: Init Z Servo]\r\n"); Z_Servo_Axis.init(); Z_Servo_Axis.set_range(SERVO_Z_RANGE_MIN, SERVO_Z_RANGE_MAX); Z_Servo_Axis.set_homing_type(SERVO_HOMING_TARGET); @@ -75,12 +79,13 @@ 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 + while(true) { // don't ever return from this or the task dies #ifdef SERVO_X_PIN - X_Servo_Axis.set_location(); - + X_Servo_Axis.set_location(); #endif #ifdef SERVO_Y_PIN Y_Servo_Axis.set_location(); @@ -105,7 +110,7 @@ void ServoAxis::init() { ledcSetup(_channel_num, _pwm_freq, _pwm_resolution_bits); ledcAttachPin(_pin_num, _channel_num); - disable(); + disable(); } /* void ServoAxis::set_location() @@ -140,7 +145,7 @@ void ServoAxis::set_location() } // get the calibration values - if (_cal_is_valid(false)) { // if calibration settings are OK then apply them + if (_cal_is_valid()) { // if calibration settings are OK then apply them min_pulse_cal = (settings.steps_per_mm[_axis] / 100.0); max_pulse_cal = (settings.max_travel[_axis] / -100.0); if (bit_istrue(settings.dir_invert_mask,bit(_axis))) { // the offset needs to be backwards @@ -214,7 +219,7 @@ void ServoAxis::set_location() } // get the calibration values - if (_cal_is_valid(false)) { // if calibration settings are OK then apply them + if (_cal_is_valid()) { // if calibration settings are OK then apply them min_pulse_cal = (settings.steps_per_mm[_axis] / 100.0); max_pulse_cal = (settings.max_travel[_axis] / -100.0); if (bit_istrue(settings.dir_invert_mask,bit(_axis))) { // the offset needs to be backwards @@ -264,12 +269,13 @@ void ServoAxis::disable() // 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 verbose) +bool ServoAxis::_cal_is_valid() { bool settingsOK = true; + static bool showError = true; // this will be used to show error only once if ( (settings.steps_per_mm[_axis] < SERVO_CAL_MIN) || (settings.steps_per_mm[_axis] > SERVO_CAL_MAX) ) { - if (verbose) { + if (showError) { grbl_sendf(CLIENT_SERIAL, "[MSG:Servo cal ($10%d) Error: %4.4f s/b between %.2f and %.2f]\r\n", _axis, settings.steps_per_mm[_axis], SERVO_CAL_MIN, SERVO_CAL_MAX); } settingsOK = false; @@ -277,11 +283,13 @@ bool ServoAxis::_cal_is_valid(bool verbose) // 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 (verbose) { + if (showError) { grbl_sendf(CLIENT_SERIAL, "[MSG:Servo cal ($13%d) Error: %4.4f s/b between %.2f and %.2f]\r\n", _axis, -settings.max_travel[_axis], SERVO_CAL_MIN, SERVO_CAL_MAX); } settingsOK = false; } + + showError = false; // to show error once return settingsOK; } diff --git a/Grbl_Esp32/servo_axis.h b/Grbl_Esp32/servo_axis.h index da0a478b..3c50028d 100644 --- a/Grbl_Esp32/servo_axis.h +++ b/Grbl_Esp32/servo_axis.h @@ -124,9 +124,7 @@ class ServoAxis{ bool _validate_cal_settings(); void _write_pwm(uint32_t duty); - bool _cal_is_valid(bool verbose); // checks to see if calibration values are in acceptable range - - + bool _cal_is_valid(); // checks to see if calibration values are in acceptable range }; #endif diff --git a/Grbl_Esp32/solenoid_pen.cpp b/Grbl_Esp32/solenoid_pen.cpp index 3c9e17e5..2c75bec4 100644 --- a/Grbl_Esp32/solenoid_pen.cpp +++ b/Grbl_Esp32/solenoid_pen.cpp @@ -115,7 +115,7 @@ void calc_solenoid(float penZ) // ledcWrite appears to have issues with interrupts, so make this a critical section portMUX_TYPE myMutex = portMUX_INITIALIZER_UNLOCKED; portENTER_CRITICAL(&myMutex); - ledcWrite(SOLENOID_CHANNEL_NUM, solenoid_pen_pulse_len); + ledcWrite(SOLENOID_CHANNEL_NUM, solenoid_pen_pulse_len); portEXIT_CRITICAL(&myMutex); } diff --git a/Grbl_Esp32/solenoid_pen.h b/Grbl_Esp32/solenoid_pen.h index cd7c328a..e6495a35 100644 --- a/Grbl_Esp32/solenoid_pen.h +++ b/Grbl_Esp32/solenoid_pen.h @@ -32,8 +32,6 @@ */ -#define SOLENOID_PEN_PIN GPIO_NUM_16 -#define SOLENOID_CHANNEL_NUM 6 #define SOLENOID_PWM_FREQ 5000 #define SOLENOID_PWM_RES_BITS 8