Alright, so recently I've started using the AccelStepper library, which seems to very useful, but i can't for the life of me get a certain action to happen with my stepper motor. I want it to accelerate for a certain amount of steps/time, run at a constant speed for a certain amount of steps, and then decelerate and stop after another amount of steps.
Is there any way to code this? I am completely lost...
#include <AccelStepper.h>
//Define a stepper and the pins it will use
AccelStepper stepper(1, 9, 8);
void setup()
{
 stepper.setMaxSpeed(4000);
 stepper.setSpeed(1000);
 stepper.setAcceleration(500);
Â
}
void loop()
{
stepper.moveTo(5000);
stepper.runToPosition();
}
Sorry. I need any code that will do this really, I have no idea what to do....
The AccelStepper library will accelerate as needed/possible, run at a constant speed, and then decelerate as needed/possible. You don't have to do a thing, except set the acceleration rate and speed desired (which may not be possible, depending on the number of steps to be taken, the load on the stepper, and the current supplied to the stepper).
InfiniBro:
I want it to accelerate for a certain amount of steps/time, run at a constant speed for a certain amount of steps, and then decelerate and stop after another amount of steps.
I'm not sure that the AccelStepper library is designed to allow you to specify how many steps are used for acceleration or deceleration. AFAIK you can give it an acceleration/deceleration rate, a max speed and the total number of steps to move. It then works out how many steps out of that total are used in the acceleration and deceleration phases and the balance (if any) at max speed.
If the AccelStepper system is really not suitable, and as you are using a stepper driver that takes step and direction signals it would not be very difficult to write your own code without using the Accelstepper library. The second example in this Simple Stepper Code could be a starting point - though, as written, it is designed for constant speed.
Robin2:
I'm not sure that the AccelStepper library is designed to allow you to specify how many steps are used for acceleration or deceleration. AFAIK you can give it an acceleration/deceleration rate, a max speed and the total number of steps to move. It then works out how many steps out of that total are used in the acceleration and deceleration phases and the balance (if any) at max speed.
If the AccelStepper system is really not suitable, and as you are using a stepper driver that takes step and direction signals it would not be very difficult to write your own code without using the Accelstepper library. The second example in this Simple Stepper Code could be a starting point - though, as written, it is designed for constant speed.
Alright...hmm. See, my end goal is to have the stepper accelerate for a stated amount of steps, go at a fast constant velocity and then decelerate to a slow constant speed and then after another amount of steps, stop. The place where it decelerates would be the same every time but I would want to change where it stops. I can't think of a way to do this, though.
Yes, I've studied it, but it makes little sense to me, and I'm not sure how I would go about doing exactly what I want it. I'll have to see how this works...I'm assuming that a for loop or something like that could be used for acceleration for a said number of steps, perhaps?
InfiniBro:
'm assuming that a for loop or something like that could be used for acceleration for a said number of steps, perhaps?
That is one way and it will work if you don't mind not being able to do anything else until the FOR completes. Alternatively allow loop() to do the repetition and iterate through the number of steps using a variable to keep track of the count.
During the acceleration phase the value of millisBetweenSteps should gradually decrease.
Write some code and if it does not work post your code and we will try to help.