gin66 / FastAccelStepper

A high speed stepper library for Atmega 168/328p (nano), Atmega32u4, Atmega 2560, ESP32, ESP32S2, ESP32S3, ESP32C3, ESP32C6 and Atmel SAM Due
MIT License
301 stars 70 forks source link

Mega 2560 - 0.28.4 - The distance diffirent after change speed #193

Closed quanlotbangsat closed 1 year ago

quanlotbangsat commented 1 year ago

Hi gin66, thank you so much for your lib.

But i have issue when using mega 2560, first it maximum 1000hz if i using your 30.4 library, So i must using 28.4

On 28.4, I don't know why when i change speed the distance will diffirent. When the speed is slow the distance go longer. The code using Zero like this and moveto: bool zeroservo(FastAccelStepper servo, ServoMM servodata, byte zerosensor, float speed) { bool done; if (!servo->isRunning()) { if (digitalRead(zerosensor)) { servo->setSpeedInHz(speed); servo->move(-1000000); onzero = true; } else goto d;

    while (digitalRead(zerosensor)) {

        if (!servo->isRunning())
            goto a;
        if (stopnow == 1)
            goto b;
        loop();

    }
    d:
    //servo->stopMove();
    servo->forceStopAndNewPosition(0);
    while (servo->isRunning())
        ;
    //Serial.println(servodata->zeropoint_offset);
    servo->move(servodata->zeropoint_offset);

    while (servo->isRunning()) {

        loop();
    }
    servo->setPositionAfterCommandsCompleted(0);
    servodata->homed = 1;
}
onzero = false;
return 1;
b: stopnow = 0;
servodata->homed = 1;
onzero = false;
a:

return 0;

}

Pls support me

gin66 commented 1 year ago

For better understanding: Where is zeroservo() called ? Inside loop() or in setup() ?

quanlotbangsat commented 1 year ago

I call it throught serial.

gin66 commented 1 year ago

not clear. Could you please provide more of your code ?

There are calls to loop() within this function. This smells like a recursive use of loop(), which may cause all sorts of side effects.