move

jdavis-nodes/fastaccelstepper/move

No description
move
@/move
DEV@/fastaccelstepper-device
MODEnumber
0: // Stop 1: // Move to position 2: // Continuous speed
POSnumber
SPDnumber
DOpulse
move
DEV
MODE
POS
SPD
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 mode and parameters
        auto mode = getValue<input_MODE>(ctx); // 0 = stop, 1 = move to position, 2 = continuous speed
        auto position = getValue<input_POS>(ctx); // Target position in steps
        auto speed = getValue<input_SPD>(ctx); // Speed for continuous rotation (steps/s)

        // Perform the action based on mode
        if (!stepper) {
            raiseError(ctx); // Invalid stepper instance
            return;
        }

        switch ((int)mode) {
            case 0: // Stop
                stepper->stopMove();
                break;
            case 1: // Move to position
                stepper->moveTo(position);
                break;
            case 2: // Continuous speed
                stepper->setSpeedInHz(abs(speed));
                if (speed > 0) {
                    stepper->runForward();
                } else if (speed < 0) {
                    stepper->runBackward();
                }
                break;
            default:
                raiseError(ctx); // Invalid mode
                return;
        }

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