multistepperlite

jdavis-nodes/multistepperlite/multistepperlite

No description
multistepperlite
@/multistepperlite
STEPport
DIRport
PPSnumber
Nnumber
GOpulse
STOPpulse
PAUSEpulse
RESUMEpulse
multistepperlite
STEP
DIR
PPS
N
GO
STOP
PAUSE
RESUME
DONE
POS
POSnumber
DONEpulse
To use the node in your project you should have the jdavis-nodes/multistepperlite 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 require "https://github.com/gunakkoc/MultiStepperLite"

#include <SingleStepperLite.h>

node {
    meta {
        SingleStepperLite stepper;
        using Type = SingleStepperLite*;
    }

    void evaluate(Context ctx) {
        if (isSettingUp()) {
            //SingleStepperLite stepper;
            // Initialize pins and stepper
            auto stepPin = getValue<input_STEP>(ctx);
            auto dirPin = getValue<input_DIR>(ctx);
            pinMode(stepPin, OUTPUT);
            pinMode(dirPin, OUTPUT);
            digitalWrite(dirPin, LOW); // Default direction
            stepper.init_stepper(stepPin);
            // emitValue<output_DEV>(ctx, &stepper);
        }

        // Handle STOP pulse
        if (isInputDirty<input_STOP>(ctx)) {
            stepper.stop();
            emitValue<output_DONE>(ctx, 1);
            return;
        }

        // Handle PAUSE pulse
        if (isInputDirty<input_PAUSE>(ctx)) {
            stepper.pause();
            return;
        }

        // Handle GO pulse
        if (isInputDirty<input_GO>(ctx)) {
            auto pps = getValue<input_PPS>(ctx);
            auto nSteps = getValue<input_N>(ctx);

//             if (pps <= 0) {
//                 raiseError<output_ERR>(ctx);
//                 return;
//             }

            // Set direction based on nSteps sign
            bool dir = nSteps < 0;
            digitalWrite(getValue<input_DIR>(ctx), dir ? HIGH : LOW);

            // Convert PPS to step interval (microseconds)
            uint32_t stepInterval = 1000000 / pps;

            if (nSteps == 0) {
                stepper.start_continuous(stepInterval);
            } else {
                stepper.start_finite(stepInterval, abs(nSteps));
            }
        }

        // Call do_tasks() unless paused or stopped
        //if (stepper.is_running()) {
        uint32_t now_us = micros();
        stepper.do_tasks(now_us);
        setImmediate();
        //}

        // Output position (remaining steps)
        emitValue<output_POS>(ctx, stepper.get_remaining_steps());

        // Emit DONE if finished
        if (stepper.is_finished()) {
            emitValue<output_DONE>(ctx, 1);
        }
    }
}