Machsupport Forum

Mach Discussion => General Mach Discussion => Topic started by: SailFl on April 04, 2010, 08:24:13 AM

Title: Help with code problem
Post by: SailFl on April 04, 2010, 08:24:13 AM
The code I have included is part of X & Y Zero.

When I use the debugger and step through the code, Dro(0) get set to zero.  When I run the code, it does not get set to zero.  I have tried Call SetDro and Code....

What am I doing wrong.
Thanks

Code: [Select]
Rem
Rem  Test Code For X And Y Zero routine
Rem 

XCurrent = GetDro(0) 'Get current X position
YCurrent = GetDro(1) 'Get current Y position
ZCurrent = GetDro(2) 'Get current Z position
FeedRateCurrent = GetOEMDro(818) 'Get the current Feed Rate
NewFeedRate = 10 'Set Feed Rate for macro


    Call SetOEMDro(818, NewFeedRate)
   

    Code "(Zero X and Y Macro Running)"

    Rem Find the X negative
   
    XNew = XCurrent - 2
    Code "G31 X" &XNew
    While IsMoving()
    Wend
    XPos1 = GetVar(2000)
   
    Code "G0 X" &XCurrent
   
    Rem Find the X positive
   
    XNew = XCurrent + 2
    Code "G31 X" &XNew
    While IsMoving()
    Wend
    XPos2 = GetVar(2000)
   
    XCenter = (XPos1 + XPos2)/2
    Code "G0 X" &XCenter
 
    Code SetDro(0,0)
Title: Re: Help with code problem
Post by: SailFl on April 04, 2010, 11:08:22 AM
The last statement, "Code SetDro(0,0) is not setting X to zero.

Does that help?
Title: Re: Help with code problem
Post by: ger21 on April 04, 2010, 11:33:09 AM
Instead of

Code SetDro(0,0)

Try

Call SetOEMDro(0,0)
Title: Re: Help with code problem
Post by: SailFl on April 04, 2010, 12:18:48 PM
Greg,

Thanks for the suggestion but that did not work.
Title: Re: Help with code problem
Post by: Tweakie.CNC on April 04, 2010, 01:34:32 PM
It was almost right.
Try:-

Call SetDRO(0,0)

Tweakie.
Title: Re: Help with code problem
Post by: ger21 on April 04, 2010, 01:35:51 PM
How about

Call SetOEMDro (800,0)
Title: Re: Help with code problem
Post by: SailFl on April 04, 2010, 02:02:22 PM
Greg,

I found that also, the 800 number.  When I setup through the code it works and the X gets set to zero but when I run the macro it does not get set to zero.  I have even put a pause to give it time to update but that does not help either.

SetDro does the same thing.

Title: Re: Help with code problem
Post by: Tweakie.CNC on April 04, 2010, 02:27:36 PM
You need to pause the macro to give Mach time to catch up.

Try this:-

While IsMoving()   
    Wend
Call SetDRO(0,0)


Tweakie.
Title: Re: Help with code problem
Post by: ger21 on April 04, 2010, 02:38:10 PM
And it's Gerry, btw. :)
Title: Re: Help with code problem
Post by: SailFl on April 04, 2010, 03:10:37 PM
Gerry,

I should know better sorry about your name.

I will add a while move and see if that helps.

Thanks
Nils
Title: Re: Help with code problem
Post by: SailFl on April 04, 2010, 06:27:42 PM
Gerry

Adding the While Moving fixed my problem.  Thanks for the suggestion.
Title: Re: Help with code problem
Post by: Tweakie.CNC on April 05, 2010, 02:12:15 AM
Glad you got it fixed Nathan.  ;D

Tweakie.