I am having a tough time getting my steppers to consistently reach their destination at the same time. Certain combinations of positions work perfectly:
I.e.:
positions[0] = 1000;
positions[1] = 50;
followed by:
positions[0] = -100;
positions[1] = 100;
Works fine. Both steppers arrive at their intended destinations at the same time.
But:
positions[0] = 850;
positions[1] = 1450;
followed by:
positions[0] = 0;
positions[1] = 0;
Doesn't work as I would expect. positions[1] is reached way before positions[0] of the other stepper.
With [850,1450], if I increase the max stepper speed from 100 to 200, the steppers actually both run at the same speed until stepper1 reaches its destination. Then stepper2 speeds up and completes. But it will work correctly for the first set of coordinates [1000,50] to [100,100] .
Confused and frustrated.
Arduino Uno
Motor Shield V2.3
200 step 1.8 degree Arduino 12V steppers
Running right at 12V. About .6A draw when the steppers move and .8A when stationary.
AccelStepper 1.58.0
Adafruit Motor Shield V2 Library 1.0.5
Any suggestions greatly appreciated!
Thanks!
// MultiStepper.pde
// -*- mode: C++ -*-
// Use MultiStepper class to manage multiple steppers and make them all move to
// the same position at the same time for linear 2d (or 3d) motion.
#include <Adafruit_MotorShield.h>
#include <AccelStepper.h>
#include <MultiStepper.h>
Adafruit_MotorShield AFMS(0x60); // Default address, no jumpers
Adafruit_StepperMotor *myStepper1 = AFMS.getStepper(200, 2);
Adafruit_StepperMotor *myStepper2 = AFMS.getStepper(200, 1);
// wrappers for the stepperX
void forwardStep1() {
myStepper1->onestep(FORWARD, DOUBLE);
}
void backwardStep1() {
myStepper1->onestep(BACKWARD, DOUBLE);
}
// wrappers for the stepperY
void forwardStep2() {
myStepper2->onestep(FORWARD, DOUBLE);
}
void backwardStep2() {
myStepper2->onestep(BACKWARD, DOUBLE);
}
// Wrap the steppers in an AccelStepper object
AccelStepper stepper1(forwardStep1, backwardStep1);
AccelStepper stepper2(forwardStep2, backwardStep2);
MultiStepper steppers;
void setup() {
Serial.begin(9600);
AFMS.begin();
// Configure each stepper
stepper1.setMaxSpeed(100);
stepper2.setMaxSpeed(100);
// Then give them to MultiStepper to manage
steppers.addStepper(stepper1);
steppers.addStepper(stepper2);
}
void loop() {
long positions[2]; // Array of desired stepper positions
positions[0] = 1000;
positions[1] = 50;
//positions[0] = 850;
//positions[1] = 1450;
steppers.moveTo(positions);
steppers.runSpeedToPosition(); // Blocks until all are in position
delay(1000);
// Move to a different coordinate
positions[0] = -100;
positions[1] = 100;
//positions[0] = 0;
//positions[1] = 0;
steppers.moveTo(positions);
steppers.runSpeedToPosition(); // Blocks until all are in position
delay(1000);
}