move-to-position

jdavis-nodes/fastaccelstepper/move-to-position

No description
move-to-position
@/move-to-position
DEV@/fastaccelstepper-device
POSnumber
DOpulse
move-to-position
DEV
POS
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);
        }

        // Check for valid stepper instance
        if (!stepper) {
            raiseError(ctx); // Invalid stepper instance
            return;
        }

        // Handle new move command
        if (isInputDirty<input_DO>(ctx)) {
            // Get the position parameter
            auto position = getValue<input_POS>(ctx); // Target position in steps

            // Start moving to the position
            stepper->moveTo(position);
            emitValue<output_ACK>(ctx, 1);
        }
    }
}