Machsupport Forum

Mach Discussion => General Mach Discussion => Topic started by: Tecmaqcnc on March 19, 2025, 03:44:42 PM

Title: Macro/Script rodillos de sujeccion fresadora
Post 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

Title: Re: Macro/Script rodillos de sujeccion fresadora
Post by: TPS on March 22, 2025, 02:54:52 AM
something like this should work:
Code: [Select]
'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
Title: Re: Macro/Script rodillos de sujeccion fresadora
Post by: Tecmaqcnc on March 22, 2025, 04:31:41 AM
Thanks a lot, mate, I'll try it!!

Have a great weekend!
Title: Re: Macro/Script rodillos de sujeccion fresadora
Post by: Tecmaqcnc on April 01, 2025, 01:47:50 PM
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
'-----------------------------------------------------------------------------
Title: Re: Macro/Script rodillos de sujeccion fresadora
Post by: TPS on April 01, 2025, 02:08:49 PM
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.
 
Title: Re: Macro/Script rodillos de sujeccion fresadora
Post by: Tecmaqcnc on April 01, 2025, 02:21:50 PM
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)?
Title: Re: Macro/Script rodillos de sujeccion fresadora
Post by: TPS on April 02, 2025, 01:42:39 AM
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)

Title: Re: Macro/Script rodillos de sujeccion fresadora
Post by: Tecmaqcnc on April 02, 2025, 09:37:37 AM
Hi, thank you very much! I'll try it.
Title: Re: Macro/Script rodillos de sujeccion fresadora
Post by: Tecmaqcnc on April 12, 2025, 12:13:35 PM
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.
Title: Re: Macro/Script rodillos de sujeccion fresadora
Post by: TPS on April 13, 2025, 03:33:34 AM
maybe GetOEMDro(801) is what you are looking for.
Title: Re: Macro/Script rodillos de sujeccion fresadora
Post by: Tecmaqcnc on April 13, 2025, 03:44:47 AM
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.
Title: Re: Macro/Script rodillos de sujeccion fresadora
Post by: TPS on April 13, 2025, 03:46:44 AM
i mean:

ActY = GetOEMDro(801)

it will not effect the Min and Max.
Title: Re: Macro/Script rodillos de sujeccion fresadora
Post by: Tecmaqcnc on April 13, 2025, 03:53:01 AM
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.
Title: Re: Macro/Script rodillos de sujeccion fresadora
Post by: TPS on April 13, 2025, 03:56:12 AM
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.
Title: Re: Macro/Script rodillos de sujeccion fresadora
Post by: Tecmaqcnc on April 13, 2025, 04:04:43 AM
I'll try ActY = GetOEMDro(801).

Thank you.

If we are using G55 and G56
Title: Re: Macro/Script rodillos de sujeccion fresadora
Post by: Tecmaqcnc on May 24, 2025, 01:26:34 PM
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.

Title: Re: Macro/Script rodillos de sujeccion fresadora
Post by: TPS on May 25, 2025, 03:01:20 AM
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:

Code: [Select]
'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.
Title: Re: Macro/Script rodillos de sujeccion fresadora
Post by: Tecmaqcnc on June 06, 2025, 02:14:18 AM
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.
Title: Re: Macro/Script rodillos de sujeccion fresadora
Post by: TPS on June 06, 2025, 02:34:55 AM
copy this code:

Code: [Select]
'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
Title: Re: Macro/Script rodillos de sujeccion fresadora
Post by: Tecmaqcnc on June 06, 2025, 02:55:41 AM
This mesag in the screen
Title: Re: Macro/Script rodillos de sujeccion fresadora
Post by: Tecmaqcnc on June 06, 2025, 03:07:44 AM
This image
Title: Re: Macro/Script rodillos de sujeccion fresadora
Post by: TPS on June 06, 2025, 06:50:31 AM
then there is a bug in line 15 of your code.
pls post excactly the code of the VB scripter window.
Title: Re: Macro/Script rodillos de sujeccion fresadora
Post by: Tecmaqcnc on June 06, 2025, 07:11:05 AM
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
' -----------------------------------------------------------------------------

                                                         
Title: Re: Macro/Script rodillos de sujeccion fresadora
Post by: TPS on June 06, 2025, 11:38:40 AM
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
Title: Re: Macro/Script rodillos de sujeccion fresadora
Post by: Tecmaqcnc on June 06, 2025, 01:08:31 PM
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.
Title: Re: Macro/Script rodillos de sujeccion fresadora
Post by: Tecmaqcnc on June 07, 2025, 02:04:21 AM
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?
Title: Re: Macro/Script rodillos de sujeccion fresadora
Post by: TPS on June 07, 2025, 02:36:10 AM
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)

Title: Re: Macro/Script rodillos de sujeccion fresadora
Post by: TPS on June 07, 2025, 02:43:52 AM
maybe OEMDro(185) will do the job
Title: Re: Macro/Script rodillos de sujeccion fresadora
Post by: Tecmaqcnc on June 08, 2025, 03:20:20 AM
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?
Title: Re: Macro/Script rodillos de sujeccion fresadora
Post by: TPS on June 08, 2025, 04:56:20 AM
okay this is a version witch is only excecuted if Cycle Start LED is ON
Code: [Select]
'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