Extrernal step gerenation using ESP32+w5500

More
25 Jul 2024 08:55 - 25 Jul 2024 08:58 #305996 by yathish
Hello Linuxcnc community, I was trying external step generation using ESP32+W5500, I was refering github.com/jzolee/HAL2UDP/blob/main/src/main.cpp. In HAL2UDp/scr/main.cpp , which is nothing but ESP32 side code, the syntax has to be changed because some functions have been combined refer this for changed syntax docs.espressif.com/projects/arduino-esp3...atest/api/timer.html.
This is the updated main.cpp : #include <Arduino.h>
//#include <driver/ledc.h>/
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <esp_task_wdt.h>
/*==================================================================*/
byte mac = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 96, 54);
unsigned int port = 58427;
/*==================================================================*/
#define SPI_CS_PIN 5 // hardcoded in Ethernet_mod/src/utility/w5100.h !!!!!!!!!!!!!!
/*==================================================================*/
#define STEP_0_PIN 12
#define STEP_0_H REG_WRITE(GPIO_OUT_W1TS_REG, BIT12)
#define STEP_0_L REG_WRITE(GPIO_OUT_W1TC_REG, BIT12)
#define DIR_0_PIN 13
#define DIR_0_H REG_WRITE(GPIO_OUT_W1TS_REG, BIT13)
#define DIR_0_L REG_WRITE(GPIO_OUT_W1TC_REG, BIT13)
#define STEP_1_PIN 16
#define STEP_1_H REG_WRITE(GPIO_OUT_W1TS_REG, BIT16)
#define STEP_1_L REG_WRITE(GPIO_OUT_W1TC_REG, BIT16)
#define DIR_1_PIN 17
#define DIR_1_H REG_WRITE(GPIO_OUT_W1TS_REG, BIT17)
#define DIR_1_L REG_WRITE(GPIO_OUT_W1TC_REG, BIT17)
#define STEP_2_PIN 21
#define STEP_2_H REG_WRITE(GPIO_OUT_W1TS_REG, BIT21)
#define STEP_2_L REG_WRITE(GPIO_OUT_W1TC_REG, BIT21)
#define DIR_2_PIN 22
#define DIR_2_H REG_WRITE(GPIO_OUT_W1TS_REG, BIT22)
#define DIR_2_L REG_WRITE(GPIO_OUT_W1TC_REG, BIT22)
/*==================================================================*/
#define OUT_00_PIN 2
#define OUT_00_H REG_WRITE(GPIO_OUT_W1TS_REG, BIT2)
#define OUT_00_L REG_WRITE(GPIO_OUT_W1TC_REG, BIT2)
#define OUT_01_PIN 4
#define OUT_01_H REG_WRITE(GPIO_OUT_W1TS_REG, BIT4)
#define OUT_01_L REG_WRITE(GPIO_OUT_W1TC_REG, BIT4)
#define OUT_02_PIN 25
#define OUT_02_H REG_WRITE(GPIO_OUT_W1TS_REG, BIT25)
#define OUT_02_L REG_WRITE(GPIO_OUT_W1TC_REG, BIT25)
#define OUT_03_PIN 1
#define OUT_03_H REG_WRITE(GPIO_OUT_W1TS_REG, BIT1)
#define OUT_03_L REG_WRITE(GPIO_OUT_W1TC_REG, BIT1)
#define OUT_04_PIN 14
#define OUT_04_H REG_WRITE(GPIO_OUT_W1TS_REG, BIT14)
#define OUT_04_L REG_WRITE(GPIO_OUT_W1TC_REG, BIT14)
#define OUT_05_PIN 15
#define OUT_05_H REG_WRITE(GPIO_OUT_W1TS_REG, BIT15)
#define OUT_05_L REG_WRITE(GPIO_OUT_W1TC_REG, BIT15)
/*==================================================================*/
#define IN_00_PIN 26
#define IN_00 REG_READ(GPIO_IN_REG) & BIT26 //26
#define IN_01_PIN 27
#define IN_01 REG_READ(GPIO_IN_REG) & BIT27 //27
#define IN_02_PIN 32
#define IN_02 REG_READ(GPIO_IN1_REG) & BIT0 //32 -32
#define IN_03_PIN 33
#define IN_03 REG_READ(GPIO_IN1_REG) & BIT1 //33 -32
#define IN_04_PIN 34
#define IN_04 REG_READ(GPIO_IN1_REG) & BIT2 //34 -32
#define IN_05_PIN 35
#define IN_05 REG_READ(GPIO_IN1_REG) & BIT3 //35 -32
#define IN_06_PIN 36
#define IN_06 REG_READ(GPIO_IN1_REG) & BIT4 //36 -32
#define IN_07_PIN 39
#define IN_07 REG_READ(GPIO_IN1_REG) & BIT7 //39 -32
/*==================================================================*/
#define CTRL_DIRSETUP 0b00000001
#define CTRL_ACCEL    0b00000010
#define CTRL_PWMFREQ  0b00000100
#define CTRL_READY    0b01000000
#define CTRL_ENABLE   0b10000000
#define IO_00 0b00000001
#define IO_01 0b00000010
#define IO_02 0b00000100
#define IO_03 0b00001000
#define IO_04 0b00010000
#define IO_05 0b00100000
#define IO_06 0b01000000
#define IO_07 0b10000000
/*==================================================================*/
EthernetUDP Udp; // An EthernetUDP instance to let us send and receive packets over UDP
struct cmdPacket {
    uint8_t control;
    uint8_t io;
    uint16_t pwm[6];
    int32_t pos[3];
    float vel[3];
} cmd = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0f, 0.0f, 0.0f };
struct fbPacket {
    uint8_t control;
    uint8_t io;
    int32_t pos[3];
    float vel[3];
} fb = { 0, 0, 0, 0, 0, 0.0f, 0.0f, 0.0f };
/*==================================================================*/
volatile unsigned long ul_dirSetup[3] = { 1000, 1000, 1000 }; // x 25 nanosec
volatile float f_accel_x2[3] = { 1000.0, 1000.0, 1000.0 }; // acceleration*2 step/sec2
/*==================================================================*/
volatile unsigned long ul_cmd_T[3];
unsigned long ul_accelStep[3] = { 0, 0, 0 };
volatile unsigned long ul_T[3] = { 0, 0, 0 };
volatile unsigned long ul_TH[3] = { 0, 0, 0 };
volatile unsigned long ul_TL[3] = { 0, 0, 0 };
volatile bool b_math[3] = { false, false, false };
volatile bool b_dirSignal[3] = { LOW, LOW, LOW };
volatile bool b_dirChange[3] = { false, false, false };
const uint8_t pwm_pin[6] = { OUT_00_PIN, OUT_01_PIN, OUT_02_PIN, OUT_03_PIN, OUT_04_PIN, OUT_05_PIN };
bool pwm_enable[6] = { false, false, false, false, false, false };
/*==================================================================*/
hw_timer_t* stepGen_0 = NULL;
hw_timer_t* stepGen_1 = NULL;
hw_timer_t* stepGen_2 = NULL;
/*==================================================================*/
float IRAM_ATTR fastInvSqrt(const float x)
{
    const float xhalf = x * 0.5f;
    union {
        float x;
        uint32_t i;
    } u = { .x = x };
    u.i = 0x5f3759df - (u.i >> 1);
    return u.x * (1.5f - xhalf * u.x * u.x);
}
/*==================================================================*/
/*float IRAM_ATTR Q_InvSqrt(float x)
{
    float xhalf = x * 0.5f;
    int i = (int)&x; // evil floating point bit level hacking
    i = 0x5f3759df - (i >> 1); // what the fuck?
    x = (float)&i; // convert new bits into float
    x = x * (1.5f - xhalf * x * x); // 1st iteration of Newton's method
    //x = x * (1.5f - xhalf * x * x); // 2nd iteration, this can be removed
    return x;
}*/
/*==================================================================*/
void IRAM_ATTR onTime_0()
{
    static bool b_stepState = LOW;
    static bool b_dirState = LOW;
    if (b_stepState == LOW) { // end of period
        if (ul_T[0]) { // there is a period time so a pulse must be started
            if (!b_dirChange[0]) { //direction is good, start a new pulse (step L-H transition)
                STEP_0_H;
                timerWrite(stepGen_0, ul_TH[0]);
                b_stepState = HIGH;
                b_dirState ? fb.pos[0]++ : fb.pos[0]--;
                b_math[0] = true; // calculation of a new period time
            } else { // need to change direction
                if (b_dirSignal[0]) {
                    DIR_0_H;
                    b_dirState = HIGH;
                } else {
                    DIR_0_L;
                    b_dirState = LOW;
                }
                timerWrite(stepGen_0, ul_dirSetup[0]);
                b_dirChange[0] = false;
            }
        } else { // no need to step pulse
            timerWrite(stepGen_0, 4000ul); // 0,1 millis scan
            b_math[0] = true; // calculation of a new period time
        }
    } else { // the middle of the period time (step H-L transition)
        STEP_0_L;
        timerWrite(stepGen_0, ul_TL[0]);
        b_stepState = LOW;
    }
}
/*==================================================================*/
void IRAM_ATTR onTime_1()
{
    static bool b_stepState = LOW;
    static bool b_dirState = LOW;
    if (b_stepState == LOW) { // end of period
        if (ul_T[1]) { // there is a period time so a pulse must be started
            if (!b_dirChange[1]) { //direction is good, start a new pulse (step L-H transition)
                STEP_1_H;
                timerWrite(stepGen_1, ul_TH[1]);
                b_stepState = HIGH;
                b_dirState ? fb.pos[1]++ : fb.pos[1]--;
                b_math[1] = true; // calculation of a new period time
            } else { // need to change direction
                if (b_dirSignal[1]) {
                    DIR_1_H;
                    b_dirState = HIGH;
                } else {
                    DIR_1_L;
                    b_dirState = LOW;
                }
                timerWrite(stepGen_1, ul_dirSetup[1]);
                b_dirChange[1] = false;
            }
        } else { // no need to step pulse
            timerWrite(stepGen_1, 4000ul); // 0,1 millis scan
            b_math[1] = true; // calculation of a new period time
        }
    } else { // the middle of the period time (step H-L transition)
        STEP_1_L;
        timerWrite(stepGen_1, ul_TL[1]);
        b_stepState = LOW;
    }
}
/*==================================================================*/
void IRAM_ATTR onTime_2()
{
    static bool b_stepState = LOW;
    static bool b_dirState = LOW;
    if (b_stepState == LOW) { // end of period
        if (ul_T[2]) { // there is a period time so a pulse must be started
            if (!b_dirChange[2]) { //direction is good, start a new pulse (step L-H transition)
                STEP_2_H;
                timerWrite(stepGen_2, ul_TH[2]);
                b_stepState = HIGH;
                b_dirState ? fb.pos[2]++ : fb.pos[2]--;
                b_math[2] = true; // calculation of a new period time
            } else { // need to change direction
                if (b_dirSignal[2]) {
                    DIR_2_H;
                    b_dirState = HIGH;
                } else {
                    DIR_2_L;
                    b_dirState = LOW;
                }
                timerWrite(stepGen_2, ul_dirSetup[2]);
                b_dirChange[2] = false;
            }
        } else { // no need to step pulse
            timerWrite(stepGen_2, 4000ul); // 0,1 millis scan
            b_math[2] = true; // calculation of a new period time
        }
    } else { // the middle of the period time (step H-L transition)
        STEP_2_L;
        timerWrite(stepGen_2, ul_TL[2]);
        b_stepState = LOW;
    }
}
/*==================================================================*/
void IRAM_ATTR newT(const int i) // period time calculation
{
    //ul_T = 40000000.0f / sqrtf((float)(ul_accelStep * ul_accel_x2));
    ul_T = 40000000.0f * fastInvSqrt((float)ul_accelStep * f_accel_x2); // fast method (>3x)
    ul_TH = ul_T >> 1;
    ul_TL = ul_T - ul_TH;
}
/*==================================================================*/
void IRAM_ATTR deceleration(const int i)
{
    if (ul_accelStep) {
        ul_accelStep--;
        if (ul_accelStep)
            newT(i);
        else
            ul_T = 0;
    }
}
/*==================================================================*/
void IRAM_ATTR acceleration(const int i)
{
    if (cmd.control & CTRL_ENABLE) {
        ul_accelStep++;
        newT(i);
    } else
        deceleration(i);
}
/*==================================================================*/
void IRAM_ATTR outputHandler() {
    static int last_pwm[6] = { 0, 0, 0, 0, 0, 0 };
    bool enable = cmd.control & CTRL_ENABLE;
    if (pwm_enable[0]) {
        if (enable) {
            if (last_pwm[0] != cmd.pwm[0]) {
                last_pwm[0] = cmd.pwm[0];
                ledcWrite(0, last_pwm[0]);
            }
        } else {
            ledcWrite(0, 0);
            last_pwm[0] = 0;
        }
    } else {
        if (enable) {
            if (cmd.io & IO_00) {
                OUT_00_H;
            } else {
                OUT_00_L;
            }
        } else {
            OUT_00_L;
        }
    }
    if (pwm_enable[1]) {
        if (enable) {
            if (last_pwm[1] != cmd.pwm[1]) {
                last_pwm[1] = cmd.pwm[1];
                ledcWrite(2, last_pwm[1]);
            }
        } else {
            ledcWrite(2, 0);
            last_pwm[1] = 0;
        }
    } else {
        if (enable) {
            if (cmd.io & IO_01) {
                OUT_01_H;
            } else {
                OUT_01_L;
            }
        } else {
            OUT_01_L;
        }
    }
    if (pwm_enable[2]) {
        if (enable) {
            if (last_pwm[2] != cmd.pwm[2]) {
                last_pwm[2] = cmd.pwm[2];
                ledcWrite(4, last_pwm[2]);
            }
        } else {
            ledcWrite(4, 0);
            last_pwm[2] = 0;
        }
    } else {
        if (enable) {
            if (cmd.io & IO_02) {
                OUT_02_H;
            } else {
                OUT_02_L;
            }
        } else {
            OUT_02_L;
        }
    }
    if (pwm_enable[3]) {
        if (enable) {
            if (last_pwm[3] != cmd.pwm[3]) {
                last_pwm[3] = cmd.pwm[3];
                ledcWrite(6, last_pwm[3]);
            }
        } else {
            ledcWrite(6, 0);
            last_pwm[3] = 0;
        }
    } else {
        if (enable) {
            if (cmd.io & IO_03) {
                OUT_03_H;
            } else {
                OUT_03_L;
            }
        } else {
            OUT_03_L;
        }
    }
    if (pwm_enable[4]) {
        if (enable) {
            if (last_pwm[4] != cmd.pwm[4]) {
                last_pwm[4] = cmd.pwm[4];
                ledcWrite(8, last_pwm[4]);
            }
        } else {
            ledcWrite(8, 0);
            last_pwm[4] = 0;
        }
    } else {
        if (enable) {
            if (cmd.io & IO_04) {
                OUT_04_H;
            } else {
                OUT_04_L;
            }
        } else {
            OUT_04_L;
        }
    }
    if (pwm_enable[5]) {
        if (enable) {
            if (last_pwm[5] != cmd.pwm[5]) {
                last_pwm[5] = cmd.pwm[5];
                ledcWrite(10, last_pwm[5]);
            }
        } else {
            ledcWrite(10, 0);
            last_pwm[5] = 0;
        }
    } else {
        if (enable) {
            if (cmd.io & IO_05) {
                OUT_05_H;
            } else {
                OUT_05_L;
            }
        } else {
            OUT_05_L;
        }
    }
}
/*==================================================================*/
void IRAM_ATTR inputHandler()
{
    (IN_00) ? fb.io = IO_00 : fb.io = 0;
    if (IN_01)
        fb.io |= IO_01;
    if (IN_02)
        fb.io |= IO_02;
    if (IN_03)
        fb.io |= IO_03;
    if (IN_04)
        fb.io |= IO_04;
    if (IN_05)
        fb.io |= IO_05;
    if (IN_06)
        fb.io |= IO_06;
    if (IN_07)
        fb.io |= IO_07;
}
/*==================================================================*/
void IRAM_ATTR commandHandler()
{
    if (cmd.control & CTRL_READY) {
        Serial.println("Handling CTRL_READY");
        for (int i = 0; i < 3; i++) {
            if (cmd.vel > 0.0f)
                ul_cmd_T = (unsigned long)(40000000.0f / cmd.vel);
            else if (cmd.vel < 0.0f)
                ul_cmd_T = (unsigned long)(40000000.0f / -cmd.vel);
            else
                ul_cmd_T = 40000000ul;
        }
    }
    if (!(fb.control & CTRL_READY)) {
        Serial.println("fb.control not ready");
        if ((fb.control & CTRL_DIRSETUP)
            && (fb.control & CTRL_ACCEL)
            && (fb.control & CTRL_PWMFREQ)) {
            fb.control |= CTRL_READY;
            Serial.println("CTRL_READY set");
        } else if (cmd.control & CTRL_DIRSETUP) {
            fb.control |= CTRL_DIRSETUP;
            for (int i = 0; i < 3; i++)
                ul_dirSetup = cmd.pos / 25; //   25ns / timer tic
            Serial.println("CTRL_DIRSETUP set");
        } else if (cmd.control & CTRL_ACCEL) {
            fb.control |= CTRL_ACCEL;
            for (int i = 0; i < 3; i++)
                f_accel_x2 = (float)cmd.pos * 2.0;
            Serial.println("CTRL_ACCEL set");
        } else if (cmd.control & CTRL_PWMFREQ) {
            fb.control |= CTRL_PWMFREQ;
            for (int i = 0; i < 6; i++) {
                if (cmd.pwm) {
                    ledcAttach(pwm_pin, i * 2, true);
                    ledcAttach(pwm_pin, cmd.pwm, 10);
                    ledcWrite(i * 2, 0);
                    pwm_enable = true;
                    Serial.print("PWM enabled for pin ");
                    Serial.println(pwm_pin);
                } else {
                    if (i == 0) {
                        pinMode(OUT_00_PIN, OUTPUT);
                        digitalWrite(OUT_00_PIN, 0);
                    } else if (i == 1) {
                        pinMode(OUT_01_PIN, OUTPUT);
                        digitalWrite(OUT_01_PIN, 0);
                    } else if (i == 2) {
                        pinMode(OUT_02_PIN, OUTPUT);
                        digitalWrite(OUT_02_PIN, 0);
                    } else if (i == 3) {
                        pinMode(OUT_03_PIN, OUTPUT);
                        digitalWrite(OUT_03_PIN, 0);
                    } else if (i == 4) {
                        pinMode(OUT_04_PIN, OUTPUT);
                        digitalWrite(OUT_04_PIN, 0);
                    } else if (i == 5) {
                        pinMode(OUT_05_PIN, OUTPUT);
                        digitalWrite(OUT_05_PIN, 0);
                    }
                }
            }
        }
    }
}
/*==================================================================*/
void IRAM_ATTR loop_Core0(void* parameter)
{
    delay(500);
    Udp.parsePacket(); /* to empty buffer */
    for (;;) {
        Serial.println("Inside loop_Core0");
        static unsigned long ul_watchdog;
        if (Udp.parsePacket() == sizeof(cmd) + 1) {
            char packetBuffer[60]; // buffer for receiving and sending data
            Udp.read(packetBuffer, sizeof(cmd) + 1);
            uint8_t chk = 71;
            for (int i = 0; i < sizeof(cmd); i++)
                chk ^= packetBuffer;
            if (packetBuffer[sizeof(cmd)] == chk) {
                memcpy(&cmd, &packetBuffer, sizeof(cmd));
                commandHandler();
                ul_watchdog = millis();
            }
            inputHandler();
            for (int i = 0; i < 3; i++) {
                unsigned long ul_t = ul_T;
                if (ul_t)
                    b_dirSignal ? fb.vel = 40000000.0f / (float)ul_t : fb.vel = -40000000.0f / (float)ul_t;
                else
                    fb.vel = 0.0f;
            }
            memcpy(&packetBuffer, &fb, sizeof(fb));
            Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
            Udp.write(packetBuffer, sizeof(fb));
            Udp.endPacket();
            outputHandler();
        }
        if (millis() - ul_watchdog > 10ul) {
            fb.control = 0;
            cmd.control = 0;
            outputHandler();
            ul_watchdog = millis();
        }
        esp_task_wdt_reset();
    }
}
/*==================================================================*/
void setup_Core0(void* parameter)
{  
    disableCore0WDT(); // Disable Core0 Watchdog Timer
    //disableCore1WDT(); // Disable Core1 Watchdog Timer
   
    pinMode(IN_00_PIN, INPUT_PULLUP);
    pinMode(IN_01_PIN, INPUT_PULLUP);
    pinMode(IN_02_PIN, INPUT_PULLUP);
    pinMode(IN_03_PIN, INPUT_PULLUP);
    pinMode(IN_04_PIN, INPUT);
    pinMode(IN_05_PIN, INPUT);
    pinMode(IN_06_PIN, INPUT);
    pinMode(IN_07_PIN, INPUT);
    delay(500);
    Ethernet.init(SPI_CS_PIN); /* You can use Ethernet.init(pin) to configure the CS pin */
    Ethernet.begin(mac, ip); /* start the Ethernet */
    delay(500);
    Udp.begin(port); /* start UDP */
    delay(100);
    xTaskCreatePinnedToCore(
        loop_Core0, // Task function.
        "loopTask_Core0", // name of task.
        1024, // Stack size of task, // Stack size of task
        NULL, // parameter of the task
        0, // priority of the task (changed to 1)
        NULL, // Task handle to keep track of created task
        0); // pin task to core 0
    //disableCore0WDT();
    vTaskDelete(NULL);
}
/*==================================================================*/
void setup()
{
    Serial.begin(9600);
    //disableCore0WDT(); // Disable Core0 Watchdog Timer
    //disableCore1WDT(); // Disable Core1 Watchdog Timer
   
    pinMode(STEP_0_PIN, OUTPUT);
    digitalWrite(STEP_0_PIN, 0);
    pinMode(DIR_0_PIN, OUTPUT);
    digitalWrite(DIR_0_PIN, 0);
    pinMode(STEP_1_PIN, OUTPUT);
    digitalWrite(STEP_1_PIN, 0);
    pinMode(DIR_1_PIN, OUTPUT);
    digitalWrite(DIR_1_PIN, 0);
    pinMode(STEP_2_PIN, OUTPUT);
    digitalWrite(STEP_2_PIN, 0);
    pinMode(DIR_2_PIN, OUTPUT);
    digitalWrite(DIR_2_PIN, 0);
    // Configure the timers
 // Set timer frequency to 1 MHz (1,000,000 Hz)
    stepGen_0 = timerBegin(1000000); // Timer 0
    stepGen_1 = timerBegin(1000000); // Timer 1
    stepGen_2 = timerBegin(1000000); // Timer 2
    // Attach the interrupt service routine (ISR) `onTime_0` to Timer 0.
    timerAttachInterrupt(stepGen_0, &onTime_0);
    // Attach the ISR `onTime_1` to Timer 1.
    timerAttachInterrupt(stepGen_1, &onTime_1);
    // Attach the ISR `onTime_2` to Timer 2.
    timerAttachInterrupt(stepGen_2, &onTime_2);
    // Set the alarm value for Timer 0 to 40,000,000 microseconds (40 seconds).
    timerAlarm(stepGen_0, 40000000, true, 0);
    // Set the alarm value for Timer 1 to 40,000,000 microseconds (40 seconds).
    timerAlarm(stepGen_1, 40000000, true, 0);
    // Set the alarm value for Timer 2 to 40,000,000 microseconds (40 seconds).
    timerAlarm(stepGen_2, 40000000, true, 0);
    // Start Timer 0.
   // timerStart(stepGen_0);
    // Start Timer 1.
  //  timerStart(stepGen_1);
    // Start Timer 2.
  //  timerStart(stepGen_2);
    xTaskCreatePinnedToCore(
        setup_Core0, // Task function.
        "setup_Core0Task", // name of task.
        1024, // Stack size of task
        NULL, // parameter of the task
        0, // priority of the task
        NULL, // Task handle to keep track of created task
        0); // pin task to core 0
    //vTaskDelete(NULL);
}
/*==================================================================*/
void IRAM_ATTR loop()
{
    for (int i = 0; i < 3; i++) {
        if (b_math) {
            Serial.print("Math processing for axis: ");
            Serial.println(i);
            b_math = false;
            if (!ul_accelStep) { // the axis is stationary
                long l_pos_error = cmd.pos - fb.pos;
                Serial.print("Position error for axis ");
                Serial.print(i);
                Serial.print(": ");
                Serial.println(l_pos_error);
                if (l_pos_error) { // if there is a position error
                    if ((l_pos_error > 0 && b_dirSignal == HIGH) || (l_pos_error < 0 && b_dirSignal == LOW)) // the direction is good
                        acceleration(i);
                    else { // need to change direction
                        (l_pos_error > 0) ? b_dirSignal = HIGH : b_dirSignal = LOW;
                        b_dirChange = true;
                        Serial.print("Changing direction for axis ");
                        Serial.println(i);
                    }
                }
            } else { // the axis moves
                Serial.print("Axis ");
                Serial.print(i);
                Serial.println(" is moving");
                if ((cmd.vel > 0.0f && b_dirSignal == HIGH) || (cmd.vel < 0.0f && b_dirSignal == LOW)) { // the direction is good
                    if (ul_T > ul_cmd_T) // the speed is low
                        acceleration(i);
                    else if (ul_T < ul_cmd_T) // the speed is high
                        deceleration(i);
                } else // the direction is wrong or the target speed is zero
                    deceleration(i);
            }
        }
    }
}

But still im getting error as 
ELF file SHA256: 78d5431e5da1b11c

 Rebooting...
�E (123) task_wdt: esp_task_wdt_reset(763): task not found
E (124) task_wdt: esp_task_wdt_reset(763): task not found
E (125) task_wdt: esp_task_wdt_reset(763): task not found
E (173) task_wdt: esp_task_wdt_reset(763): task not found
E (235) task_wdt: esp_task_wdt_reset(763): task not found
E (296) task_wdt: esp_task_wdt_reset(763): task not found
E (358) task_wdt: esp_task_wdt_reset(763): task not found
E (419) task_wdt: esp_task_wdt_reset(763): task not found
E (481) task_wdt: esp_task_wdt_reset(763): task not found
E (542) task_wdt: esp_task_wdt_reset(763): task not found
E (604) task_wdt: esp_task_wdt_reset(763): task not found
Guru Meditation Error: Core 0 panic'ed (Unhandled debug exception).
Debug exception reason: Stack canary watchpoint triggered (setup_Core0Task)
Core 0 register dump:
PC : 0x4008b56c PS : 0x00060a36 A0 : 0x40084766 A1 : 0x3ffb8c90
A2 : 0x00000000 A3 : 0x3ffc1f7c A4 : 0xffffffff A5 : 0x3ffc221c
A6 : 0x00000227 A7 : 0x00000000 A8 : 0x80083ad8 A9 : 0x3ffb8d30
A10 : 0x3ff000dc A11 : 0x00000001 A12 : 0x00060620 A13 : 0x3f407040
A14 : 0x80000000 A15 : 0x00060021 SAR : 0x00000007 EXCCAUSE: 0x00000001
EXCVADDR: 0x00000000 LBEG : 0x400868c0 LEND : 0x400868d6 LCOUNT : 0x00000000

 
 Backtrace: 0x4008b569:0x3ffb8c90 0x40084763:0x3ffb8d70 0x400d4275:0x3ffb8d90 0x400d2e5b:0x3ffb8db0 0x400d1e97:0x3ffb8de0 0x400d1f3c:0x3ffb8e10 0x400d1f9d:0x3ffb8ec0 0x400d1ff0:0x3ffb8f60 0x400d18fd:0x3ffb8fe0 0x4008b1fd:0x3ffb9030

 
Last edit: 25 Jul 2024 08:58 by yathish.

Please Log in or Create an account to join the conversation.

More
25 Jul 2024 10:33 #306000 by cornholio
The dev seems active on the github repo, raise the issue there and be patient and wait for a reply.

Please Log in or Create an account to join the conversation.

Time to create page: 0.141 seconds
Powered by Kunena Forum