Fix deadlock in windingWidth, Handle 0 width, optimize UI
guide-stepper: - fix deadlock when editing winding width - fix behaivor when windingWidth is set to 0 (disable guide) control: - add dead time to prevent setTarget when exiting setWindingWidth with buttons - fix typo and conditons - increase max winding width - optimize display text
This commit is contained in:
parent
c049da3583
commit
84c88e8f02
@ -106,7 +106,7 @@
|
||||
//---------------------------
|
||||
// default axis coordinates the guide changes direction (winding width)
|
||||
#define GUIDE_MIN_MM 0 // TODO add feature so guide stays at zero for some steps (negative MIN_MM?), currently seems appropriate for even winding
|
||||
#define GUIDE_MAX_MM 95 // actual reel is 110, but currently guide turned out to stay at max position for too long
|
||||
#define GUIDE_MAX_MM 90 // 95 still to long at max pos - actual reel is 110, but currently guide turned out to stay at max position for too long, due to cable running diagonal from guide to reel
|
||||
|
||||
// tolerance added to last stored position at previous shutdown.
|
||||
// When calibrating at startup the stepper moves for that sum to get track of zero position (ensure crashes into hardware limit for at least some time)
|
||||
@ -117,7 +117,9 @@
|
||||
#define D_REEL 160 // start diameter of empty reel
|
||||
|
||||
// max winding width that can be set using potentiometer (SET+PRESET1 buttons)
|
||||
#define MAX_WINDING_WIDTH_MM 100;
|
||||
#define MAX_SELECTABLE_WINDING_WIDTH_MM 100;
|
||||
// max target length that can be selected using potentiometer (SET button)
|
||||
#define MAX_SELECTABLE_LENGTH_POTI_MM 100000
|
||||
|
||||
|
||||
//--------------------------
|
||||
|
@ -54,6 +54,10 @@ static uint32_t timestamp_cut_lastBeep = 0;
|
||||
static uint32_t autoCut_delayMs = 2500; //TODO add this to config
|
||||
static bool autoCutEnabled = false; //store state of toggle switch (no hotswitch)
|
||||
|
||||
//user interface
|
||||
static uint32_t timestamp_lastWidthSelect = 0;
|
||||
//ignore new set events for that time after last value set using poti
|
||||
#define DEAD_TIME_POTI_SET_VALUE 1000
|
||||
|
||||
|
||||
//-----------------------------------------
|
||||
@ -257,10 +261,11 @@ void task_control(void *pvParameter)
|
||||
// set winding width (axis travel) with poti position
|
||||
// when SET and PRESET1 button are pressed
|
||||
if (SW_SET.state == true && SW_PRESET1.state == true) {
|
||||
timestamp_lastWidthSelect = esp_log_timestamp();
|
||||
//read adc
|
||||
potiRead = gpio_readAdc(ADC_CHANNEL_POTI); //0-4095
|
||||
//scale to target length range
|
||||
uint8_t windingWidthNew = (float)potiRead / 4095 * MAX_WINDING_WIDTH_MM;
|
||||
uint8_t windingWidthNew = (float)potiRead / 4095 * MAX_SELECTABLE_WINDING_WIDTH_MM;
|
||||
//apply hysteresis and round to whole meters //TODO optimize this
|
||||
if (windingWidthNew % 5 < 2) { //round down if remainder less than 2mm
|
||||
ESP_LOGD(TAG, "Poti input = %d -> rounding down", windingWidthNew);
|
||||
@ -270,7 +275,7 @@ void task_control(void *pvParameter)
|
||||
windingWidthNew = (windingWidthNew/5 + 1) * 5; //round up
|
||||
} else {
|
||||
ESP_LOGD(TAG, "Poti input = %d -> hysteresis", windingWidthNew);
|
||||
windingWidthNew = lengthTarget;
|
||||
windingWidthNew = guide_getWindingWidth();
|
||||
}
|
||||
//update target width and beep when effectively changed
|
||||
if (windingWidthNew != guide_getWindingWidth()) {
|
||||
@ -282,12 +287,13 @@ void task_control(void *pvParameter)
|
||||
}
|
||||
|
||||
//## set target length (SET+POTI) ##
|
||||
//set target length to poti position when SET switch is pressed
|
||||
else if (SW_SET.state == true) {
|
||||
//set target length to poti position when only SET button is pressed and certain dead time passed after last setWindingWidth (SET and PRESET1 button) to prevent set target at release
|
||||
// FIXME: when going to edit the winding width (SET+PRESET1) sometimes the target-length also updates when initially pressing SET -> update only at actual poti change (works sometimes)
|
||||
else if (SW_SET.state == true && (esp_log_timestamp() - timestamp_lastWidthSelect > DEAD_TIME_POTI_SET_VALUE)) {
|
||||
//read adc
|
||||
potiRead = gpio_readAdc(ADC_CHANNEL_POTI); //0-4095
|
||||
//scale to target length range
|
||||
int lengthTargetNew = (float)potiRead / 4095 * 50000;
|
||||
int lengthTargetNew = (float)potiRead / 4095 * MAX_SELECTABLE_LENGTH_POTI_MM;
|
||||
//apply hysteresis and round to whole meters //TODO optimize this
|
||||
if (lengthTargetNew % 1000 < 200) { //round down if less than .2 meter
|
||||
ESP_LOGD(TAG, "Poti input = %d -> rounding down", lengthTargetNew);
|
||||
@ -318,7 +324,7 @@ void task_control(void *pvParameter)
|
||||
|
||||
|
||||
//##### target length preset buttons #####
|
||||
if (controlState != systemState_t::MANUAL) { //dont apply preset length while controlling motor with preset buttons
|
||||
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;
|
||||
buzzer.beep(lengthTarget/1000, 25, 30);
|
||||
@ -506,7 +512,7 @@ void task_control(void *pvParameter)
|
||||
}
|
||||
//setting winding width: blink info message
|
||||
else if (SW_SET.state && SW_PRESET1.state){
|
||||
displayTop.blinkStrings(" SET ", " WIDTH ", 400, 400);
|
||||
displayTop.blinkStrings("SET.WIND", " WIDTH ", 900, 900);
|
||||
}
|
||||
//otherwise show current position
|
||||
else {
|
||||
@ -538,7 +544,7 @@ void task_control(void *pvParameter)
|
||||
}
|
||||
//setting winding width: blink currently set windingWidth
|
||||
else if (SW_SET.state && SW_PRESET1.state){
|
||||
sprintf(buf_tmp, " %03d mm", lengthNow/1000);
|
||||
sprintf(buf_tmp, " %03d mm", guide_getWindingWidth());
|
||||
displayBot.blinkStrings(buf_tmp, " ", 300, 100);
|
||||
}
|
||||
//setting target length: blink target length
|
||||
|
@ -95,13 +95,14 @@ void guide_setWindingWidth(uint8_t maxPosMm)
|
||||
//=============================
|
||||
//=== guide_getWindingWidth ===
|
||||
//=============================
|
||||
// get currently configured winding width (axis position the guide returns in mm)
|
||||
// get currently configured winding width (axis position at which the guide returns in mm)
|
||||
uint8_t guide_getWindingWidth()
|
||||
{
|
||||
if (xSemaphoreTake(configVariables_mutex, portMAX_DELAY) == pdTRUE) // mutex to prevent multiple access by control and stepper-ctl task
|
||||
{
|
||||
return posMaxSteps / STEPPER_STEPS_PER_MM;
|
||||
uint8_t returnValue = posMaxSteps / STEPPER_STEPS_PER_MM;
|
||||
xSemaphoreGive(configVariables_mutex);
|
||||
return returnValue;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -125,6 +126,12 @@ void guide_moveToZero(){
|
||||
void travelSteps(int stepsTarget){
|
||||
//TODO simplify this function, one simple calculation of new position?
|
||||
//with new custom driver no need to detect direction change
|
||||
|
||||
// cancel when width is zero or no steps received
|
||||
if (posMaxSteps == 0 || stepsTarget == 0){
|
||||
ESP_LOGD(TAG, "travelSteps: MaxSteps or stepsTarget = 0 -> nothing to do");
|
||||
return;
|
||||
}
|
||||
|
||||
int stepsToGo, remaining;
|
||||
|
||||
@ -349,6 +356,18 @@ void task_stepper_ctl(void *pvParameter)
|
||||
|
||||
//repeatedly read changes in measured cable length and move axis accordingly
|
||||
while(1){
|
||||
|
||||
// guide is disabled when posMaxSteps is zero:
|
||||
if (posMaxSteps == 0)
|
||||
{
|
||||
// move to starting position
|
||||
stepper_setTargetPosSteps(0);
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
ESP_LOGD(TAG, "posMaxSteps is zero -> guide disabled, doing nothing");
|
||||
// stop loop iteration
|
||||
continue;
|
||||
}
|
||||
|
||||
#ifdef STEPPER_SIMULATE_ENCODER
|
||||
//TESTING - simulate encoder using switch
|
||||
SW_RESET.handle();
|
||||
|
Loading…
x
Reference in New Issue
Block a user