Machsupport Forum
Mach Discussion => VB and the development of wizards => Topic started by: aluplastvz on December 10, 2015, 07:42:40 AM
-
Can someone help me how to rotate tool cw / ccw with BCD encoder 1-4 tools .outpt 1 - cw , output2 - ccw, output3 -clok
The engine that runs the three-phase tools with 2 relays
'M6Start.m1s
OldTool = GetOEMDRO (1200)
Tool = GetSelectedTool()
MaxToolNum = 4
If OldTool = Tool Then
Message ("Selected Tool already loaded")
Exit Sub
End If
While Tool > MaxToolNum
Tool = Question ("Enter New Tool Number up to " & MaxToolNum)
Wend
Call StartTool
While NewTool <> Tool
Call CheckPins
While IsMoving()
Wend
Wend
Call StopTool
Call SetUserDRO (1200, NewTool)
SetCurrentTool(NewTool)
Sub StartTool
If NevTool< Tool Then
ActivateSignal(Output2)
Exit Sub
End If
While IsMoving()
Wend
If NevTool>Tool Then
ActivateSignal(Output4)
Exit Sub
End If
ActivateSignal(Output3)
While IsMoving()
Wend
End Sub
Sub CheckPins
If IsActive(Input1) Then
NewTool = 1
End If
If IsActive(Input2) Then
NewTool = 2
End If
If IsActive(Input3) Then
NewTool = 3
End If
If IsActive(Input4) Then
NewTool = 4
End If
End Sub
Sub Stoptool
DeActivateSignal(Output2)
While IsMoving()
Wend
ActivateSignal(Output3)
Code "G4 P1.0"
While IsMoving()
Wend
DeActivateSignal(Output3)
DeActivateSignal(Output4)
While IsMoving()
Wend
End Sub
This example works in one direction, what is the problem
thanks
-
Now I'm a novice here so bare with me, but I think you are using the "Call" sub routine incorrect. And by luck it seems to be working in one direction....
You assume the variables you define in you Main program (Global variables) are also available in the Sub routine, this is wrong.
A sub routine uses "Local variable" and is, by default, not aware of the main program, or main program variables at all !
Now to use the "Call StartTool" you must send the variable to that sub routine, that the routine needs which is "NewTool and Tool"
So the correct code would look like "Call StartTool(Newtool,Tool)" here you send 2 values beloning to NewTool, and Tool AND IN THAT ORDER !!
Now the Sub Routine need to know what kind of information to recieve.
Again "Sub StartTool(Newtool, Tool)" AND IN THAT ORDER This is because you use the same variablenames in you main program as in the sub routine.
This also messes up your other subroutine, where you Call for a tool position, here you expect that a Subroutine (Local variables), updates the Global variables of you main program.
They dont !
Here you must tell the Sub-routine that the variables are linked "ByRef" allowing a sub-routine to update global variables.
Perhaps you can find a bit of help here: https://youtu.be/duULYFBjDnk?t=530 (https://youtu.be/duULYFBjDnk?t=530)
Here I walk through a script for Tool Probing, and here I use, Call and Call "ByRef"
-Bo-
Call StartTool
While NewTool <> Tool
Call CheckPins
While IsMoving()
Wend
Wend
Call StopTool
Call SetUserDRO (1200, NewTool)
SetCurrentTool(NewTool)
Sub StartTool
If NevTool< Tool Then
ActivateSignal(Output2)
Exit Sub
End If
While IsMoving()
Wend
If NevTool>Tool Then
ActivateSignal(Output4)
Exit Sub
End If
ActivateSignal(Output3)
While IsMoving()
Wend
End Sub
-
https://www.youtube.com/watch?v=ogxpFvXb5XU&feature=youtu.be
-
GREAT, seems you got it sorted out. Nice job.