I want to make my stepper motor gradually speed up to a particular rate and then continue spinning at that speed. I thought the AccelStepper library might allow me to do this, with something like:
But looking at the library more carefully, it appears that it only allows the motor to accelerate as it moves to a target position, not when it moves up to a constant speed.
If I try to use "setSpeed" and "runSpeed", the load on my motor has too much inertia. I have to spin it by hand to get it moving.
Is there anything in the AccelStepper library that will help me out, or do I need to write my own routine to achieve this acceleration?
Okay, I don’t see anything in the AccelStepper library to do this directly, so this is my workaround. If someone knows a better way or a library call that does this directly, post up.
Thanks.
// Accelerates up to MaxSpeed. Does this by setting a low initial speed,
// then increasing the speed a small amount every "interval" number of
// milliseconds.
#include <AccelStepper.h>
AccelStepper stepper; // Defaults to 4 pins on 2, 3, 4, 5
float maxSpeed = 250; // # of steps per second to speeed up to
unsigned long time;
unsigned long previousAccel = 0;
int interval = 100; // # of milliseconds between speed increases
void setup()
{
stepper.setMaxSpeed(maxSpeed);
stepper.setSpeed(10);
}
void loop()
{
while (stepper.speed() < maxSpeed) {
time = millis();
if (time > previousAccel + interval) {
previousAccel = time;
stepper.setSpeed(stepper.speed() + 2);
}
stepper.runSpeed();
}
stepper.setSpeed(maxSpeed);
stepper.runSpeed();
}
I am doing the same thing, 2 motors accelerating to speed and then running indefinitely. When I ran with one motor I was getting about 20rpm.Adding the second motor slowed it WAY down. Am I hitting the wall for processing speed?