Stepper: add mutex, logging, delay, less steps
When testing last commit the stepper task crashed almost instantly and moved randomly. Trying to fix/debug that with those changes
This commit is contained in:
@@ -128,10 +128,13 @@ esp_err_t DendoStepper::runPos(int32_t relative)
|
||||
if (ctrl.dir == newDir){ //current direction is the same
|
||||
ctrl.statusPrev = ctrl.status; //update previous status
|
||||
ctrl.status = ctrl.status==COAST ? COAST : ACC; //stay at coast otherwise switch to ACC
|
||||
xSemaphoreTake(semaphore_isrVariables, portMAX_DELAY);
|
||||
calc(abs(relative + ctrl.stepsRemaining)); //calculate new velolcity profile for new+remaining steps
|
||||
ESP_LOGW("DendoStepper", "EXTEND running movement (stepsRemaining: %d + stepsNew: %d)", ctrl.stepsRemaining, relative);
|
||||
xSemaphoreGive(semaphore_isrVariables);
|
||||
} else { //direction has changed
|
||||
//direction change not supported TODO wait for decel finish / queue?
|
||||
STEP_LOGW("DendoStepper", "DIRECTION HOT-CHANGE NOT SUPPORTED - Finising previous move, this command will be ignored");
|
||||
STEP_LOGE("DendoStepper", "DIRECTION HOT-CHANGE NOT SUPPORTED - Finising previous move, this command will be ignored");
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
}
|
||||
@@ -333,14 +336,17 @@ bool DendoStepper::xISR()
|
||||
|
||||
ctrl.stepCnt++;
|
||||
|
||||
//CUSTOM: track actual precice current position
|
||||
if (ctrl.dir) {
|
||||
ctrl.posActual ++;
|
||||
} else {
|
||||
ctrl.posActual --;
|
||||
}
|
||||
////CUSTOM: track actual precice current position
|
||||
//if (ctrl.dir) {
|
||||
// ctrl.posActual ++;
|
||||
//} else {
|
||||
// ctrl.posActual --;
|
||||
//}
|
||||
|
||||
//CUSTOM: track remaining steps for eventually resuming
|
||||
xSemaphoreTake(semaphore_isrVariables, portMAX_DELAY);
|
||||
ctrl.stepsRemaining = ctrl.stepCnt - ctrl.stepCnt;
|
||||
xSemaphoreGive(semaphore_isrVariables);
|
||||
|
||||
// we are done
|
||||
if (ctrl.stepsToGo == ctrl.stepCnt && !ctrl.runInfinite)
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "freertos/task.h"
|
||||
#include "esp_timer.h"
|
||||
#include "math.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
//#define STEP_DEBUG
|
||||
|
||||
@@ -95,7 +96,7 @@ typedef struct
|
||||
uint32_t accSteps = 0;
|
||||
uint32_t decSteps = 0;
|
||||
int32_t stepsRemaining = 0;
|
||||
uint64_t posActual = 0; //actual current pos incremented at every step
|
||||
//uint64_t posActual = 0; //actual current pos incremented at every step
|
||||
uint8_t statusPrev = DISABLED; //FIXME currently unused
|
||||
uint8_t status = DISABLED;
|
||||
bool dir = CW;
|
||||
@@ -111,6 +112,7 @@ private:
|
||||
ctrl_var_t ctrl;
|
||||
esp_timer_handle_t dyingTimer;
|
||||
TaskHandle_t enTask;
|
||||
SemaphoreHandle_t semaphore_isrVariables = NULL;
|
||||
uint64_t currentPos = 0; // absolute position
|
||||
bool timerStarted = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user