So...
You have a stepper motor that drives a screw which moves a "head" between two positions "TOP" and "BOTTOM".
Position feed-back is developed through counting pulses.
When the counter equals the preset 1 its in desired pos 1 and the same for 2.
Here's what I think the program should look like... sorta...
First... I should expect that the "HEAD" goes through a "Homing" Routine at Start-Up.
"HOME" should be a position between the "TOP" Position and the Physical Limit of the Upward travel.
Assuming that the Home Position is at a point higher than TOP (AND below the Physical Stop!), and that you have something (Limit Switch, Photo-Eye...) to indicate "AT HOME", the motor turns in the appropriate direction to bring the Head to Home.
I've designed a few of these Homing Routines where the subject (using a 4000 Count/Rev Encoder) moves to HOME at high speed. When the "AT HOME" Sensor goes OFF (Fail-Safe), the drive stops, using the built-in, or programmed, Decel Rate.
When it has stopped, I reverse the direction and move off of the "AT HOME" Sensor at SLOW speed. When the "AT HOME" Sensor goes ON, the drive stops, using the built-in (or, programmed) Decel Rate.
Then, depending on how precise I need to be, I use a slow/slower/slowest speed to approach the "AT HOME" Sensor.
As soon as the "AT HOME" Sensor goes OFF again, the encoder (counter) is Zero'd Out - This is "HOME". The motor is still moving but stopping at the built-in (or, programed) Decel Rate.
HOME = 0
TOP = W
NEAR TOP = X
NEAR BOTTOM = Y
BOTTOM = Z
GRAB LIMIT = Z + ?
Now, knowing where the Head is, the program and drive send the motor, at high speed, to the "NEAR TOP" Position - based on counts.
Then the program and drive send the motor to the TOP Position at SLOW Speed. When the count indicates "AT TOP", the drive and motor stops.
Now, assuming a cycle consists of the following operations...
- "Go to Bottom"
- "Grab Part"
- "Go to Top"
- "Go to Drop"
- "Drop Part"
- "Go to Pick-Up"
IF "Ready for Next Part" and "Part Ready"... (Begin cycle)
(Use Set, Latch, or a latching rung, whatever...)
While "Do Cycle"... (this spans the entire section of code for the cycle)
IF "Do Cycle and NOT "In Cycle"
- Set "In Cycle"
- Set "Go to Bottom"
IF "Go to Bottom" and NEAR TOP, Drive-1 down at LOW SPEED.
IF "Go to Bottom" and NOT NEAR TOP and NOT NEAR BOTTOM, Drive-1 down at HIGH SPEED.
IF "Go to Bottom" and NEAR BOTTOM and NOT BOTTOM, Drive-1 down at LOW SPEED.
IF "Go to Bottom" and BOTTOM, stop Drive-1.
IF "Go to Bottom" and BOTTOM and Drive-1 is Stopped,
- Reset "Go to BOTTOM"
- Set "Grab Part" (Turn ON Vacuum?)
While NOT "GOT PART"("GOT PART" = Vacuum Switch is ON)...
While NOT GRAB LIMIT...
IF "Grab Part", Drive-1 down LOW SPEED.
IF "Grab Part" and "GOT PART",
- Reset "Grab Part"
- Set "Go to Top"
IF "Go to Top" and NEAR BOTTOM, Drive-1 up at LOW SPEED.
IF "Go to Top" and NOT NEAR BOTTOM and NOT NEAR TOP, Drive-1 up at HIGH SPEED.
IF "Go to Top" and NEAR TOP and NOT TOP, Drive-1 up at LOW SPEED.
IF "Go to Top" and TOP, stop Drive-1.
IF "Go to Top" and TOP and Drive-1 is Stopped,
- Reset "Go to TOP"
- Set "Go to Drop"
IF "Go to Drop" and NEAR PICK-UP, Drive-2 Counter-Clock-wise at LOW SPEED.
IF "Go to Drop" and NOT NEAR PICK-UP and NOT NEAR DROP, Drive-2 Counter-Clock-wise at HIGH SPEED.
IF "Go to Drop" and NEAR DROP and NOT DROP, Drive-2 Counter-Clock-wise at LOW SPEED.
IF "Go to Drop" and DROP, stop Drive-2.
IF "Go to Drop" and DROP and Drive-2 is Stopped,
- Reset "Go to Drop"
- Set "Drop Part" (Turn Vacuum OFF)
IF "Drop Part" and NOT GOT PART (Vacuum Switch is OFF)...
- Reset "Drop Part"
- Set "Go to Pick-Up"
IF "Go to Pick-Up" and NEAR DROP, Drive-2 Clock-wise at LOW SPEED.
IF "Go to Pick-Up" and NOT NEAR DROP and NOT NEAR PICK-UP, Drive-2 Clock-wise at HIGH SPEED.
IF "Go to Pick-Up" and NEAR PICK-UP and NOT PICK-UP, Drive-2 Clock-wise at LOW SPEED.
IF "Go to Pick-Up" and PICK-UP, stop Drive-2.
IF "Go to Pick-Up" and PICK-UP and Drive-2 is Stopped,
- Reset "Go to Pick-Up"
- Reset "In Cycle"
- Set "Ready for Next Part"
The point of that whole thing is to illustrate a way to reduce the loading on your drives. As the Head gets NEAR to a target, have the Drive go to a slower speed.
You can define the "NEAR Position" and "AT Position" values in your code.
That listing is written in "C"-code fashion, but it translates very easily into ladder.