set-acceleration

jdavis-nodes/fastaccelstepper/set-acceleration

No description
set-acceleration
@/set-acceleration
DEV@/fastaccelstepper-device
VALnumber
DOpulse
set-acceleration
DEV
VAL
DO
DEV'
ACK
ACKpulse
DEV'@/fastaccelstepper-device
To use the node in your project you should have the jdavis-nodes/fastaccelstepper library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

#pragma XOD evaluate_on_pin disable
#pragma XOD evaluate_on_pin enable input_DO

node {
    void evaluate(Context ctx) {
        // Get the stepper instance
        auto stepper = getValue<input_DEV>(ctx);

        if (isSettingUp()) {
            // Short-circuit DEV and DEV'
            emitValue<output_DEVU0027>(ctx, stepper);
        }

        // Only proceed if the DO input is dirty (pulsed)
        if (!isInputDirty<input_DO>(ctx))
            return;

        // Get the acceleration value
        auto accel = getValue<input_VAL>(ctx); // Acceleration in steps/s^2

        // Set the acceleration
        int8_t result = -1;
        result = stepper->setAcceleration((uint32_t)accel);
        stepper->applySpeedAcceleration();

                // Check if the operation was successful
        if (result != 0) {
            raiseError(ctx); // Speed setting failed
            return;
        }

        // Emit a pulse to indicate the action was successful
        emitValue<output_ACK>(ctx, 1);
    }
}