diff --git a/main/config.h b/main/config.h index 8978f51..1b2b5d6 100644 --- a/main/config.h +++ b/main/config.h @@ -121,6 +121,10 @@ // max target length that can be selected using potentiometer (SET button) #define MAX_SELECTABLE_LENGTH_POTI_MM 100000 +// calculate new winding width each time target length changes, according to custom thresholds defined in guide-stepper.cpp +// if not defined, winding width is always GUIDE_MAX_MM even for short lengths +#define DYNAMIC_WINDING_WIDTH_ENABLED + //-------------------------- //------ calibration ------- diff --git a/main/control.cpp b/main/control.cpp index b971a8c..278c4da 100644 --- a/main/control.cpp +++ b/main/control.cpp @@ -161,6 +161,9 @@ void task_control(void *pvParameter) //currently show name and date and scrolling 'hello' display_ShowWelcomeMsg(two7SegDisplays); + //-- set initial winding width for default length -- + guide_setWindingWidth(guide_targetLength2WindingWidth(lengthTarget)); + // ############################## // ######## control loop ######## // ############################## @@ -309,6 +312,7 @@ void task_control(void *pvParameter) if (lengthTargetNew != lengthTarget) { //TODO update lengthTarget only at button release? lengthTarget = lengthTargetNew; + guide_setWindingWidth(guide_targetLength2WindingWidth(lengthTarget)); ESP_LOGI(TAG, "Changed target length to %d mm", lengthTarget); buzzer.beep(1, 25, 10); } @@ -327,16 +331,19 @@ void task_control(void *pvParameter) if (controlState != systemState_t::MANUAL && SW_SET.state == false) { //dont apply preset length while controlling motor with preset buttons if (SW_PRESET1.risingEdge) { lengthTarget = 5000; + guide_setWindingWidth(guide_targetLength2WindingWidth(lengthTarget)); buzzer.beep(lengthTarget/1000, 25, 30); displayBot.blink(2, 100, 100, "S0LL "); } else if (SW_PRESET2.risingEdge) { lengthTarget = 10000; + guide_setWindingWidth(guide_targetLength2WindingWidth(lengthTarget)); buzzer.beep(lengthTarget/1000, 25, 30); displayBot.blink(2, 100, 100, "S0LL "); } else if (SW_PRESET3.risingEdge) { lengthTarget = 15000; + guide_setWindingWidth(guide_targetLength2WindingWidth(lengthTarget)); buzzer.beep(lengthTarget/1000, 25, 30); displayBot.blink(2, 100, 100, "S0LL "); } @@ -512,7 +519,7 @@ void task_control(void *pvParameter) } //setting winding width: blink info message else if (SW_SET.state && SW_PRESET1.state){ - displayTop.blinkStrings("SET.WIND", " WIDTH ", 900, 900); + displayTop.blinkStrings("SET WIND", " WIDTH ", 900, 900); } //otherwise show current position else { diff --git a/main/guide-stepper.cpp b/main/guide-stepper.cpp index 1fa5e69..807ca4a 100644 --- a/main/guide-stepper.cpp +++ b/main/guide-stepper.cpp @@ -92,6 +92,36 @@ void guide_setWindingWidth(uint8_t maxPosMm) } +//======================================= +//=== guide_targetLength2WindingWidth === +//======================================= +// calculate dynamic winding width in mm from cable length in mm +uint8_t guide_targetLength2WindingWidth(int lenMm) +{ +#ifdef DYNAMIC_WINDING_WIDTH_ENABLED + uint8_t width; + //--- config --- + // define thresholds for winding widths according to target length: + if (lenMm <= 5000) // 0-5m + width = 15; + else if (lenMm <= 10000) // 6-10m + width = 25; + else if (lenMm <= 15000) // 11-15m + width = 30; + else if (lenMm <= 25000) // 16-25m + width = 65; + else // >25m + width = GUIDE_MAX_MM; + ESP_LOGW(TAG, "length2width: calculated windingWidth=%dmm from targetLength=%dm", width, lenMm); + return width; +#else + ESP_LOGD(TAG, "length2width: dynamic windingWidh not enabled, stay at GUIDE_MAX=%d", GUIDE_MAX_MM); + return GUIDE_MAX_MM; +#endif +//TODO update winding width here as well already? +} + + //============================= //=== guide_getWindingWidth === //============================= diff --git a/main/guide-stepper.hpp b/main/guide-stepper.hpp index dc1ecbf..b4d513a 100644 --- a/main/guide-stepper.hpp +++ b/main/guide-stepper.hpp @@ -24,4 +24,7 @@ int guide_getAxisPosSteps(); void guide_setWindingWidth(uint8_t maxPosMm); // get currently configured winding width (axis position the guide returns in mm) -uint8_t guide_getWindingWidth(); \ No newline at end of file +uint8_t guide_getWindingWidth(); + +// calculate dynamic winding width in mm from cable length in mm according to fixed thresholds +uint8_t guide_targetLength2WindingWidth(int lenMm); \ No newline at end of file