Hello Guest it is May 24, 2025, 03:30:57 AM

Author Topic: Gear Change Script.....Where is this stored  (Read 3629 times)

0 Members and 1 Guest are viewing this topic.

Gear Change Script.....Where is this stored
« on: September 29, 2024, 01:52:17 PM »
In mach3 it is stored in the spindlespeed, but where is it stored in mach4?

Re: Gear Change Script.....Where is this stored
« Reply #1 on: September 30, 2024, 09:37:08 AM »
I'm not sure what you are asking by where is it stored.  The different settings for each range is in the spindle tab in control configuration.
Here is a macro that allows you to get the current spindle range and to set the spindle range.

--Get the spindle range and set the spindle range
function m110()
local inst = mc.mcGetInstance()
local Gear = mc.mcSpindleGetCurrentRange(inst)
mc.mcSpindleSetRange(inst, 0)
end--m110()

if (mc.mcInEditor() == 1) then
   m110()
end

I change gears on a lathe that has a high and low range.  It works very well.
Chad Byrd
Re: Gear Change Script.....Where is this stored
« Reply #2 on: September 30, 2024, 03:03:25 PM »
Hello,
I would like to switch gears automatically and use pneumatic cylinders and valves.
I managed that with mach3.
how do I do this with mach4?

In mach3 this is in the file spindlespeed.m1s


Getriebeschaltung MACH3 Mikron WF3DP

'Spannungsversorgung Ventile EIN
SetOutbit(90,14)

rpm = GetRPM()
M3 = GETOEMLED(164)
M4 = GETOEMLED(165)

If rpm = 0 Then
rpm = InputBox("RPM?")
End If



If rpm <= 335 Then
Call Gang1
ElseIf rpm <= 560 Then
Call Gang2
ElseIf rpm <= 1320 Then
Call Gang3
ElseIf rpm <= 3150 Then
Call Gang4
Else
Message "Gewählte Drehzahl zu hoch"
DOOEMButton (1003)
End If

SetSpinSpeed (rpm)


If M3 = TRUE Then
DOSpinCW()
End If

If M4 = TRUE Then
DOSpinCCW()
End If

' Gänge
' 1: output 90, 11/13 input 91, 1/3
' 2: output 90, 11/12 input 91, 1/4
' 3: output 90, 10/13 input 91, 2/3
' 4: output 90, 10/12 input 91, 2/4
' Spindle Festdrehzahl output 90, 2 + DoSpinCW()
'



Sub Gang1
SetPulley(1)

' Positonsschalter Gangstellung abfragen
If GetInBit(91,1) And GetInBit(91,3) Then
Message "Gang 1 war schon eingelegt"
Exit Sub
End If

' Motor ein Festdrehzahl ein und Spannungsversorung SERVO ein
DoSpinCW()
SetOutbit(90,2)
SetOutbit(90,14)

' Hebel mitte schalten

Sleep 1500

ResetOutbit(90,10)
SetOutbit(90,11)


Sleep 1500

' Gangestellung abfragen
If GetInBit(91,1)=0 Then
Message "Stellung Hebel mitte nicht erreicht " & Time & " " & GetInBit(91,1)
SLEEP 1500
ResetOutbit(90,10)
SetOutbit(90,11)
SLEEP 1500

If GetInBit(91,1)=0 Then
Message " Hebel mitte für Gang1 kann nicht eingelegt werden"
' Befehl Stop
DOOEMButton (1003)
End If
End If
'Hebel rechts schalten

ResetOutbit(90,12)
SetOutbit(90,13)


Sleep 1500

' Gangestellung abfragen
If GetInBit(91,3)=0 Then
Message "Stellung Hebel rechts nicht erreicht " & Time & " " & GetInBit(91,1)
SLEEP 1500
ResetOutbit(90,12)
SetOutbit(90,13)
SLEEP 1500

If GetInBit(91,3)=0 Then
Message "Hebel rechts für Gang1 kann nicht eingelegt werden"
' Befehl Stop
DOOEMButton (1003)
End If
End If


' Motor Festdrehzahl und Spannungsversorung aus
ResetOutbit(90,10)
ResetOutbit(90,11)
ResetOutbit(90,12)
ResetOutbit(90,13)

DoSpinStop()
ResetOutbit(90,2)
Message "Gang 1 eingelegt"

End Sub

Sub Gang2
SetPulley(2)


' Positonsschalter Gangstellung abfragen
If GetInBit(91,1) And GetInBit(91,4) Then
Message "Gang 2 war schon eingelegt"
Exit Sub
End If

' Motor ein Festdrehzahl ein und Spannungsversorung SERVO ein
DoSpinCW()
SetOutbit(90,2)
SetOutbit(90,14)

' Hebel mitte schalten

Sleep 1500

ResetOutbit(90,10)
SetOutbit(90,11)


Sleep 1500

' Gangestellung abfragen
If GetInBit(91,1)=0 Then
Message "Stellung Hebel mitte nicht erreicht " & Time & " " & GetInBit(91,1)
SLEEP 1500
ResetOutbit(90,10)
SetOutbit(90,11)
SLEEP 1500

If GetInBit(91,1)=0 Then
Message " Hebel mitte für Gang 2 kann nicht eingelegt werden"
' Befehl Stop
DOOEMButton (1003)
End If
End If
'Hebel rechts schalten

ResetOutbit(90,13)
SetOutbit(90,12)


Sleep 1500

' Gangestellung abfragen
If GetInBit(91,4)=0 Then
Message "Stellung Hebel rechts nicht erreicht " & Time & " " & GetInBit(91,1)
SLEEP 1500
ResetOutbit(90,13)
SetOutbit(90,12)
SLEEP 1500

If GetInBit(91,4)=0 Then
Message "Hebel rechts für Gang 2 kann nicht eingelegt werden"
' Befehl Stop
DOOEMButton (1003)
End If
End If


' Motor Festdrehzahl und Spannungsversorung aus
ResetOutbit(90,10)
ResetOutbit(90,11)
ResetOutbit(90,12)
ResetOutbit(90,13)

DoSpinStop()
ResetOutbit(90,2)
Message "Gang 2 eingelegt"

End Sub

Sub Gang3
SetPulley(3)


' Positonsschalter Gangstellung abfragen
If GetInBit(91,2) And GetInBit(91,3) Then
Message "Gang 3 war schon eingelegt"
Exit Sub
End If

' Motor ein Festdrehzahl ein und Spannungsversorung SERVO ein
DoSpinCW()
SetOutbit(90,2)
SetOutbit(90,14)

' Hebel mitte schalten

Sleep 1500

ResetOutbit(90,11)
SetOutbit(90,10)


Sleep 1500

' Gangestellung abfragen
If GetInBit(91,2)=0 Then
Message "Stellung Hebel mitte nicht erreicht " & Time & " " & GetInBit(91,1)
SLEEP 1500
ResetOutbit(90,11)
SetOutbit(90,10)
SLEEP 1500

If GetInBit(91,2)=0 Then
Message " Hebel mitte für Gang 3 kann nicht eingelegt werden"
' Befehl Stop
DOOEMButton (1003)
End If
End If
'Hebel rechts schalten

ResetOutbit(90,12)
SetOutbit(90,13)


Sleep 1500

' Gangestellung abfragen
If GetInBit(91,3)=0 Then
Message "Stellung Hebel rechts nicht erreicht " & Time & " " & GetInBit(91,1)
SLEEP 1500
ResetOutbit(90,12)
SetOutbit(90,13)
SLEEP 1500

If GetInBit(91,3)=0 Then
Message "Hebel rechts für Gang 3 kann nicht eingelegt werden"
' Befehl Stop
DOOEMButton (1003)
End If
End If


' Motor Festdrehzahl und Spannungsversorung aus
ResetOutbit(90,10)
ResetOutbit(90,11)
ResetOutbit(90,12)
ResetOutbit(90,13)

DoSpinStop()
ResetOutbit(90,2)
Message "Gang 3 eingelegt"
End Sub

Sub Gang4
SetPulley(4)
' Positonsschalter Gangstellung abfragen
If GetInBit(91,2) And GetInBit(91,4) Then
Message "Gang 4 war schon eingelegt"
Exit Sub
End If

' Motor ein Festdrehzahl ein und Spannungsversorung SERVO ein
DoSpinCW()
SetOutbit(90,2)
SetOutbit(90,14)

' Hebel mitte schalten

Sleep 1500

ResetOutbit(90,11)
SetOutbit(90,10)


Sleep 1500

' Gangestellung abfragen
If GetInBit(91,2)=0 Then
Message "Stellung Hebel mitte nicht erreicht " & Time & " " & GetInBit(91,1)
SLEEP 1500
ResetOutbit(90,11)
SetOutbit(90,10)
SLEEP 1500

If GetInBit(91,2)=0 Then
Message " Hebel mitte für Gang 4 kann nicht eingelegt werden"
' Befehl Stop
DOOEMButton (1003)
End If
End If
'Hebel rechts schalten

ResetOutbit(90,13)
SetOutbit(90,12)


Sleep 1500

' Gangestellung abfragen
If GetInBit(91,4)=0 Then
Message "Stellung Hebel rechts nicht erreicht " & Time & " " & GetInBit(91,4)
SLEEP 1500
ResetOutbit(90,13)
SetOutbit(90,12)
SLEEP 1500

If GetInBit(91,4)=0 Then
Message "Hebel rechts für Gang 4 kann nicht eingelegt werden"
' Befehl Stop
DOOEMButton (1003)
End If
End If


' Motor Festdrehzahl und Spannungsversorung aus
ResetOutbit(90,10)
ResetOutbit(90,11)
ResetOutbit(90,12)
ResetOutbit(90,13)

DoSpinStop()
ResetOutbit(90,2)
Message "Gang 4 eingelegt"

End Sub
Nach oben
« Last Edit: September 30, 2024, 03:07:01 PM by gravie »
Re: Gear Change Script.....Where is this stored
« Reply #3 on: September 30, 2024, 03:25:33 PM »
This will take some scripting in LUA but is doable.
I would start by putting some code in the PLC Script to look at the command spindle speed
Compare it to the current selected gear
If it is different then set a flag saying it needs to change gears
Select the cylinder required for that range
Turn off all other cylinders
Turn the required cylinder on
Change the spindle range
Turn off the gear change flag. 

In the M3 and M4 commands, just check for the flag you have set.  You can use an input internally, with that you can wait indefinitely or timed for the input to turn true with a mc command in lua.
If the flag is on (or off however you want to do your logic) then it will wait.  Once it is done it will continue with the script.

Having never really given this much thought.... you may even be able to change gears while the machine is running g code.  Have the PLC Script feedhold the machine while it is changing gears and then cycle start afterwards.  I'm not entirely sure that would work... but in theory it seems like it would.
« Last Edit: September 30, 2024, 03:28:47 PM by Cbyrdtopper »
Chad Byrd