Machsupport Forum
Mach Discussion => VB and the development of wizards => Topic started by: xiteamxi on March 14, 2017, 01:37:30 AM
-
Hello all, I'm new to the forum but not cnc or mach3(have several machines running it) recently retrofitted a mill (denford triac) and i'm stumped with the atc macro. Any help will be appreciated at this point. The part i'm having an issue with is, i want to activate output 7(while input 1 is active)and have output 7 remain on until input 1 goes inactive and returns active again then deactivate output 7.
some info..
The input is a proximity sensor on the geneva gear drive thats shaped like 3/4 of a circle and is active on the missing 1/4 section
tool charger is 8 position
relays ect are setup
its a reversible ac gear motor driving a geneva gear
1 relay is motor power 1 for reversing
has proximity sensor which i have wired to a relay that grounds a pin to activate (input1)
ive started with a macro i found and edited (for better or worse...)the section below between the "#######" is the main issue but any help is welcome this is v1.0 after all...
Sub Main()
'Global variables declaration
NewTool = GetSelectedTool()
OldTool = GetCurrentTool()
While NewTool > 8
NewTool = Question ("Enter New Tool Number up to " & MaxToolNum)
Wend
If NewTool = OldTool Then'Compare between actual tool and requested tool
Else
End If
If NewTool > 8 Then'requested tool higher then tool numbers
Else
End If
If NewTool < 1 Then'tool number to low
Else
End If
code("m05")
Call ZatcPosition
Call AtcIn'Activate air cylinder valve to put old tool back to carrousel
Call Unclamp'Spindle: Tool Unclamp
Call AtcDown'lowers atc
Call LeastTravel'determine the least travel to move and Turns CW or CCW
Call AtcUp'raises atc
Call Clamp'Spindle: Tool Clamp
Call AtcOut'retracts atc
Call SetUserDRO (1200,NewTool)'Store new tool as actual tool value
SetCurrentTool( NewTool )
End Sub
Function ZatcPosition()'Move to Z tool position and wait until position reached
code("G53")'Move in Absolute Machine coordinates
code("G00 Z-1") 'Z value as to be checked for exact match with carrousel height
While(IsMoving())
Sleep(100)'temporisation entre while++
Wend
End Function
Function AtcIn()'Put old tool back to carrousel
ActivateSignal(OUTPUT4)'Move carrousel air cylinder to the tool change position adjust output# to match atc slide
code("g04 p01")
End Function
Function Unclamp()'Spindle: Tool Unclamp
ActivateSignal(OUTPUT6)'Release the tool, adjust output number for drawbar output
code("g04 p01")'pause
End Function
Function AtcDown()'lowers atc to rotate
ActivateSignal(OUTPUT5)'solonoid to lower atc
code("G04 p01")'pause
End Function
'Sequence to determine the least travel to move for TC, CW or CCW
Function LeastTravel()
NewTool = GetSelectedTool()
OldTool = GetCurrentTool()
NTool = 8 ' Number of tools changer holds
CWPos = GetSelectedTool() - GetCurrentTool() ' Assume a CW move
If CWPos < 0 Then ' CWPos < 0 ==> rtp < atp
CWPos = CWPos + NTools
End If
CCWPos = NTools - CWPos
If CWPos < CCWPos Then
Call CW()
Else
Call CCW()
End If
End Function
############################################################################################
Function CW()'Rotation CW
Dim x As Integer
Dim CTPos As Integer 'Carrousel Tool Position Relative to OldTool Position
CTPos=0
ActivateSignal(OUTPUT7)'Turns the AC Motor On
code"g04 p05"
Do Until IsActive(input1)
ActivateSignal(OUTPUT7)'Turns the AC Motor On
deactivatesignal(output7)
sleep(0)
Loop
For x=0 To CWPos
If IsActive(input1) Then
x=x+1
While IsActive(input1)'Wait for OEMTrig to de-assert
Wend
End If
Next x
CTPos=x
DeactivateSignal(OUTPUT7)
End Function
Function CCW()'Rotation CCW
Dim y As Integer
Dim CTPos As Integer 'Carrousel Tool Position Relative to OldTool Position
CTPos=0
ActivateSignal(OUTPUT7)'Turns the AC Motor On
activatesignal(output8)'atc motor revirsing relay
code"g04 p05"
Do Until IsActive(input1)
ActivateSignal(OUTPUT7)'Turns the AC Motor On
activatesignal(output8)'atc motor revirsing relay
sleep(0)
Loop
For y=0 To CCWPos
If IsActive(input1) Then
y=y+1
While IsActive(input1)'Wait for OEMTrig to de-assert
Wend
End If
Next y
CTPos=y
DeactivateSignal(OUTPUT7)
deactivatesignal(output8)
End Function
############################################################################################
Function AtcUp()'lifts atc
deActivateSignal(OUTPUT5)'relay for solonoid to lower/lift atc
code("G04 p01")'pause
End Function
Function Clamp()'power drawbar unactivated
DeactivateSignal(OUTPUT6)'unactivating drawbar relay
End Function
Function AtcOut()'retracts atc
deActivateSignal(OUTPUT4)'atc retract cylinder relay
code("g04 p01")
End Function
Main
-
ok lets try to read your code:
############################################################################################
Dim x As Integer
Dim CTPos As Integer 'Carrousel Tool Position Relative to OldTool Position
CTPos=0
--> some declarations
ActivateSignal(OUTPUT7)'Turns the AC Motor On
--> Switch Output 7 on
code"g04 p05"
--> wait a Little bit
Do Until IsActive(input1)
ActivateSignal(OUTPUT7)'Turns the AC Motor On
deactivatesignal(output7)
sleep(0)
Loop
--> Switch Output 7 on and off until input1 is on makes no sence
--> sleep(0) also senseless
For x=0 To CWPos
If IsActive(input1) Then
x=x+1
While IsActive(input1)'Wait for OEMTrig to de-assert
Wend
End If
Next x
--> CWPos is no global variable and no Inputparameter of the function so nothing will happen
CTPos=x
--> will be Zero, see Problem of CWPos
DeactivateSignal(OUTPUT7)
--> Switch Output7 off , so it only will be on for G04 P5 nothing else
Regards Thomas
-
Willing to try any suggestions you have and i appreciate the reply. If you have some code i can replace the section im having trouble with and see what happens i can do that.
-
no i have no code to replace,
tryed to make you think about your code.
-
i appreciate the attempt but im not sure whats required to achieve my goal I've attempted to look at probing macros ect to learn as they would do a similar task
(if probe input is active move Z+ if not active move Z-)
i'm getting many errors when trying to use the vb editor and not sure how to correct them.
a simple form of what i'm trying to achieve is
turn output 7 on until input 1 is NOT active (when initially turned on the input 1 will be active/home)
(then what ever option is easier)
(option 1) have output 7 remain on until input 1 returns to an active state
(option 2) have it shut off once input 1 is NOT active then turn back on until active again
this cycle above will make it rotate the atc 1/2 of a tool distance so that ran twice will be equal to 1 tool position.
in non vb editor correct form...
activatesignal(output 7) until input 1 is not active
then deactivatesignal(output1)
next
activatesignal(output7) untill input 1 is active
then deactivate signal (output7)
loop the above the amount of times required to get to new atc position (i can work on this part after if needed)
-
ok made some changes in your code:
Sub Main()
'Global variables declaration
Dim CCWPos as Integer
Dim CWPos as Integer
NewTool = GetSelectedTool()
OldTool = GetCurrentTool()
While NewTool > 8
NewTool = Question ("Enter New Tool Number up to " & MaxToolNum)
Wend
If NewTool = OldTool Then'Compare between actual tool and requested tool
Else
End If
If NewTool > 8 Then'requested tool higher then tool numbers
Else
End If
If NewTool < 1 Then'tool number to low
Else
End If
code("m05")
Call ZatcPosition
Call AtcIn'Activate air cylinder valve to put old tool back to carrousel
Call Unclamp'Spindle: Tool Unclamp
Call AtcDown'lowers atc
Call LeastTravel'determine the least travel to move and Turns CW or CCW
Call AtcUp'raises atc
Call Clamp'Spindle: Tool Clamp
Call AtcOut'retracts atc
Call SetUserDRO (1200,NewTool)'Store new tool as actual tool value
SetCurrentTool( NewTool )
End Sub
Function ZatcPosition()'Move to Z tool position and wait until position reached
code("G53")'Move in Absolute Machine coordinates
code("G00 Z-1") 'Z value as to be checked for exact match with carrousel height
While(IsMoving())
Sleep(100)'temporisation entre while++
Wend
End Function
Function AtcIn()'Put old tool back to carrousel
ActivateSignal(OUTPUT4)'Move carrousel air cylinder to the tool change position adjust output# to match atc slide
code("g04 p01")
End Function
Function Unclamp()'Spindle: Tool Unclamp
ActivateSignal(OUTPUT6)'Release the tool, adjust output number for drawbar output
code("g04 p01")'pause
End Function
Function AtcDown()'lowers atc to rotate
ActivateSignal(OUTPUT5)'solonoid to lower atc
code("G04 p01")'pause
End Function
'Sequence to determine the least travel to move for TC, CW or CCW
Function LeastTravel()
NewTool = GetSelectedTool()
OldTool = GetCurrentTool()
NTool = 8 ' Number of tools changer holds
CWPos = GetSelectedTool() - GetCurrentTool() ' Assume a CW move
If CWPos < 0 Then ' CWPos < 0 ==> rtp < atp
CWPos = CWPos + NTools
End If
CCWPos = NTools - CWPos
If CWPos < CCWPos Then
Call CW()
Else
Call CCW()
End If
End Function
Function CW()'Rotation CW
Dim x As Integer
Dim CTPos As Integer 'Carrousel Tool Position Relative to OldTool Position
CTPos=0
ActivateSignal(OUTPUT7)'Turns the AC Motor On
Deactivatesignal(output8)'atc motor revirsing relay
code"g04 p05"
Do Until IsActive(input1)
sleep(10)
Loop
For x=0 To CWPos
If IsActive(input1) Then
x=x+1
While IsActive(input1)'Wait for OEMTrig to de-assert
Wend
End If
Next x
CTPos=x
DeactivateSignal(OUTPUT7)
End Function
Function CCW()'Rotation CCW
Dim y As Integer
Dim CTPos As Integer 'Carrousel Tool Position Relative to OldTool Position
CTPos=0
Activatesignal(output8)'atc motor revirsing relay
ActivateSignal(OUTPUT7)'Turns the AC Motor On
code"g04 p05"
Do Until IsActive(input1)
sleep(10)
Loop
For y=0 To CCWPos
If IsActive(input1) Then
y=y+1
While IsActive(input1)'Wait for OEMTrig to de-assert
Wend
End If
Next y
CTPos=y
DeactivateSignal(OUTPUT7)
Deactivatesignal(output8)
End Function
Function AtcUp()'lifts atc
DeActivateSignal(OUTPUT5)'relay for solonoid to lower/lift atc
code("G04 p01")'pause
End Function
Function Clamp()'power drawbar unactivated
DeactivateSignal(OUTPUT6)'unactivating drawbar relay
End Function
Function AtcOut()'retracts atc
deActivateSignal(OUTPUT4)'atc retract cylinder relay
code("g04 p01")
End Function
please try in vbeditor step in mode and Report Errors, sorry have no Chance to test.
Thomas
-
Hello, yet again thanks for your help. there is no errors in that macro but it doesn't do what i'm trying to achieve, when i try to go from tool say 1 to tool 2 it just turns on for (about) a second then off getting about half way from t1 to t2. i think the g04 p05 is wrong that was me just trying anything i could think of. What is the correct term for "do until input 1 is not active"? i'm debating replacing the motor with a stepper as i could figure that out but in its current form i seen this atc work with the same sensor/motor/relays on the old less user friendly software so i know it should work.
if i can just get the 2 correct lines for
'activate output 7 until output 1 is not active"
then
"activate output 7 until input 1 is active"
i think it may be a step in the correct direction
Function CW()'Rotation CW
Dim x As Integer
Dim CTPos As Integer 'Carrousel Tool Position Relative to OldTool Position
CTPos=0
ActivateSignal(OUTPUT7)'Turns the AC Motor On
Deactivatesignal(output8)'atc motor revirsing relay
code"g04 p05"
Do Until IsActive(input1)
sleep(10)
-
if its of any help i appear to have found the original macro just need it in a format mach 3 can work with ( output/input numbers may vary since i did update the machine)
REM ~~~~~~~~~~~~~~~ Tool Changer Routines ~~~~~~~~~~~~~~
#ArmIn
GOSUB SpindleStop
IF !comms(10) THEN RETURN : REM ignore it if we're none ATC
IF !(OUT & 1) DO : REM Check spindle is stopped
OUT3 = 1 : REM Switch the solenoid
REPEAT : REM Wait for the IN switch (inverse logic)
UNTIL !IN0 OR STOPSW
WAIT = 500
ENDIF
RETURN
#ArmOut
IF !comms(10) THEN RETURN : REM ignore it if we're none ATC
OUT3 = 0: REM Switch the solenoid
REPEAT : REM Wait for the OUT switch (inverse logic)
UNTIL !IN1 OR STOPSW
WAIT = 500
RETURN
#ArmDown
IF !comms(10) THEN RETURN : REM ignore it if we're none ATC
IF !(OUT & 1) DO : REM Check spindle is stopped
OUT4 = 1 : REM Switch the solenoid
REPEAT : REM Wait for the DOWN switch (inverse logic)
UNTIL !IN3 OR STOPSW
WAIT = 500
ENDIF
RETURN
#ArmUp
IF !comms(10) THEN RETURN : REM ignore it if we're none ATC
OUT4 = 0: REM Switch the solenoid
REPEAT : REM Wait for the UP switch (inverse logic)
UNTIL !IN2 OR STOPSW
WAIT = 500
RETURN
#DrawbarUnClamp
IF !comms(10) THEN RETURN : REM ignore it if we're none ATC
IF !(OUT & 1) DO : REM Check spindle is stopped
OUT5 = 1
WAIT = 500
ENDIF
RETURN
#DrawbarClamp
IF !comms(10) THEN RETURN : REM ignore it if we're none ATC
OUT5 = 0
WAIT = 500
RETURN
#CarouselCW
IF !comms(10) THEN RETURN : REM ignore it if we're none ATC
IF !IN3 OR !IN1 DO :REM If arm is back or down
OUT7 = 1 : REM Set Direction Output
OUT6 = 1 : REM Set the Power output
WAIT = 50
REPEAT
UNTIL IN4 OR STOPSW
REPEAT
UNTIL !IN4 OR STOPSW
REPEAT
UNTIL IN4 OR STOPSW
REPEAT
UNTIL !IN4 OR STOPSW
WAIT = 40
OUT6 = 0
Pocket = Pocket + 1 : REM Inc the Pocket Counter
IF Pocket > MaxPockets THEN Pocket = 1
ENDIF
RETURN
#CarouselHalf
IF !comms(10) THEN RETURN : REM ignore it if we're none ATC
OUT7 = 1 : REM Set Direction Output
OUT6 = 1 : REM Set the Power output
WAIT = 50
REPEAT
UNTIL IN4 OR STOPSW
REPEAT
UNTIL !IN4 OR STOPSW
WAIT = 40
OUT6 = 0
RETURN
#CarouselCCW
IF !comms(10) THEN RETURN : REM ignore it if we're none ATC
IF !IN3 OR !IN1 DO :REM If arm is back or down
OUT7 = 0 : REM Set Direction Output
OUT6 = 1 : REM Set the Power output
WAIT = 50
REPEAT
UNTIL IN4 OR STOPSW
REPEAT
UNTIL !IN4 OR STOPSW
REPEAT
UNTIL IN4 OR STOPSW
REPEAT
UNTIL !IN4 OR STOPSW
WAIT = 40
OUT6 = 0
Pocket = Pocket - 1 : REM Dec the Pocket Counter
IF Pocket < 1 THEN Pocket = MaxPockets
ENDIF
RETURN
#toolChange
GOSUB SpindleStop
if !comms(10) THEN Pocket=Comms(7) : REM store last tool if not ATC
IF (comms(7) = Pocket) OR !comms(10) THEN RETURN : REM ignore it if we're already there or none ATC
IF !(OUT & 57) DO : REM If atc is back,Up and drawbar safe
IF STOPSW THEN RETURN
GOSUB ArmIn
IF STOPSW THEN RETURN
GOSUB DrawbarUnclamp
IF STOPSW THEN RETURN
GOSUB ArmDown
REM Calculate the shortest path...
steps = (comms(7) - Pocket + MaxPockets) MOD MaxPockets
IF steps > (MaxPockets / 2) DO
WHILE Pocket <> comms(7)
GOSUB CarouselCCW
ENDW
ELSE
WHILE Pocket <> comms(7)
GOSUB CarouselCW
ENDW
ENDIF
GOSUB ArmUp
IF STOPSW THEN RETURN
GOSUB DrawbarClamp
IF STOPSW THEN RETURN
GOSUB ArmOut
IF STOPSW THEN RETURN
ENDIF
RETURN
REM ~~~~~~~~~ End of Tool Changer Routines ~~~~~~~
-
Do Until Not IsActive(input1)
sleep(10)
Loop
-
for the moment i am little bit confused about the ligic of input1 for doing one step of ATC
in the original macro:
--> UNTIL IN4 OR STOPSW
--> REPEAT
--> UNTIL !IN4 OR STOPSW
--> REPEAT
--> UNTIL IN4 OR STOPSW
--> REPEAT
--> UNTIL !IN4 OR STOPSW
it looks like it is ON at the start
then OFF ON OFF ON
to do one step at ATC
please describe the pattern of input1 to do one step.
Thomas
-
for the moment i am little bit confused about the ligic of input1 for doing one step of ATC
in the original macro:
--> UNTIL IN4 OR STOPSW
--> REPEAT
--> UNTIL !IN4 OR STOPSW
--> REPEAT
--> UNTIL IN4 OR STOPSW
--> REPEAT
--> UNTIL !IN4 OR STOPSW
it looks like it is ON at the start
then OFF ON OFF ON
to do one step at ATC
please describe the pattern of input1 to do one step.
Thomas
Hello, that correct it will start ON
then OFF ON OFF ON (ending in ON)
this would equal 1 tool position so if i was at tool 1 and ran that id end up at tool 2 if i was at 1 and ran it in ccw it would be tool 8.
-
ok then something like this should be closer:
Sub Main()
'Global variables declaration
Dim CCWPos as Integer
Dim CWPos as Integer
NewTool = GetSelectedTool()
OldTool = GetCurrentTool()
While NewTool > 8
NewTool = Question ("Enter New Tool Number up to " & MaxToolNum)
Wend
If NewTool = OldTool Then'Compare between actual tool and requested tool
Else
End If
If NewTool > 8 Then'requested tool higher then tool numbers
Else
End If
If NewTool < 1 Then'tool number to low
Else
End If
code("m05")
Call ZatcPosition
Call AtcIn'Activate air cylinder valve to put old tool back to carrousel
Call Unclamp'Spindle: Tool Unclamp
Call AtcDown'lowers atc
Call LeastTravel'determine the least travel to move and Turns CW or CCW
Call AtcUp'raises atc
Call Clamp'Spindle: Tool Clamp
Call AtcOut'retracts atc
Call SetUserDRO (1200,NewTool)'Store new tool as actual tool value
SetCurrentTool( NewTool )
End Sub
Function ZatcPosition()'Move to Z tool position and wait until position reached
code("G53")'Move in Absolute Machine coordinates
code("G00 Z-1") 'Z value as to be checked for exact match with carrousel height
While(IsMoving())
Sleep(100)'temporisation entre while++
Wend
End Function
Function AtcIn()'Put old tool back to carrousel
ActivateSignal(OUTPUT4)'Move carrousel air cylinder to the tool change position adjust output# to match atc slide
code("g04 p01")
End Function
Function Unclamp()'Spindle: Tool Unclamp
ActivateSignal(OUTPUT6)'Release the tool, adjust output number for drawbar output
code("g04 p01")'pause
End Function
Function AtcDown()'lowers atc to rotate
ActivateSignal(OUTPUT5)'solonoid to lower atc
code("G04 p01")'pause
End Function
'Sequence to determine the least travel to move for TC, CW or CCW
Function LeastTravel()
NewTool = GetSelectedTool()
OldTool = GetCurrentTool()
NTool = 8 ' Number of tools changer holds
CWPos = GetSelectedTool() - GetCurrentTool() ' Assume a CW move
If CWPos < 0 Then ' CWPos < 0 ==> rtp < atp
CWPos = CWPos + NTools
End If
CCWPos = NTools - CWPos
If CWPos < CCWPos Then
Call CW()
Else
Call CCW()
End If
End Function
Function CW()'Rotation CW
Dim x As Integer
Dim CTPos As Integer 'Carrousel Tool Position Relative to OldTool Position
CTPos=0
ActivateSignal(OUTPUT7)'Turns the AC Motor On
Deactivatesignal(output8)'atc motor revirsing relay
Sleep(50)
For x=0 To CWPos
While IsActive(input1)'Wait for INPUT1 is off
Sleep(10)
Wend
While NOT IsActive(input1)'Wait for INPUT1 is on
Sleep(10)
Wend
While IsActive(input1)'Wait for INPUT1 is off
Sleep(10)
Wend
While NOT IsActive(input1)'Wait for INPUT1 is on
Sleep(10)
Wend
x=x+1
Next x
CTPos=x
DeactivateSignal(OUTPUT7)
Deactivatesignal(output8)'atc motor revirsing relay
End Function
Function CCW()'Rotation CCW
Dim y As Integer
Dim CTPos As Integer 'Carrousel Tool Position Relative to OldTool Position
CTPos=0
Activatesignal(output8)'atc motor revirsing relay
ActivateSignal(OUTPUT7)'Turns the AC Motor On
Sleep(50)
For y=0 To CCWPos
While IsActive(input1)'Wait for INPUT1 is off
Sleep(10)
Wend
While NOT IsActive(input1)'Wait for INPUT1 is on
Sleep(10)
Wend
While IsActive(input1)'Wait for INPUT1 is off
Sleep(10)
Wend
While NOT IsActive(input1)'Wait for INPUT1 is on
Sleep(10)
Wend
y=y+1
Next y
CTPos=y
DeactivateSignal(OUTPUT7)
Deactivatesignal(output8)
End Function
Function AtcUp()'lifts atc
DeActivateSignal(OUTPUT5)'relay for solonoid to lower/lift atc
code("G04 p01")'pause
End Function
Function Clamp()'power drawbar unactivated
DeactivateSignal(OUTPUT6)'unactivating drawbar relay
End Function
Function AtcOut()'retracts atc
deActivateSignal(OUTPUT4)'atc retract cylinder relay
code("g04 p01")
End Function
-
Hello, i tried that and its much better. i will tinker with it a bit and try to see what the issues, it seems to work fine if i change 1 tool number at a time (ex. t7 to t8) if i go multiple (ex. t1 to t4) it acts up. it seems like it over shoots the sensor some times like the response time is to slow so instead of ending with input1 active it will over shoot and end in a non active state.
Thanks for all your help so far.
-
something new ?
-
hello, ended up replacing the motor with a stepper motor coding will be much simpler now, i have one issue i need to solve,
in my new macro i have an equation which works but i need to figure out how to get the answer then move the stepper accordingly
ex.
s = (newtool - 1)*45
code "g00 a(s)"
so if it was tool 5 the equation would be
s = (5-1)*45
code" g00 a180"
when i'm in vb editor and i hover over "S" it will show the answer (ex. 180) but in the code line its not reading "S" as a number
whats the proper way to do that?
-
code "g00 a" + CStr(s)