Pages: [1]   Go Down
Author Topic: 2 Stepper Moving Simultaneiously.  (Read 982 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset 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/)
Adafruit Motor shield(http://www.ladyada.net/make/mshield/use.html)

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 Offline
Tesla Member
***
Karma: 180
Posts: 8103
View Profile
 Bigger Bigger  Smaller Smaller  Reset 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

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset 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.
// Requires the AFMotor library (https://github.com/adafruit/Adafruit-Motor-Shield-library)
#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 Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset 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!!


* withStepperWire.jpg (685.57 KB, 4288x2848 - viewed 34 times.)

* withoutStepperWire.jpg (583.83 KB, 4288x2848 - viewed 19 times.)
Logged

Pages: [1]   Go Up
Jump to: