Go Down

Topic: Pausing Steppers using AccelStepper (Read 827 times) previous topic - next topic

AXNRXN

Hi All,

I'm building a weird clock as part of a sculpture installation. I'm using three different stepper motors to control the "hands" of the clock. I say its weird because this clock uses half-day increments, months, and two-month increments rather than seconds, minutes, hours. But, for this question, that shouldn't matter.

I'm trying to figure out how to delay the second hand between movements without effecting the minute and hour hands. So, as it is now, I ramp up the second hand up to speed, rotate, and ramp down to 180-degrees and repeat. I don't have any delay between the ramp down and the next ramp up, but I'd like to have some. If I add a "delay(10)" in there for instance, both the minute and hour hands will also delay each time a second passes. The minute and hour hands take a few seconds to position themselves and I'd like them to move smoothly and not encounter this delay. So, I think I have to delay the second hand using millis() or some other function.

So, the condensed question is how do you use AccelStepper to move and stop one stepper multiple time while two other steppers continue to move smoothly? I'm using three Big Easy Drivers and an Arduino Uno. Its all powered off of a 12v/10A power supply.

Code: [Select]
/*
Description
This is the Arduino code for the Coincidence Clock. Three individual stepper motors are connected to the day, month and coincidence dials on the clock.
The day dial in the center moves in half-day increments. So, the first movement is 180-degrees with a brief pause follwed by another 180-degree revolution completing the motion.


Steppers = 200 steps / revolution. 1.2A / coil. 

*/

//******************Constants***********
#include <AccelStepper.h>
#include <Servo.h>

Servo myservo;  // create servo object to control a servo

AccelStepper dayStepper(1, 13, 12);
AccelStepper monthStepper(1, 10, 9);
AccelStepper coincidenceStepper(1, 7, 6);

int halfDaySteps = 400; //Using 1/4 step
int monthSteps = 3430;  //use default 16 steps. 231 teeth on wheel. 18 teeth on pulley. Ratio = 12.833. 200 steps / rev * 16 = 3200, 3422.13 steps
int coincidenceSteps = 2193;  // Default 16th step. 74 teeth on wheel, 18 on pulley. Ration = 4.111. 3200 * 4.111 / 6 = 2193 steps per movement

long totalDays = 9490000 * 2 + 1; // DAYS * 2 (half day steps) Add +1 to total desired days. 26000 years = 365 * 26000 = 9,490,000
int daysInMonth = 30 * 2; // 30 Days in a month * 2 half days
int daysInCoincidence = 60 * 2; // 30 days in Coincidence * 2 half days

//******************Variables***********
long dayCount = 0;
long monthCount = 0;
long oldTime = 0;
//****************Function Prototypes******

void endlessLoop();
//***************Setup******************************
void setup() {
 
  dayStepper.setMaxSpeed(500);
  dayStepper.setAcceleration(4000);
  monthStepper.setMaxSpeed(684);
  monthStepper.setAcceleration(2000);
  coincidenceStepper.setMaxSpeed(438);
  coincidenceStepper.setAcceleration(2000);
 
  myservo.attach(2);  // attaches the servo on pin 2 to the servo object
  delay(1000);
 
  for(int i=15; i <= 170; i++){    //Sweep the servos to align season symbols
    myservo.write(i);                  // sets the servo position according to the scaled value
    delay(3);                    // waits for the servo to get there
  }
delay(1000);
for(int i=170; i >= 15; i--){       //Return servos to start position
  myservo.write(i);                  // sets the servo position according to the scaled value
  delay(3);        // waits for the servo to get there
}
delay(1000);
}

//*************Main Program Loop************************
void loop() {

  if (dayStepper.distanceToGo() == 0)
   {
    dayStepper.setCurrentPosition(0);
    dayCount++;
    dayStepper.moveTo(halfDaySteps);
    oldTime = millis();
   }

 
  int monthTag = dayCount % daysInMonth;
  if(monthTag == 0){
    if (monthStepper.distanceToGo() == 0)
    {
      //delay(5000);
      monthStepper.setCurrentPosition(0);
      monthCount++;
      monthStepper.moveTo(monthSteps);
    }
  }
 
  int coincidenceTag = dayCount % daysInCoincidence;
  if(coincidenceTag == 0){
    if (coincidenceStepper.distanceToGo() == 0)
    {
      //delay(5000);
      coincidenceStepper.setCurrentPosition(0);
      coincidenceStepper.moveTo(coincidenceSteps);
    }
  } 
 
  dayStepper.run();
  monthStepper.run();
  coincidenceStepper.run();
 
   if(dayCount == totalDays){
     for(int i=15; i <= 170; i++){
     myservo.write(i);                  // sets the servo position according to the scaled value
     delay(3);                          // waits for the servo to get there
   }
   endlessLoop();
  }
 
}
//*********************FUNCTIONS***************************
void endlessLoop(){
  int i =0;
  while(i == 0){
  }

}
//**************************************************************************





I tried this, and it you have to fudge around with the timing to get the pause to work. But, if I do this, the second hand seems to loose its position and stops in random places. So, calling dayStepper at a delayed rate seems to screw with the positioning.

Code: [Select]
if (millis() - oldTime > 1500){
  if (dayStepper.distanceToGo() == 0)
   {
    dayStepper.setCurrentPosition(0);
    dayCount++;
    dayStepper.moveTo(halfDaySteps);
    oldTime = millis();
   }
}


Thanks for any help!

sbright33

You may have already chosen the best library for your task.  But if you get stuck, it is easy to make mine work with multiple motors non-blocking.  Soon I may make it easier as an object.  It's all here in the Motor category.
If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

Go Up