Skip to content

Task Watchdog & AccelStepper #2892

@joeltbennett

Description

@joeltbennett

Hi - I have what I believe to be a unique scenario. I'm sure someone smarter will say I'm an idiot, but I will describe it to you anyway:

I have an ESP32 WROOM with core1 running functions for a Nextion screen (controlled with serial communications back and forth) and stepper motor functions on core0.

I ran into the classic TWD idle reboots described in this thread here. I tried the vTaskDelay(10) method and it worked great, right up until we got to a loop containing my stepper motor run functions (stepper1.run() / stepper2.run()). With no vTaskDelay in that loop, I get a reboot. With a vTaskDelay of any size (right down to 1), the program functions but the motors run pitifully slow.

Accel stepper requires these run functions to run in the loop unmolested, when you start adding things in it skips steps or just slows everything down.

I then decided to try to disable TWD entirely for core0 (functions outlined here) - this worked great, no delays necessary. But when I got to that loop with my .run functions in it, I get a reboot with no TWD message. Actually, there's just no message at all when TWD is disabled - just reboots. Can't backtrace it, but I'm guessing it's the AccelStepper .run() function causing a panic.

So now I kind of have a "damned if you do, damned if you don't" type scenario.

Here's the backtrace when I don't have a vTaskDelay in the stepper.run loop:

Decoding stack results
0x40088dd8: invoke_abort at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/panic.c line 155
0x40089005: abort at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/panic.c line 170
0x400dd5df: task_wdt_isr at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/task_wdt.c line 174
0x40081137: delayMicroseconds at /Users/JTB/Library/Arduino15/packages/esp32/hardware/esp32/1.0.2/cores/esp32/esp32-hal-misc.c line 157
0x400d4476: AccelStepper::step1(long) at /Users/JTB/Documents/Arduino/libraries/AccelStepper/AccelStepper.cpp line 391
0x400d4341: AccelStepper::step(long) at /Users/JTB/Documents/Arduino/libraries/AccelStepper/AccelStepper.cpp line 348
0x400d45c2: AccelStepper::runSpeed() at /Users/JTB/Documents/Arduino/libraries/AccelStepper/AccelStepper.cpp line 60
0x400d47c9: AccelStepper::run() at /Users/JTB/Documents/Arduino/libraries/AccelStepper/AccelStepper.cpp line 185
0x400d3110: MotorsTc(void*) at /Users/JTB/Downloads/AC-1 :: Work/Sterling-AC-1/Sterling-AC-1.ino line 1801
0x40087925: vPortTaskWrapper at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/freertos/port.c line 143

This is the .cpp file referenced in the backtrace.

I can't see it saying much else besides AccelStepper's .run function (and the others it subsequently calls on) aren't going to work with watchdog...would it help to modify that function in AccelStepper to feed the watchdog without any delay?


edit to put in some sketch info:

this is the loop that's causing the panic:

void MotorsTc( void * pvParameters ){
Serial.print("Motors running on core ");
Serial.println(xPortGetCoreID());
for(;;){
while (windStatus == true) {
stepper1.enableOutputs();
stepper2.enableOutputs();
s2_zero();
s2_bobComp();
for (int i = 0; i < 20; i ++) {
stepper1.setCurrentPosition(0);
stepper1.setMaxSpeed(MaxSpeed1);
stepper1.setAcceleration(Accel1);
stepper2.setMaxSpeed(MAX_SPD);
stepper2.setAcceleration(MAX_XCL);
stepper2.moveTo(Move2_A[i]);
stepper2.runToPosition();
stepper2.setMaxSpeed(MaxSpeed2[i]);
stepper2.moveTo(Move2_B[i]);
if (dirCW != true) {Move1[i] = -Move1[i];}
stepper1.moveTo(Move1[i]);
if (dirCW != true) {
VVV THIS ONE HERE INSIDE THE WHILE STATEMENT(S) VVV
while (stepper1.distanceToGo() < 0) {
stepper1.run();
if (stepper2.currentPosition() == Move2_A[i]) {
stepper2.moveTo(Move2_B[i]);}
if (stepper2.currentPosition() == Move2_B[i]) {
stepper2.moveTo(Move2_A[i]);}
stepper2.run();
}
} else {
while (stepper1.distanceToGo() > 0) {
stepper1.run();
if (stepper2.currentPosition() == Move2_A[i]) {
stepper2.moveTo(Move2_B[i]);}
if (stepper2.currentPosition() == Move2_B[i]) {
stepper2.moveTo(Move2_A[i]);}
stepper2.run();
};
}
};
stepper2.moveTo(0);
stepper2.runToPosition();
windStatus = false;
stepper1.disableOutputs();
stepper2.disableOutputs();
vTaskDelay(10);
};
vTaskDelay(10);
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: StaleIssue is stale stage (outdated/stuck)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions