single-coil-2motors

dinosalvioni/adafruit-motor-shield-v1/single-coil-2motors

No description
single-coil-2motors
@/single-coil-2motors
M1_maxspeednumber
MOTORE 1: velogità massima (g/min)
M1_accelnumber
MOTORE 1: accelerazione
M1RUNboolean
M1REVboolean
M2_maxspeednumber
MOTORE 2: velogità massima (g/min)
M2_accelnumber
Numero di step per ogni giro del motore: è una caratteristica del motore in uso
M2RUNboolean
M2REVboolean
UPDpulse
Avvia il motore nel senso scelto per il numero di step stabilito alla velocità stabilita poi lascialo libero. Se lanciato in continuazione tiene acceso il movimento
single-coil-2motors
M1_maxspeed
M1_accel
M1RUN
M1REV
M2_maxspeed
M2_accel
M2RUN
M2REV
UPD
DONE
DONEpulse
To use the node in your project you should have the dinosalvioni/adafruit-motor-shield-v1 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/adafruit/Adafruit-Motor-Shield-library"

// Adafruit Motor shield library
// copyright Adafruit Industries LLC, 2009
// this code is public domain, enjoy!





{{#global}}
#include "AccelStepper.h"
#include "AFMotor.h"
{{/global}}


struct State {
};

        

{{ GENERATED_CODE }}
// two stepper motors one on each port
AF_Stepper motor1(200, 1);
AF_Stepper motor2(200, 2);

// you can change these to DOUBLE or INTERLEAVE or MICROSTEP!
// wrappers for the first motor!
void forwardstep1() {  
  motor1.onestep(FORWARD, SINGLE);
}
void backwardstep1() {  
  motor1.onestep(BACKWARD, SINGLE);
}
// wrappers for the second motor!
void forwardstep2() {  
  motor2.onestep(FORWARD, SINGLE);
}
void backwardstep2() {  
  motor2.onestep(BACKWARD, SINGLE);
}
// Motor shield has two motor ports, now we'll wrap them in an AccelStepper object
AccelStepper stepper1(forwardstep1, backwardstep1);
AccelStepper stepper2(forwardstep2, backwardstep2);


void evaluate(Context ctx) {
auto state = getState(ctx);
//AF_Stepper motor(getValue<input_STEPrev>(ctx), getValue<input_MOTORn>(ctx));
auto position=1000000;


    stepper1.setMaxSpeed(getValue<input_M1_maxspeed>(ctx));
    stepper1.setAcceleration(getValue<input_M1_accel>(ctx));
 
    auto position1=position;   
    if (getValue<input_M1REV>(ctx)) {
        position1=-position;
    }

    stepper2.setMaxSpeed(getValue<input_M2_maxspeed>(ctx));
    stepper2.setAcceleration(getValue<input_M2_accel>(ctx));

    auto position2=position;
    if (getValue<input_M2REV>(ctx)) {
        position2=-position;
    }


    if (isInputDirty<input_UPD>(ctx)){

        if (getValue<input_M1RUN>(ctx)) {
            stepper1.moveTo(position1);
            stepper1.run();
        }else{
            stepper1.setMaxSpeed(1)//TEST
            stepper1.run();//TEST
            
            motor1.release(); 
            stepper1.disableOutputs();
        }


        if (getValue<input_M2RUN>(ctx)) {
            stepper2.moveTo(position2);
            stepper2.run();
        }else{
            stepper2.setMaxSpeed(1) //TEST
            stepper2.run(); //TEST
            
            motor2.release(); 
            stepper2.disableOutputs();
        }


    emitValue<output_DONE>(ctx, 1);
    }


}