Go Down

Topic: Absolute Position for Stepper Motors and linear axis (Read 5893 times) previous topic - next topic



I using a "direction / Step" Driver for a Steppermotor with an linear axis and i would like to define the axis with absolute positions numbers in order to simple call this numbers and move the "runner block" to this position.

lets say:

left end of the linearaxis:        0
right end of the linearaxis: 1000
middle of the linearaxis:      500

how to translate the "steps numbers" and "direction low/high" to

-go to absolute position: 300
-go to absolute position: 100
-go to absolute position: 150
-go to absolute position: 900
-go to absolute position: 990

any advice or someone can point me in the right direction ?

thanks, pe


You have to keep track of the current absolute position.  Subtract that from the destination position to get relative motion which can then be scaled to steps and direction.  If you loose power you will have to re-determine the absolute position, usually by running the slider until it hits a 'home' switch and calling that 0.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp


You might look into something called a "linear encoder":

I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.


thanks cr0sh and johnwasser,

@cr0sh: i would rather not use any encoders, the project would be then to expensive


- yes, there will be a end-switch which give me the initial position.

- loosing power will start a new initialization process and i make sure to not lose any steps from the motors.

- keeping track of the absolute postition is my problem. It would be very easy doing this in "Max/msp" but as a beginner in arduino i am mostliy struggeling with the left / right and counting in both ways postitive values. How difficult is this for a beginner ?

thanks pe

btw, my setup is:

LM Guide Actuator thk KR33
nema 23 steppers
arduino uno
pololu A4988 drivers


It's pretty simple:
Code: [Select]

unsigned long currentPosition;
void moveAbsolute(unsigned long position)
    if (position == currentPosition)
        return;  // Already there

    unsigned long steps;

    if (position > currentPosition)
        digitalWrite(directionPin, HIGH);
        steps = position - currentPosition);
        digitalWrite(directionPin, LOW);
        steps = currentPostion - position;
    currentPosition = position;
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp


- loosing power will start a new initialization process and i make sure to not lose any steps from the motors.

Something you're assuming is that:

1) When you tell the motor to step, that it will step (rotate a fraction)
2) That it will always step, whether or not it is under load
3) That when you tell it to stop (not step), the load on it won't cause the motor to rotate any further due to inertia

Now - maybe your motors are high-quality, very strong, and your load is lightweight (thus low inertia); if that is the case, then maybe you can run this whole thing "open loop" - but that still makes the assumption that the mass of the rotor won't cause the motor to mis-step, over-step, or under-step (there do exist so-called "coreless" stepper motors, which have very lightweight cores - but they aren't cheap).

This is the point of an encoder - so you can tell, with a certain level of precision, where exactly your motor shaft (or linear travel) is at any given point. What you need to think about is how you can build your own form of encoder that isn't as expensive as a "common" commercial unit. One possibility (it won't be super-accurate, but it might work well enough for your purposes) is to use a precision multi-turn potentiometer (5-10 turns), coupled to the system using a geared-down system (however you want to achieve this is up to you, but it would be prudent to use something fairly anti-backlash), so that the motion of the linear element corresponds to only a fraction of the total number of turns the potentiometer can resolve. Then just read the value using the ADC. That kind of a system would probably be the cheapest method (that, or something similar - for instance, you could substitute in a variable capacitor instead).
I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.


Given that your motor and driver are providing sufficient torque, there should be no need for an encoder.After all, stepper driven CNC machines are quite reliably driven open loop and will only lose steps if driven too fast. So, do the math to determine the torque needed to accelerate the load to the speed you wish to achieve and size your motor accordingly. This guide will assist you in this:http://www.geckodrive.com/ark-2/support.html. Another important aspect is to provide acceleration ramping in your code. A stepper cannot move a load from a dead stop without losing steps. Look at AccelStepper in the Arduino Playground.


I fully agree that an encoder is not needed when using steppers.
Indeed it is possible the step can not be made. However steppers have relatively high torque.
If you go to fast you may miss steps due to rotational delay.
I have made a setup where a laser was connected to a gear driven by a stepper. To test I had the laser shine about 15 meters far. I could reposition easily by simple step counting.
Note that once you go to microstepping the code is not easy at all.
Best regards
Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -


thanks for all that help.

agree, i running a cnc machine in openloop, no encoder needed. The pitch of spindels function further as a gear reduction.

thanks also to johnwasser, this helps a lot. Now i have to try to integrate this in my simple coding practice..

i will post my code + images from the project as soon it works (or ask for more help :)

great !

best, pe

Go Up