Set's stepper running speed in Hz (rotations/second)
set-speed
@/set-speed
Set's stepper running speed in Hz (rotations/second)
DEV@/fastaccelstepper-device
VALnumber
DOpulse
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 speed value
//auto mode = getValue<input_MODE>(ctx); // 0 = us, 1 = ticks, 2 = Hz, 3 = milliHz
auto value = getValue<input_VAL>(ctx); // Speed value in selected unit
int8_t result = -1;
// Perform the action based on mode
/*
switch ((int)mode) {
case 0: // Microseconds
result = stepper->setSpeedInUs((uint32_t)value);
break;
case 1: // Ticks
result = stepper->setSpeedInTicks((uint32_t)value);
break;
case 2: // Hz
result = stepper->setSpeedInHz((uint32_t)value);
break;
case 3: // milliHz
result = stepper->setSpeedInMilliHz((uint32_t)value);
break;
default:
raiseError(ctx); // Invalid mode
return;
}
*/
result = stepper->setSpeedInHz((uint32_t)value);
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);
}
}