# Sorting algorithm with stepper motors

J
Thread Starter

#### Jim Butler

I’m doing a final year project which incorporates a Mitsubshi Fx-16MR plc controlling two FX-IPG blocks that control two stepper motors. The stepper motors control the X and Y axis of a pick and place rig. The rig is currently working with a pre-programmed set of movoments. It basically sorts a 3*3 array of three sets of three coloured discs placed in a certain order in this array. I’m now trying to implement a program that will be able to handle a random placement of these discs. The actual position of the discs will be inputed via a Mac 40 user interface. There turns out to be 280 possibilities of placing these discs randomly into the array, which of course means writing a different line of movements for each random placement would turn out to be very tedious. Thus I’m trying to implement a sorting algorithm. Anybody wish to help.
Regards
Jim

R

#### Rufus

I’m not quite clear as to what you’re saying here. From your description I envisioned a tic-tac-toe board (3 x 3 array) with say, 3 dimes, 3 pennies, and 3 nickels, placed on the tic-tac-toe board with one coin per spot. Is the analogy correct?
(with that model, I came up with 1680 combinations, not allowing for rotations or reflections of the array)
What is the end result required by your algorithm?

G

#### Guy H. Looney

I would normally handle this w/ a teach mode method. Set aside X & Y number of registers in the PLC. Manually jog the motors into place & visually confirm the locations. Trigger the PLC to record the motor positions (zeroing the counter before you start based on a home position). Once finished, implement some sort of For Next loop using variables to move through the data table. Each time through the loop a particular postion (based on the data table) would be called and moved to.
If that’s not possible, perhaps setting up a table w/ all the data points (manually as opposed to teaching) & then doing a For Next loop structure could be implemented.
Either method is fairly common. Let me know if you have other questions or want to discuss it further.
Thanks,

Guy H. Looney
Sales Engineer
Regan Controls, Inc.

J

#### Johan Bengtsson

I may not have understood the task correctly either but
i suppose it is picking the three different colors from
a special place for each color outside of the array
something like this:
&#61623; pick * place * place * place *
&#61623; red * 1:1 * 2:1 * 3:1 *
&#61623; pick * place * place * place *
&#61623; green * 1:2 * 2:2 * 3:2 *
&#61623; pick * place * place * place *
&#61623; blue * 1:3 * 2:3 * 3:3 *

If I have understood the problem correctly my simplest solution would be like:
1. “Select” place 1:1
2. Find out what color to get
3. Move to that “pick” position
4. Move to “home” position
5. Move to selected place position
6. More place positions left? if yes - “select” the next one and repeat from step 2.

This can be done in several different ways, but I suppose that is something you have to find out for yourself. The drawback and strength with this method is the “home” position dividing the movements into separate parts, one get part completely isolated from the place part. This will make more movements than really necesary but it is a simple approach.
btw. 1680 combinations (including mirrors etc.) sounds most correct to me.

Johan Bengtsson
P&L, the Academy of Automation
Box 252, S-281 23 H{ssleholm SWEDEN

G

#### Guy H. Looney

I think a generic loop is your best answer. The Mac 40 can choose the position via a register or variable & that choice can be put in a generic program. I’ll give you an example in a basic language format because I’m not sure what programming language you’re using.
LX X would be the number times through the loop
(use a variable from the Mac to determine the number of positions or
parts you are running or do an indefinite loop) A100 Acceleration of 100 in/sec/sec (or what ever scale factor you’re using)
AD100 Deceleration of 100 in/sec/sec (or what ever scale factor you’re using)
V1 Velocity of 1 in/sec (or what ever scale factor you’re using)
Wait(input 1 = 1) Wait until input 1 is turned on. Input 1 would be
from the Mac 40. It would tell the stepper card that the Mac 40
has selected the position to move to. D(Var1) Set the distance equal to the value in variable 1 (could use a register table)
GO Begin the move
LN End of loop. Begin the loop again.

This is just a basic structure. You could easily modify this for 2 axes.
I hope this helps.

Guy H. Looney
Sales Engineer

Regan Controls, Inc.

Similar threads