Machsupport Forum
Mach Discussion => General Mach Discussion => Topic started by: Tecmaqcnc on March 19, 2025, 03:44:42 PM
-
I need to create a macro or script to manage the raising and lowering of two pressure rollers of the part against the machine bed.
I need the front roller to deactivate (raise) by activating an output when it is 80mm or less from the edge of the geometry at the origin in Y, and to raise again when it exceeds the 80mm Y dimension.
The rear roller needs to raise when it is 80mm or less from the maximum Y value in the Gcode, and to lower again when it is outside this range.
Could you help me?
It would be something like a variable or something like that.
I've seen that this data can be used from Mach:
MaxY – Get maximum Y extent for current G-code file
SetParam("YMachine", Axis position)
The variables would be something like this, but I don't know if Mach3 works this way...
MaxY=>MaxY-80, DeactivateSignal(OUTPUT3) ' Deactivate rear piston lowering
MaxY=<MaxY-80, ActivateSignal(OUTPUT3) ' Activate rear piston lowering
YMachine=>YMachine-80, DeactivateSignal(OUTPUT2) ' Deactivate front piston lowering
YMachine=>YMachine+80, ActivateSignal(OUTPUT2) ' Activate front piston lowering
Necesito crear una macro o script, para gestionar la subida y bajada de dos rodillos de presion de la pieza contra la bancada maquina.
El rodillo delantero, necesito que desactive (suba) activando una salida cuando este en Y a 80mm o menos del filo de la geometria en el origen y que vuelva a subir cuando se supere la cota 80mm en Y.
El rodillo trasero necesita que suba cuando este a 80mm o menos del Y maximo del Gcode, y que vuelva a bajar cuando este fuera de este rango.
Podriais ayudarme?
Seria algo como una variable o algo asi.
He visto que se pueden usar estos datos desde mach:
MaxY – Get maximum Y extent for current G-code file
SetParam(“YMachine”, Axis position)
Las variables serian algo asi, pero nose si mach3 trabaja de esta forma.....
MaxY=>MaxY-80, DeactivateSignal(OUTPUT3) ‘ Desactivar bajada piston trasero
MaxY=<MaxY-80,ActivateSignal(OUTPUT3) ‘ Activar bajada piston trasero
YMachine=>YMachine-80, DeactivateSignal(OUTPUT2) ‘ Desactivar bajada piston delantero
YMachine=>YMachine+80,ActivateSignal(OUTPUT2) ‘ Activar bajada piston delantero
-
something like this should work:
'Get the actual values
ActY = GetOEMDro(1)
MinYCoord = GetOEMDro(5)
MaxYCoord = GetOEMDro(11)
'front lowering
If ActY <= (MinYCoord+80) Then ActivateSignal(OUTPUT2)
'front raising
If ActY > (MinYCoord+80) Then DeActivateSignal(OUTPUT2)
'rear lowering
If ActY <= (MaxYCoord-80) Then ActivateSignal(OUTPUT3)
'front raising
If ActY > (MaxYCoord-80) Then DeActivateSignal(OUTPUT3)
if you put it in macropump.M1s it will run cyclic.
not tested just written down
-
Thanks a lot, mate, I'll try it!!
Have a great weekend!
-
Hi, I uploaded the programming to the macropump today, but it didn't work.
The outputs I used were always active; they wouldn't deactivate.
The macropump already had a subroutine for switching work zones, but I don't think that's the problem.
I'm posting the entire programming here in case you can help me. Thanks!
'Get the current values
ActY = GetOEMDro(1)
MinYCoord = GetOEMDro(5)
MaxYCoord = GetOEMDro(11)
'front lowering
If ActY <= (MinYCoord+80) Then ActivateSignal(OUTPUT10)
'front raising
If ActY > (MinYCoord+80) Then DeActivateSignal(OUTPUT10)
rear lowering
If ActY <= (MaxYCoord-80) Then ActivateSignal(OUTPUT11)
'front raising
If ActY > (MaxYCoord-80) Then DeActivateSignal(OUTPUT11)
If(GetInBit(90, 2)) And Not (GetOemLed(800)) Then
Code("G55")
Wait
If getDro(24) = 2 Then
Code("G52 X-275.95 Y167.36 ")
Wait
End If
If getDro(24) = 3 Then
Code("G52 X-551.09 Y-2.87 Z0")
Wait
End If
Wait
End If
If(GetInBit(90, 3)) And Not (GetOemLed(800)) Then
Code("G56")
Wait
If getDro(24) = 2 Then
Code("G52 X-275.95 Y167.36 ")
Wait
End If
If getDro(24) = 3 Then
Code("G52 X-551.09 Y-2.87 Z0")
Wait
End If
End If
End
'-----------------------------------------------------------------------------
Sub Wait()
WhileIsMoving()
Sleep(15)
wend
End Sub
'-----------------------------------------------------------------------------
-
the code looks ok for me.
the other code looks like you are using a CSMIO controler?
how did you configure the outputs in ports and pins?
normaly you use the SetOutBit(x,y) or ResetOutBit(x,y) for those outputs.
it is very dangerous to use Sleep's in macropump because macropump is called
normaly every 20ms as a 'cyclic' task.
also all your GCode commands should not be in macropump, they are looking like
they are related to a toolchange and should be in M6Start macro, just a thought.
-
Thanks for your suggestion. Another programmer made it. It's a subroutine to divide the machine into two work zones. With this programming, the machine switches zones so it's always working while the operator places another part on the other side.
If I change this current programming to macro M6, will the machine use this programming at the start of each program? Or when calling M6?
Correct, the machine has a CSMIO.
I configured the output ports and pins normally. I checked enabled and configured the port and pin numbers, just that...
Could you tell me how to configure the outputs as you indicated with SetOutBit(x,y) or ResetOutBit(x,y)?
-
there is a small mistake in code :
original:
'Get the current values
ActY = GetOEMDro(1)
MinYCoord = GetOEMDro(5)
MaxYCoord = GetOEMDro(11)
'front lowering
If ActY <= (MinYCoord+80) Then ActivateSignal(OUTPUT10)
'front raising
If ActY > (MinYCoord+80) Then DeActivateSignal(OUTPUT10)
rear lowering
If ActY <= (MaxYCoord-80) Then ActivateSignal(OUTPUT11)
'front raising
If ActY > (MaxYCoord-80) Then DeActivateSignal(OUTPUT11)
should be:
'Get the current values
ActY = GetDro(1)
MinYCoord = GetOEMDro(5)
MaxYCoord = GetOEMDro(11)
'front lowering
If ActY <= (MinYCoord+80) Then ActivateSignal(OUTPUT10)
'front raising
If ActY > (MinYCoord+80) Then DeActivateSignal(OUTPUT10)
'rear lowering
If ActY <= (MaxYCoord-80) Then ActivateSignal(OUTPUT11)
'front raising
If ActY > (MaxYCoord-80) Then DeActivateSignal(OUTPUT11)
-
Hi, thank you very much! I'll try it.
-
Hi, I've tested the code and it works correctly now, but I need the Y-axis position comparison to be based on the G code. Currently, it's based on the machine's absolute Y-axis position.
Should I change ActY = GetDro(1) to another parameter?
Could you help me? Thanks.
-
maybe GetOEMDro(801) is what you are looking for.
-
With GetOEMDro(801), can I use it for the two functions shown in the attached files?
I need to work with those two, MaxY and MinY.
-
i mean:
ActY = GetOEMDro(801)
it will not effect the Min and Max.
-
I need to compare the current position of the machine with the minimum and maximum Y values in the G code, to raise or lower the rollers when they are close to the maximum and minimum Y limits.
-
I need to compare the current position of the machine with the minimum and maximum Y values in the G code, to raise or lower the rollers when they are close to the maximum and minimum Y limits.
that is what the code does? if you are using G54,G55 .. it should do it during you run your G-code program.
-
I'll try ActY = GetOEMDro(801).
Thank you.
If we are using G55 and G56
-
Hi friend. How are you?
I can't get this macro to work properly, please help me.
It only activates output 10, but it's fixed and doesn't do what I need: deactivate when it reaches the limit.
It also never activates output 11, even though it's in the working position.
I'm uploading the code here for you to review. I think I'm missing some actions.
-
there is still a bug in your script:
rear lowering
should be:
'rear lowering
witch i have written earlier, anyway you can copy this code:
'Get the current values
ActY = GetOEMDro(801)
MinYCoord = GetOEMDro(5)
MaxYCoord = GetOEMDro(11)
MsgBox "ActY: " &ActY &" MinY: " &MinYCoord &" MaxYcoord; " &MaxYCoord
'front lowering
If ActY <= (MinYCoord+80) Then
ActivateSignal(OUTPUT10)
MsgBox "OUTPUT10 activated"
End If
'front raising
If ActY > (MinYCoord+80) Then
DeActivateSignal(OUTPUT10)
MsgBox "OUTPUT10 deactivated"
End If
'rear lowering
If ActY <= (MaxYCoord-80) Then
ActivateSignal(OUTPUT11)
MsgBox "OUTPUT11 activated"
End If
'front raising
If ActY > (MaxYCoord-80) Then
DeActivateSignal(OUTPUT11)
MsgBox "OUTPUT11 deactivated"
End If
into VB Scripter Window and use >|| button to step through programm to see what is going on.
a GGode programm has to be loaded to have valid MinY and MaxY coords. then you can move y axis in manual and step throug programm again.
-
Hola, he escrito el código tal cual me lo ha enviado y no funciona. La maquina solo activa la salida 11, fija durante todo el mecanizado, sin subir cuando se acerca al limite. Y al finalizar el mecanizado activa las dos salidas 10 y 11.
-
copy this code:
'Get the current values
ActY = GetOEMDro(801)
MinYCoord = GetOEMDro(5)
MaxYCoord = GetOEMDro(11)
MsgBox "ActY: " &ActY &" MinY: " &MinYCoord &" MaxYcoord; " &MaxYCoord
into VB Scripter window and press the run button, then you will get a messagebox with coordinates
to see the real coordinates and post the result
-
This mesag in the screen
-
This image
-
then there is a bug in line 15 of your code.
pls post excactly the code of the VB scripter window.
-
I've fixed the msg issue in the script.
The ActY takes data from the Yact machine, so it's invalid. We need MaxY and MinY from the G-code.
The code:
'Get the current values
ActY = GetOEMDro(801)
MinYCoord = GetOEMDro(5)
MaxYCoord = GetOEMDro(11)
MsgBox "ActY: " &ActY &" MinY: " &MinYCoord &" MaxYcoord; " &MaxYCoord
'front lowering
If ActY >= (MinYCoord) Then'<=
ActivateSignal(OUTPUT11)
End If
'front raising
If ActY <= (MinYCoord) Then'<=
DeActivateSignal(OUTPUT11)
End If
'rear lowering
If ActY >= (MaxYCoord) Then'<=
ActivateSignal(OUTPUT10)
End If
'front raising
If ActY <= (MaxYCoord) Then'>=
DeActivateSignal(OUTPUT10)
End If
If(GetInBit(90, 2)) And Not (GetOemLed(800)) Then
Code(" G55")
Espera
If getDro (24) = 2 Then
Code("G52 X-275.95 Y167.36 ")
Espera
End If
If getDro (24) = 3 Then
Code("G52 X-551.09 Y-2.87 Z0")
Espera
End If
Espera
End If
If(GetInBit(90, 3)) And Not (GetOemLed(800)) Then
Code(" G56")
Espera
If getDro (24) = 2 Then
Code("G52 X-275.95 Y167.36 ")
Espera
End If
If getDro (24) = 3 Then
Code("G52 X-551.09 Y-2.87 Z0")
Espera
End If
End If
End
' -----------------------------------------------------------------------------
Sub Espera ()
While IsMoving()
Sleep(15)
Wend
End Sub
' -----------------------------------------------------------------------------
-
if i load i simple G-code here i can see the Min/Max values from G-Code program in program limit's
this is what OEMDro(5) and OEMDro(11) are normaly showing.
and ActY is what this Axis DRO is showing
-
If you look at the message generated in the VB script, the ActY value is the machine coordinate.
The MinY value refers to the minimum absolute machine coordinate.
Only the MaxY value is actually how we want to compare it with the MaxY in G code.
This is strange, since, as you say, 5 and 11 refer to G code.
Only OEM Dro 11 is working as we want.
-
The OEMDRO 801 is a multifunction device that can be used for Machine Coordinates, Work, or DTG. How do we select one of these three functions?
-
here:
https://www.machsupport.com/forum/index.php?topic=19482.0
you can download a list of all DRO's / OEMDro's
OEMDro(801) is the current Y-Coord
Dro(84) is Y-MachineCoord
and there a couple of other's
i usually allways use OemDro(801)
-
maybe OEMDro(185) will do the job
-
Okay, thanks, friend. The variables are correct. I don't understand why it's not collecting the information about the Gcode. Would it be possible to add an option so that it only starts executing these script functions after requesting the Gcode program to start?
-
okay this is a version witch is only excecuted if Cycle Start LED is ON
'only if Start LED is only
If GetOEMLed(804) = True Then
'Get the current values
ActY = GetOEMDro(801)
MinYCoord = GetOEMDro(5)
MaxYCoord = GetOEMDro(11)
'front lowering
If ActY >= (MinYCoord) Then'<=
ActivateSignal(OUTPUT11)
End If
'front raising
If ActY <= (MinYCoord) Then'<=
DeActivateSignal(OUTPUT11)
End If
'rear lowering
If ActY >= (MaxYCoord) Then'<=
ActivateSignal(OUTPUT10)
End If
'front raising
If ActY <= (MaxYCoord) Then'>=
DeActivateSignal(OUTPUT10)
End If
End If