Machine Automation Program - need peer feedback...


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: Machine Automation Program - need peer feedback...

    Theres alot of jumping around, half your code is gosubs and returns. its confusing me. and then theres all these steps, i'm wondering if your trying to do a texas 2 step dance.. is there a reason your using loops to control speed? you could do the same thing using an adjustable pause at the end of your gosubs in main.
    Chris


    Any man who has accomplished anything in electronics at one time or another has said... " STOP! WAIT! NOOO! Dangit.... Oh Well, Time to start over..."

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    967


    Did you find this post helpful? Yes | No

    Default Re: Machine Automation Program - need peer feedback...

    Your coding style looks good to me. Clean and precise. To each his own

    If I had to code this, I would probably avoid the 'branch'es and use a 'select case' right inside the Left side / right side operations routines. Reason being, there is very little else that you're doing in the branches.

    Another thing you can consider is using a table to fire the stepper motors instead of using the step0,1,2,3 idea. In the table you could just load the 4 bits of the stepper which you need to load at every step. It will probably save you the select case and the branch too. I won't elaborate on the idea. You can figure it out yourself.

  3. #3
    Join Date
    Oct 2004
    Location
    New Hampshire
    Posts
    76


    Did you find this post helpful? Yes | No

    Default Re: Machine Automation Program - need peer feedback...

    Hi Jerson,

    Thank you for your feedback.

    I don't have enough experience to know why I would use 'select case' over 'branch'. Is there a speed gain? Keep in mind my example is somewhat bare bones. I really appreciate your comments. Could you elaborate on the table to fire the stepper motors? I currently output pulses to a stepper controller off-board. I send pulse and direction only.

    Thank you,

    Ross
    Never enough knowledge to be called intelligent but just enough knowledge to be considered dangerous!

    I like that! :-)

  4. #4
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    967


    Did you find this post helpful? Yes | No

    Default Re: Machine Automation Program - need peer feedback...

    Hi Ross

    I suggested a 'select case' simply because there is not much you are doing after 'branch'ing to the subroutine. You seem to be just incrementing the step variable and going back. That would be very wasteful speedwise because a branch usually takes longer to execute. I am not sure if a select case saves time; haven't checked.

    For the table approach, I usually keep the 4 bit stepper values in a table. These 4 bits are jammed to a port that drive the stepper coils. So, a typical step table would have values like
    HalfStep=[0b0001,0b0011,0b0010,0b0110,0b0100,0b1100,0b1000,0 b1001];

    Sorry, I do not have a PBP example at hand, so, I have given you a quick and easy 'C' table. At each step, you load the next value from the table and jam it out to the port. This table shows values to drive a stepper motor in a half step sequence. For full stepping, you just use every alternate value.

    Hope this helps

    Jerson

    PS: have you read through this thread? It might have something useful to you
    http://www.picbasic.co.uk/forum/showthread.php?t=101
    Last edited by Jerson; - 19th April 2013 at 16:05.

  5. #5
    Join Date
    Oct 2004
    Location
    New Hampshire
    Posts
    76


    Did you find this post helpful? Yes | No

    Default Re: Machine Automation Program - need peer feedback...

    Thanks again Jerson,

    I thought that's what you meant by a stepper coil table... but I have no need for that.

    The steps that I refer to in the 'BRANCH' command, are process steps in my machine... such as the following example: Step_1... raise sealing bar, Step_2... turn on suction cup vacuum, Step_3... turn Y stepper motor 1200 pulses CCW, Step_4... turn X stepper motor 3400 steps CW... etc. Keep in mind that the pulses on Step_3 are sent one pulse at a time per loop.

    I've re-written some code to illustrate. See below: (this differs from my original posted code)

    In step 2, I set variable i to the value 100 and increment the step to LStep_3. Then I loop back to MAIN.

    When I next BRANCH, I will wind up at LStep_4 and send one pulse to the the stepper controller (off board).
    Since the WHILE statement is true, the program decrements i by one and returns (to MAIN). It will continue to branch to
    LStep_4 sending one pulse at a time until the WHILE statement is no longer true, then set left_side_step = 5 and return to MAIN.

    Note: I haven't shown any acceleration or deceleration in this code. That bit is complicated. :-P


    Code:
    LStep_2:
    
            'do these things
            left_side_step = 3
            i = 100             'set variable i for the number of pulses in step
            Return              'three. (placed here for readability)
            
    LStep_3:
    
            pulsout portb.7,4   'send out one pulse to stepper controller
            while i <> 0          'while statement is true, decrement i by one and
            i = i -1                'return to main (loop) Continue sending one pulse
            return                 'each time the program loops here until the 'while'
            wend                  'statement is false... then increment 'left_side_step
            left_side_step = 4  'to LStep_4
            return
    Thank you for taking the time to look at this with me!

    Ross
    Never enough knowledge to be called intelligent but just enough knowledge to be considered dangerous!

    I like that! :-)

  6. #6
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    967


    Did you find this post helpful? Yes | No

    Default Re: Machine Automation Program - need peer feedback...

    Well, now that makes sense and seems justified.

  7. #7
    Join Date
    Oct 2004
    Location
    New Hampshire
    Posts
    76


    Did you find this post helpful? Yes | No

    Default Re: Machine Automation Program - need peer feedback...

    Quote Originally Posted by wdmagic View Post
    Theres alot of jumping around, half your code is gosubs and returns. its confusing me. and then theres all these steps, i'm wondering if your trying to do a texas 2 step dance.. is there a reason your using loops to control speed? you could do the same thing using an adjustable pause at the end of your gosubs in main.
    The point of this code example is to show how I am accomplishing multiple movements at the same time. Quite frankly I don't know another way and would like to know if others are doing it differently. With this code I can control multiple steppers at the same time. (or at least they will all look like they are moving at the same time).

    I am constantly looping through Main: On each loop I update inputs and outputs. I also operate things going on on the left and right sides of the machine. The left side could be on step seven, the right could be on step two. With the way I have organized it, it is very easy to add steps and move from one to another by simply adding additions to the branch statements.

    Conditions are built in to the "Left_Side_Operation" and "Right_Side_Operation" routines. They allow or disallow access to the Branch statements and subsequently to the "steps".

    One important objective was to maintain a high loop speed. When it came time to send pulses to stepper motors I didn't want them to crawl along.

    Thank you for your feedback.

    Ross
    Never enough knowledge to be called intelligent but just enough knowledge to be considered dangerous!

    I like that! :-)

Similar Threads

  1. Insteon Home Automation Software Development Kit
    By Stuartk in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 23rd November 2013, 17:52
  2. Replies: 3
    Last Post: - 26th November 2012, 11:20
  3. Automation project need help
    By microcnc05 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 5th January 2010, 03:17
  4. pic to pic to pic as peer to peer to peer
    By Geezer in forum General
    Replies: 1
    Last Post: - 5th September 2008, 06:53
  5. Replies: 8
    Last Post: - 8th May 2007, 11:15

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts