Hello!
I think this is the right place to put this, as it is about programming, not necessarily the steppers.
Using the AccelStepper library, how do I get steppers to move simultaneously? Let's say, for example, that I want stepper A to move 3200 steps CW, and stepper B to move 200 steps CCW, how can I use the AccelStepper library to do this? I'm sure it has something to do with modulating the speeds of the different motors, but I'm not sure how to do this, and I've been unsuccessful in previous circumstances. I have tried modulating speeds, but the code fails in an unusual way --
Stepper X rotates the full amount, Stepper Y (Despite the values I enter) spins up indefinitely and does not accelerate. they do go simultaneously though!
#include <AccelStepper.h>
#define speed 6400
AccelStepper X(1,54,55);
AccelStepper Y(1,60,61);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
X.setMaxSpeed(speed);
X.setAcceleration(1600);
Y.setMaxSpeed(speed);
Y.setAcceleration(1600);
pinMode(38, OUTPUT);
pinMode(56, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available()>0){
int xPos=Serial.parseInt();
(void)Serial.read();
int yPos=Serial.parseInt();
X.move(xPos);
Y.move(yPos);
int biggest=max(xPos,yPos);
if(biggest==xPos){
Y.setMaxSpeed((yPos*speed)/xPos);
X.setMaxSpeed(speed);
}else if(biggest==yPos){
X.setMaxSpeed((xPos*speed)/yPos);
X.setMaxSpeed(speed);
}
bool done1=1;
bool done2=1;
while(done1||done2){//Yes, I did try just "while(X.run()||Y.run()){};" but that did the same thing. I thought that it might be because the first one is true, it doesn't evaluate the second. This didn't fix it though!
done1=0;
done2=0;
done1=X.run();
done2=Y.run();
}
}
}
Any help will be much appreciated.