Pages: [1]   Go Down
 Author Topic: 2 Stepper Moving Simultaneiously.  (Read 493 times) 0 Members and 1 Guest are viewing this topic.
Offline
Newbie
Karma: 0
Posts: 11
 « on: December 06, 2012, 09:28:39 am » Bigger Smaller Reset

Hello, Geeks!

I am working on a projekt, that need control two Steppers with two Potis. The Model is something like a balance. Ja as the topic say, the two stepper should work simultaneiously.

I look up so much much info. on the site.like
the Kritzler(http://tinkerlog.com/2011/09/02/der-kritzler/), accelstepper(http://www.open.com.au/mikem/arduino/AccelStepper/),
Interrup(http://www.uchobby.com/index.php/2007/11/24/arduino-interrupts/)

Some of them really done a perfect deep research. But I can still not get the very idea how to control them.
So, is anyone can share a tutorial about how to control two stepper simultaneously with accelstepp library(cause I am not a programmer, the C and C++ code is not that easy for me). Or just make a small sample here.
BTW. must I use the Interrupt to control the two motor?

gfast
 Logged

Massachusetts, USA
Offline
Tesla Member
Karma: 97
Posts: 6380
 « Reply #1 on: December 06, 2012, 12:19:32 pm » Bigger Smaller Reset

Code:
void loop() {
unsigned long currentTime = millis();

// If it's time to step Motor 1...
if (motor1Stepping && (currentTime - lastMotor1Time > motor1Interval))
stepMotor1();

// If it's time to step Motor 2...
if (motor2Stepping && (currentTime - lastMotor2Time > motor2Interval))
stepMotor2();

// Do other stuff like figuring out which way and how fast to step the motors.
}

 Logged

Offline
Newbie
Karma: 0
Posts: 11
 « Reply #2 on: December 07, 2012, 08:44:59 am » Bigger Smaller Reset

Code:
void loop() {
unsigned long currentTime = millis();

// If it's time to step Motor 1...
if (motor1Stepping && (currentTime - lastMotor1Time > motor1Interval))
stepMotor1();

// If it's time to step Motor 2...
if (motor2Stepping && (currentTime - lastMotor2Time > motor2Interval))
stepMotor2();

// Do other stuff like figuring out which way and how fast to step the motors.
}

Thanks！！
After reading your codes and some sample, Last night I've really getting startted.

Hier is the little sample to share.

Code:
// AFMotor_MultiStepper.pde
// -*- mode: C++ -*-
//
// Control both Stepper motors at the same time with different speeds
// and accelerations.
#include <AccelStepper.h>
#include <AFMotor.h>

// two stepper motors one on each port
AF_Stepper motor1(200, 1);
AF_Stepper motor2(96, 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 setup()

stepper1.setMaxSpeed(300.0);
stepper1.setAcceleration(100.0);
stepper1.moveTo(240);

stepper2.setMaxSpeed(300.0);
stepper2.setAcceleration(100.0);
stepper2.moveTo(240);

}
void loop()
{
// Change direction at the limits
if (stepper1.distanceToGo() == 0)
stepper1.moveTo(-stepper1.currentPosition());
if (stepper2.distanceToGo() == 0)
stepper2.moveTo(-stepper2.currentPosition());
stepper1.run();
stepper2.run();
}
 Logged

Offline
Newbie
Karma: 0
Posts: 11
 « Reply #3 on: December 08, 2012, 04:31:46 pm » Bigger Smaller Reset

Cause I wanna the Balance to balance as a definite proportion between four different things . So I've changed the motor controller from Adafruit Motor shield to four A4988 Stepper Driver from Pololu.
And the result is pretty tricky.Till to three steppers, the Arduino code that written like the above works still well beside the low speed range. But if I defined four "AccelStepper" in the code.they seemed like they just block them from each another,and the motors stay still.
I searched Youtube the installation from other Guys. There is mainly two types of solution. One is use something like "A Big Chip, which have so many Pins" and the other changed the Arduino by a Board named ChipKit, which have a 80MHz work frequency.

I thought the Problem over, and decided to try ChipKit. But I'm not sure the circuit wired up right. So please check out the Picture. Thanks!!
 Logged

 Pages: [1]   Go Up