Machsupport Forum

Mach Discussion => VB and the development of wizards => Topic started by: TPS on August 31, 2014, 10:18:48 AM

Title: homing macro and Ismoving
Post by: TPS on August 31, 2014, 10:18:48 AM
Hello together,
first of all excuse my bad english.

after hours of searching i will post my problem here.

i have written a small macro for auto homing and clearing home limit swtiches if
necessary.

here the code:
Code: [Select]
Sub Main()
' -------------------------------------------------------------------------------
' TPS 30.08.2014 
' Referenzschalter freifahren und anschliessend Referenzieren
' -------------------------------------------------------------------------------
'beim Laden des Files Abbrechen
If IsLoading() Then
    GoTo Ende
End If

Message ("Automatische Referenzfahrt")

'Referenz INI Z freifahren
If GetOEMLED(836) Then
Code "G91" ' Inkremental Modus
Code "G0 Z-50" ' Freifahren
WaitMoving
Code "G90" ' Absolut Modus
End If

'Z referenzieren
DoButton(24)   'Zuerst Z
WaitMoving

'Referenz INI X freifahren
If GetOEMLED(830) Then
Code "G91" ' Inkremental Modus
Code "G0 X-50" ' Freifahren
WaitMoving
Code "G90" ' Absolut Modus
End If

'Referenz INI Y freifahren
If GetOEMLED(833) Then
Code "G91" ' Inkremental Modus
Code "G0 Y-50" ' Freifahren
WaitMoving
Code "G90" ' Absolut Modus
End If

'X und Y referenzieren
RefCombination(3) ' dann X und Y
WaitMoving
Code "G54" 'Koordinatenverschiebung ein
Sleep(200) 'warten
    Message (" ") 'Stauszeile löschen
Exit Sub
 '--------------------------------------------------------------------------------

Ende:
 
 Message ("Automatisches Referenzieren Abgebrochen")
   
End Sub   

'Funktion zum warten bis Antrieb steht
Function WaitMoving()
Sleep(200)
While IsMoving()
Sleep(200)
Wend
End Function 


sorry for the german comments.

the problem ist that the macro hangs in about 1 of 50 tryes
at the line

   While IsMoving()

line. if i press the stop button
i get the message:

internal error at line ..


i have no idea what i am doing wrong.

Thanks Thomas
Title: Re: homing macro and Ismoving
Post by: ger21 on August 31, 2014, 10:30:04 AM
Try removing the Sleep(200)'s from the WaitMoving function.

All you need is :

While IsMoving()
Wend
Title: Re: homing macro and Ismoving
Post by: TPS on August 31, 2014, 01:25:26 PM
Hello Gerry,

tryed this already, but i figured out
that without the sleep it does not
wait after the

DoButton(24)

for z-reference.

Thanks Thomas
Title: Re: homing macro and Ismoving
Post by: TPS on September 02, 2014, 02:14:15 AM
Hello,

back again after additional testing.

i tryed

Code: [Select]
Sleep(200)
While IsMoving()
Wend

crashed at line While IsMoving() with internal error

i tryed

Code: [Select]
While IsMoving()
Wend

did not stop after the DoButton(24)

i tryed

Code: [Select]
Sleep(200)
While Not IsStopped()
Wend

crashed allways at line While Not IsStopped() with internal error


maybe i am searching at the wrong side of the road, because i am
using a csmio/ip motion controller and do not know whether this
function call (IsMoving()) is only handled by Mach Software or
also by the plugin.

possibly i have to talk to the csmio/ip people.

Thanks Thomas





Title: Re: homing macro and Ismoving
Post by: Chaoticone on September 02, 2014, 04:16:36 AM
I think you can change your home off distance in homing and limits config. to clear the switches by any amount you wish. I think you will continue to have problems as long as you use the while IsMoving() in the reference all button while using CSLabs. If you do ask CSLabs I would be interested in hearing their explanation.

Brett
Title: Re: homing macro and Ismoving
Post by: TPS on September 02, 2014, 04:26:50 AM
Hello Brett,

i emailed CSlabs the problem.
will get back to you with the response.

Thomas
Title: Re: homing macro and Ismoving
Post by: TPS on September 02, 2014, 03:12:01 PM
ok, small update,

i am sure it is not the Ismoving() thing.

replaced it with:

While GetOEMled(999)
Wend

should be the same i thought.
but i am geting no internal error anymore, it just hangs.

for the moment i am out off any ideas.

looks like i have to to accept, that it is not
working 'sometimes'.
with no idea what i can do if it is not working (automaticly)

just frustraiting.

Regards Thomas
Title: Re: homing macro and Ismoving
Post by: Chaoticone on September 02, 2014, 03:22:14 PM
I had the same idea and tried the same with the same results. I had to just do it another way. Really, the way the CSLabs handles homing I figured out there was no need for the While IsMoving() in my script. I am acustomed to haveing to add a move away from the switch in my homing script. CSLabs will do this for you without altering the script. Just set your home off distance in Mach.

Brett
Title: Re: homing macro and Ismoving
Post by: TPS on September 03, 2014, 02:52:12 AM
Hello Brett,

i thought this HOME OFF DISTANCE is the distance
witch is driven after the homing, i am gona test this today.

what i want to do with my script is to clear the homing limits
before i start a homing, because it is not homing when its
on an limit.

Thomas
Title: Re: homing macro and Ismoving
Post by: TPS on September 03, 2014, 04:43:21 AM
Hello Brett,

her the answer for CSLab

Quote
Dear sir,
Homing is an autonomous function of CSMIO/IP motion controllers and Mach3 may have a problem with IsMoving() function.

To control if homing is finished you can use LED diodes  GetOemLed(807)  / GetOemLed(808) / GetOemLed(809).

DoButton( 22 )
Sleep(200)
While GetOemLed(807) = true
    Sleep(50)
    If GetOemLed(800) Then
        Sleep(500)
        Message"Error"
        End
    End If

Wend
Message"Axis referenced"

 The way shown above works perfect

Regards

Wojtek Trawicki

Thomas
Title: Re: homing macro and Ismoving
Post by: Chaoticone on September 03, 2014, 07:30:24 AM

what i want to do with my script is to clear the homing limits
before i start a homing, because it is not homing when its
on an limit.

Thomas

I think it will but would have to test to be certain.......... the CS-Labs is pretty clever. You will have to reset any time a limit is tripped. Drive on to a limit that doubles as a home switch, hit reset then ref all home. I think it will work without having to manually jog off the switch. I think if you are on a limit switch that doubles as a home when homing is requested it will move off the switch until it changes states and the homing for that axis is then complete........... unless you set a home off distance. If you do then the axis will move to the home off distance once the switch changes states.

Thanks for sharing the info from CS-Labs.
Title: Re: homing macro and Ismoving
Post by: TPS on September 04, 2014, 02:51:56 AM
I think it will but would have to test to be certain..........

no its doing just nothing. only a message is created, that the limit switch is active.
i think CS-labs addon is not the problem, i think Mach is not notifying the addon
to do a reference because its checking the limit switch.

thats what i think, dont know for sure.

i am still in contact with CS-Labs, because with the new code the macros
still hangs up, but now without any internal error.

keep you informed.

Thomas
Title: Re: homing macro and Ismoving
Post by: Chaoticone on September 04, 2014, 07:51:04 AM
I will try to test this ASAP but it will likely be the weekend before I get to. Are you sure you are not dealing with bouncy switches or EMF? Have you tried to enter a home off distance for all axis of .100 (inches)(+ or - depending on homing direction) and tried it? Remember (with a switch doubling as a home and limit) as soon as it comes off the switch in the homing routine the very next time it sees that input turn on, be it 10 minutes or 10ms later, it should throw a LS fault.

Brett
Title: Re: homing macro and Ismoving
Post by: TPS on September 05, 2014, 02:08:38 AM
Hello Brett,

small update

its clearing the home limts itself if in ->General Config the option ->Home Sw. Safety is disabled.
so i was able to delete the code for clearing the switches. but still the problem that the macro
hangs sometimes.

Home Off distance works after the homing to drive a declared distance after the homing was
finished.

Thomas
Title: Re: homing macro and Ismoving
Post by: Chaoticone on September 05, 2014, 06:00:26 AM
What macro hangs? The ref all home? Post your code and I'll have a look.

Brett
Title: Re: homing macro and Ismoving
Post by: TPS on September 05, 2014, 07:04:10 AM
Hello Brett,

here the macro witch hangs:

Code: [Select]
Sub Main()
' -------------------------------------------------------------------------------
' TPS 04.09.2014 
' zuerst Z dann X/Y Referenzieren
' -------------------------------------------------------------------------------
'beim Laden des Files Abbrechen
If IsLoading() Then
    GoTo Ende
End If

Message ("Automatische Referenzfahrt")

    'Z referenzieren
    Message ("Z-Achse referenzieren")
RefCombination(4)   'Zuerst Z
    Sleep(200)
    While GetOemLed(809) = true
        Sleep(50)
        If GetOemLed(800) Then
            Sleep(500)
            Message"Fehler Referenzfahrt Z"
            End
        End If
    Wend
   
    'X und Y referenzieren
    Message ("X/Y-Achse referenzieren")
RefCombination(3) ' dann X und Y
    Sleep(200)
    While ((GetOemLed(807) = true) or (GetOemLed(808) = true))
        Sleep(50)
        If GetOemLed(800) Then
            Sleep(500)
            Message"Fehler Referenzfahrt X/Y"
            End
        End If
    Wend

Code "G54" 'Koordinatenverschiebung ein
Sleep(200) 'warten
    Message (" ") 'Stauszeile löschen
Exit Sub
 '--------------------------------------------------------------------------------

Ende:
 
 Message ("Automatisches Referenzieren Abgebrochen")
   
End Sub   
Thomas
Title: Re: homing macro and Ismoving
Post by: Chaoticone on September 05, 2014, 09:51:57 AM
Thomas, I do not understand why you are checking to see if the machine is reset or referenced. It should not do anything if in a reset condition and will already have the message in the status bar, no need to check or set that. If I wanted to reference the machine, I would want it to reference no matter if it thought it had been already or not so no need to check that either IMO. Maybe I am missing something but I think the code below would serve you well.

Code: [Select]
DoButton( 24 )
DoButton( 23 )
DoButton( 22 )
Title: Re: homing macro and Ismoving
Post by: TPS on September 06, 2014, 03:12:42 AM
Brett,

this macro is only a part of the final macro.

what i want at the end is

home Z
depending on my setup i only can check after homing z whether there is a tool loaded or not

if tool loaded
- home Y
- if Y is finshed home X, possibilty of crash

if no tool loaded
- home x/y together to save time

the code with the check of reset and reference via GetOemLed was the
workaround CS-Labs prevered, because IsMoving() is not stable.

maybe i am not seeing the forrest depending on all the trees.

Thomas
Title: Re: homing macro and Ismoving
Post by: Chaoticone on September 06, 2014, 05:23:41 AM
The code I posted earlier will home the Z, then the Y, then the X. They will not work if in a reset. They finish homing an axis before homing the next. The only thing it will not do is home the X and Y together if a tool is not loaded. Will it be a big deal if it does not home the X and Y at the same time if no tool is loaded? What percentage of times when you reference the machine will it have a tool in the spindle? Surely it will only take a few extra seconds to home them independently? How often do you plan to reference the machine? Most only reference after power is lost or if reset has been hit while in motion. To err on the side of caution I home anytime a reset has been requested. If you are needing to reference more often than that I think you have bigger problems to be addressing before the reference script (just my opinion). From what I have seen with the CSLabs, the reference script is pretty flaky if anything else is in your reference script. I would keep it as lean as possible. Try the code below and see how you like it.

Brett
Title: Re: homing macro and Ismoving
Post by: TPS on September 07, 2014, 03:09:25 AM
Brett,

at the end this machine will be used in prof. conditions for drilling,tapping and labeling
for mounting plates for elecrical cabinets.

the normal work will be, load part, load programm hit start.
therefore a homing will be done at the beginning of every program to make sure
to start with the same conditions.

the machine will be operated of non CNC spezialists so have to create a easy to use
software. i have choosen Mach3/CSLabs for controlling the machine because
- its cheap
- its easy to use
- and on the main point with the screenset's, scripts and all the other open
functionality it gives me all the possibilities to create a package witch is exactly
what i need for this machine.

therefore i have to create test scenarios to make sure that all the particular
functions are working propperly.

i have also tested the homing by using dobutton(24) dobutton(23) and dobutton(22).

it ended up in a Error found Art Code 3336.
i was not able to find a list, witch discribes what this code means.

as long i am not not able to get this basic functionality working lets say up to 99%
stable it makes no sense to test further functions.

Thomas
 
Title: Re: homing macro and Ismoving
Post by: Chaoticone on September 07, 2014, 08:32:59 AM
Thomas, I will see if I can find any details about Art Code 3336 and if I do I will post my findings. Until then let me tell you that any Art Code error I have ever seen was generated by one of three things. A bad macro, a bad plugin or bad Gcode. I recommend you set up a new profile with all things being default. The screen, the ref. all home script (which is basically the code I recommended earlier), everything. The only plugin you should have installed is the CS Labs. Make sure you can operate the machine without getting the error and start adding your custom bits in one at the time and test to see what it is that is causing the error message.

I do not think you are going to be able to initially reference the machine with much success any other way than having the operator click a reference all button. My experience with the CSLabs tells me the script in that button will have to be very clean and cannot contain any While IsMoving() loops for sure. I also tried using LED 999 and countless other ways. The only thing that made it stable and eliminated all sorts of weirdness is the code I posted earlier. I can understand sending the machine to a set position at the beginning or end of each program, that I understand. This is usually done by commanding those coordinates or with a G28, G30, or G28.1 in the G code. I have not tested these g codes with the CSLabs because if this machine gets out of position (following error is too great) the servo drives will throw a fault which will force the operator to reference the machine after resetting the fault. This eliminates the need to reference the machine before each cycle.

Mach and CSLabs are very capable but they (or any other controller or hardware) are only going to work the way they are hard coded to. Our job as machine builders is to get what we want without asking the controller or hardware to do things they cannot. This often means we have to rethink the way we are doing things. But, that is the best part about being the machine builder, we have that option. Code does not, it can only work as it is written to. We have to be creative enough to stay within those bounds and still get what we want.

Brett
Title: Re: homing macro and Ismoving
Post by: TPS on September 07, 2014, 10:50:16 AM
Brett,

i think i have to wait now, what the CSLab people figure out.
i have send them all the results off my testing.

let's see whats gona happen.

I will be offline until end of this week.

Thomas
Title: Re: homing macro and Ismoving
Post by: TPS on September 16, 2014, 03:12:47 AM
hello,

i'm back. this is the final macro, witch was working in my test scenario for more then
two hours without any stop. more then 4 times longer then any version before.

Code: [Select]
Sub Main()
' -------------------------------------------------------------------------------
' TPS 03.09.2014  
' Referenzschalter freifahren und anschliessend Referenzieren
' neue Version mit Benutzung von OEM Led's
' -------------------------------------------------------------------------------
'beim Laden des Files Abbrechen
If IsLoading() Then
    GoTo Ende
End If

'Geladenes Werkzeug lesen--------------------------------------------------------
AktWerkzeug = GetOEMDRO(1000)
'--------------------------------------------------------------------------------
If AktWerkzeug <> 0 Then
MsGBox "Referenzfahr mit geladenem Werkzeug nicht möglich. Bitte manuell entfernen."
        GoTo Ende
End If    
'--------------------------------------------------------------------------------

Message ("Automatische Referenzfahrt")

'Z referenzieren
Message ("Z-Achse referenzieren")
'RefCombination(4)   'Zuerst Z
DoOemButton(1024) 'Ref Z
Sleep(500)
While GetOemLed(809) = true
   Sleep(200)
   If GetOemLed(800) Then
       Sleep(500)
       Message"Fehler Referenzfahrt Z"
       End
   End If
Wend

'X und Y referenzieren
Message ("X/Y-Achse referenzieren")
'RefCombination(3) ' dann X und Y
DoOemButton(1023) 'Ref Y
DoOemButton(1022) 'Ref X
Sleep(500)
While ((GetOemLed(807) = true) Or (GetOemLed(808) = true))
   Sleep(50)
   If GetOemLed(800) Then
       Sleep(500)
       Message"Fehler Referenzfahrt X/Y"
       End
   End If
Wend

Code "G54" 'Koordinatenverschiebung ein
Sleep(500) 'warten
Message (" ") 'Stauszeile löschen
Exit Sub
 '--------------------------------------------------------------------------------

Ende:
 
 Message ("Automatisches Referenzieren Abgebrochen")
    
End Sub      


dont ask me about the difference between DoButton(22) and DoOEMbutton(1022),
but it seems to work.
Thomas