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 {
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);
}
// 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 - need struct!
// 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);
}
}
}