Shop OBEX P1 Docs P2 Docs Learn Events
Three axis stepper positioning. — Parallax Forums

Three axis stepper positioning.

BTXBTX Posts: 674
edited 2007-01-09 15:31 in Propeller 1
Hi all.
This is my first code in spin, but for people that like to experiment with steppers could be fun.
This is three axis stepper system positioning (not for CNC fans), you only need to send by serial port 6 bytes
to let the "3 axis" get a new position.
Obviously the steppers will run at the same time, and stop each, according their number of steps to turn.
I was working with it, to get the best ramp possible, the test done was good, now let you try, and post some suggest
if you like.
I'm sure that the code is not good optimized,·but it works fine, best spin use is accepted·like suggest too.
I Hope it could be interesting and useful for somebody, in my own case, I will·replace 3 microcontrollers COP8, plus
an AT89C52, that actually do the same work, that it code can do with a PChip.
Like you can imagine it's a big goal for me, believe me, the COP8 code in assembler was terrible....
And now, with a simple spin code I do the same......I'm very very according with Propeller.
In the picture, you can see in the middle of it, the 3 COPS, and near of them, one of three AT89C52 to be replaced
by the Propeller.
In·another post, I'll try to upload an avi file, where you can see·a demo, of two axis positioning.

Regards.
Alberto.

Envio editado por (BTX) : 12/6/2006 12:24:25 PM GMT
472 x 455 - 32K

Comments

  • BTXBTX Posts: 674
    edited 2006-12-06 04:52
    Here's the file that I promess.

    Regards.
    Alberto.
  • OwenOwen Posts: 100
    edited 2007-01-07 18:21
    I'm having trouble comunicating to the 3 axis stepper driver written by Alberto, Would someone be able to describe how the serial data should be formatted to use this this 3axis stepper driver? i just dont understand spin well enugh yet to know from the code how to controll it from the serial side. any help is well appriciated

    Regards,
    Owen
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2007-01-07 19:35
    Its looks as if you send it 6 bytes in a row corresponding to:

    pulx
    puly
    pulz
    mulx
    muly
    mulz
    Dirx
    Diry
    Dirz

    The meanings of which are defined at the top of the program. Pulx is number of steps and mulx combines a step multiplier and the direction. Bit 1 seems to set the direction.

    Graham
  • BTXBTX Posts: 674
    edited 2007-01-07 20:44
    Owen

    In the top of the PaP_Turn_demo.spin say:

    {{··· Use:
    '····· pulx := Steps quantity X axis.
    '····· puly := Steps quantity Y axis.
    '····· pulz := Steps quantity Z axis.
    '····· mulx := Steps multiplier plus rotation sense X axis.·· '
    '····· muly := Steps multiplier plus rotation sense Y axis.·· '·· %BBBBBBC0 --- B => multiplier·· C => CW=1, CCW=0
    '····· mulz := Steps multiplier plus rotation sense Z axis.·· '
    }}

    I'll give you an example:
    For 200 pulses in x axis, 300 in y axis and 250 in z axis but with the direction inverted, you should send:

    pulx:= 200
    mulx:= 4

    puly:= 150
    muly:= 8

    pulz:= 250
    mulz:= 6

    Just I wrote in the demo, the mul factor is divided in the first 6 mSB digits for multiplier and the last two (or the first two LSB) for direction, but only one of them.
    Let me try another explanation:
    Mulx has 8 bits bit0 from bit 7, ok ?, so if bit1 = High· => that motor turn CW, then bit1 = low => motor turn CCW, and then bits 2 through 7·are the multiplier factor, so bit2 = high => multiplier=1, then bit3 = high => multiplier = 2 and so on.

    Let me write again:· mulx, muly, mulz· use:··%BBBBBBCx
    where BBBBBB 6 bits for multiplier, C is the bit for direction, and x dont care.

    Then to get it work, send by the computer, those 6 bytes correct, and you will see the three motors turning at the same time a different number of steps and direction. The demo works on 57600,8,N,1 serial port configuration, I tried it in the same demo board and has no problem. If you have Visual Basic it is so simple !!!


    It was made by this way, cause to maintain compatibility with my old design (That not used Propeller).
    You can change the code to have more multiplier range as you need, and a different way to have the sense rotation.

    Try learn spin. !!! it is not difficult, you will see that,·you could get nice things with this PChip.

    Regards.
    Alberto.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • OwenOwen Posts: 100
    edited 2007-01-09 14:48
    thank you Alberto this clarified most things for me.
    but I think now i'm a bit confused at how:

    repeat
    pulx := serial.rx
    puly := serial.rx
    pulz := serial.rx
    mulx := serial.rx
    mulx := serial.rx
    mulx := serial.rx

    works in the spin program, how does it see each byte seperatly for each variable?

    Also is there any way to use longs instead of bytes so i wouldn't need to use the multiplyer?

    thanks for the help,

    Owen
  • BTXBTX Posts: 674
    edited 2007-01-09 15:31
    Owen:
    I don't understand very well your question.

    "pulx := serial.rx " this receive by serial port, the value of pulx and store in it, then the anothers values are obtained by the same way.
    puly,pulz, etc.
    Then those values are passed to the cogs by Turn[noparse][[/noparse]0], Turn[noparse][[/noparse]1] and Turn[noparse][[/noparse]2].

    The repeat loop will try to get new values for a new position of the three axis, it will wait, for a valid data received·through the serial rutine.

    You can pass those values to the propeller by serial port, with a Stamp or a PC using some like this:

    Stamp example:

    ··· SEROUT 15,396,[noparse][[/noparse]pulx, puly, pulz, mulx, muly, mulz] data is sending by pin 15 at 9600 bps in 8 bit no parity TRUE for a BS2PX

    (This is only an example I don't know , how you want to send the data, and which hard you're using. Change the baudrate in my spin code if you want)

    About the use of longs ...Of course !! you can implement·it, and it could be more friendly to use, but try to modify my code.....
    Is was made by this way, to maintain compatibility with·my old hardware....
    I'have not a different version of this code to share. Let's try it is not difficult to do it in spin.
    You're wellcome.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Regards.

    Alberto.
Sign In or Register to comment.