AccelStepper Question

Status
Not open for further replies.

vitormhenrique

Well-known member
Hello Guys,

I don't have any previous experience with stepper motors, just trying one little project and testing the AccelStepper library but i'm having a problem.

I'm trying to use positional based control on my stepper motor, but i'm not clear what the "relative position" actually mean, is it angle or something else?

I'm trying the following code, and expected the stepper motor to turn 180 degrees, stop, turn more 180 degrees and so on, but that is not what it is happening.

This is just a test code to understand the library.

The stepper motor is turning a little bit less than 180 every turn.

Code:
#include <AccelStepper.h>

// Define a stepper and the pins it will use
AccelStepper stepper(1,3,2);

void setup()
{  

  stepper.setMaxSpeed(600);
  stepper.setAcceleration(300);

}

void loop()

    stepper.moveTo(stepper.currentPosition()+180);
    stepper.runToPosition();
}
 
"Relative position" means it's relative to what it was. If you move a stepper to position 500 steps forward, turn it off, turn it back on, and rerun your program, it will move 500 more steps forward. There's nothing to remember it already moved 500 steps, so the 2nd movement is relative to the 2nd starting position even though from your perspective (absolute) it's moved 1000 steps. This might explain it better:

http://www.cnccookbook.com/CCMillCNCHomeSwitches.htm

For your second question: the library isn't moving your stepper motor by degrees; it's moving it discrete physical steps. You'll need to find out how many steps your particular motor does per revolution. My *guess* is that you have a 400 step per rotation motor[*] so when you're telling it to go 180 steps that's semi-close to 200 steps for a half revolution.

[*] Alternatively you might have a 200 step per rotation motor and your motor controller is configured for half steps.
 
Thanks @potatotron, I have a 200 step / rotation motor. And indeed the stepper driver was configured to use a half step!
Spoiler: My next project that I'm working on is a rubik's cube solver using a teensy! :)
 
Status
Not open for further replies.
Back
Top