From 279ac0e07e7578a86a6d13908e472bd4f379a62a Mon Sep 17 00:00:00 2001 From: jonny_l480 Date: Sun, 26 Mar 2023 11:41:46 +0200 Subject: [PATCH] Add more debug output ISSUES - Add debug output in calc - disable test mode for testing with encoder - set loglevel to DEBUG extend feature currently only works well in testing mode with buttons issues when running with encoder: movement gets extended extremely often due to encoder travel interval and rarely does reach target - compared to trigger with buttons -> while debugging noticed that the current speed gets negative and the xISR gets stuck so moves infinitely or not at all ideas: - rounding issue? - SPEED increment also has to be adjusted or set to 0 as step increment? --- components/DendoStepper/DendoStepper.cpp | 12 ++++++++---- main/config.hpp | 2 +- main/guide-stepper.cpp | 2 +- main/main.cpp | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/components/DendoStepper/DendoStepper.cpp b/components/DendoStepper/DendoStepper.cpp index cc64144..40fa8ad 100644 --- a/components/DendoStepper/DendoStepper.cpp +++ b/components/DendoStepper/DendoStepper.cpp @@ -174,7 +174,7 @@ esp_err_t DendoStepper::runAbs(uint32_t position) bool newDir = (relativeSteps < 0); // CCW if <0, else set CW if (ctrl.dir != newDir){ //direction differs STEP_LOGE("DendoStepper", "DIRECTION HOT-CHANGE NOT SUPPORTED - Waiting for move to finish..."); - while (getState() > IDLE) vTaskDelay(1); //wait for move to finish + while (getState() > IDLE) vTaskDelay(5); //wait for move to finish } } @@ -401,6 +401,7 @@ void DendoStepper::calc(uint32_t targetSteps) //steps from ctrl.speed -> 0: ctrl.decSteps = 0.5 * ctrl.dec * (ctrl.speed / ctrl.dec) * (ctrl.speed / ctrl.dec); + ESP_LOGD("DendoStepper", "decSteps: %d currspeed: %lf, ctrlSpeed: %lf\n", ctrl.decSteps, ctrl.currentSpeed, ctrl.speed); //steps from 0 -> ctrl.speed: //ctrl.accSteps = 0.5 * ctrl.acc * (ctrl.speed / ctrl.acc) * (ctrl.speed / ctrl.acc); //steps from ctrl.currentSpeed -> ctrl.speed: @@ -437,8 +438,11 @@ void DendoStepper::calc(uint32_t targetSteps) ctrl.stepInterval = TIMER_F / ctrl.currentSpeed; ctrl.stepsToGo = targetSteps; - ESP_LOGD("DendoStepper", "DEBUG: accSteps: %d currspeed: %lf, ctrlSpeed: %lf\n", ctrl.accSteps, ctrl.currentSpeed, ctrl.speed); - ESP_LOGD("DendoStepper", "CALC: speedNow=%.1f, speedTarget=%.1f, accEnd=%d, coastEnd=%d, accSteps=%d, accInc=%.3f\n", + //debug log output + ESP_LOGD("DendoStepper", "accSteps: %d, accInc: %lf, decSteps: %d, decInc: %lf", + ctrl.accSteps, ctrl.accInc, ctrl.decSteps, ctrl.decInc); + ESP_LOGD("DendoStepper", "speedNow=%.1f, speedTarget=%.1f, accEnd=%d, coastEnd=%d, accSteps=%d, accInc=%.3f\n", ctrl.currentSpeed, ctrl.targetSpeed, ctrl.accEnd, ctrl.coastEnd, ctrl.accSteps, ctrl.accInc); - STEP_LOGI("calc", "acc end:%u coastend:%u stepstogo:%u speed:%f acc:%f int: %u", ctrl.accEnd, ctrl.coastEnd, ctrl.stepsToGo, ctrl.speed, ctrl.acc, ctrl.stepInterval); + ESP_LOGD("DendoStepper", "acc end:%u coastend:%u stepstogo:%u speed:%f acc:%f int: %u", + ctrl.accEnd, ctrl.coastEnd, ctrl.stepsToGo, ctrl.speed, ctrl.acc, ctrl.stepInterval); } diff --git a/main/config.hpp b/main/config.hpp index 95ca28b..dcd474b 100644 --- a/main/config.hpp +++ b/main/config.hpp @@ -85,7 +85,7 @@ extern "C" { //----- stepper config ----- //-------------------------- //enable stepper test mode (dont start control and encoder task) -#define STEPPER_TEST +//#define STEPPER_TEST #define STEPPER_STEP_PIN GPIO_NUM_18 //mos1 #define STEPPER_DIR_PIN GPIO_NUM_16 //ST3 #define STEPPER_EN_PIN GPIO_NUM_0 //not connected (-> stepper always on) diff --git a/main/guide-stepper.cpp b/main/guide-stepper.cpp index 44e4e60..f798d94 100644 --- a/main/guide-stepper.cpp +++ b/main/guide-stepper.cpp @@ -34,7 +34,7 @@ extern "C" #define SPEED 10 //35, 100, 50 rev #define ACCEL_MS 800.0 //ms from 0 to max -#define DECEL_MS 800.0 //ms from max to 0 +#define DECEL_MS 500.0 //ms from max to 0 #define STEPPER_STEPS_PER_ROT 1600 #define STEPPER_STEPS_PER_MM STEPPER_STEPS_PER_ROT/4 diff --git a/main/main.cpp b/main/main.cpp index af2f72a..18cdc5b 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -87,7 +87,7 @@ extern "C" void app_main() esp_log_level_set("switches-analog", ESP_LOG_WARN); esp_log_level_set("control", ESP_LOG_INFO); esp_log_level_set("stepper", ESP_LOG_DEBUG); - esp_log_level_set("Dendostepper", ESP_LOG_DEBUG); //stepper lib + esp_log_level_set("DendoStepper", ESP_LOG_DEBUG); //stepper lib esp_log_level_set("calc", ESP_LOG_WARN); //stepper lib #ifdef STEPPER_TEST