Machsupport Forum
Mach Discussion => VB and the development of wizards => Topic started by: garetbiglow on June 23, 2017, 01:57:58 PM
-
So I'm trying to write a simple VB script to home my gantry (CNC plasma). I'm new to Mach and scripting for it, but not new to CNC or programming. I've added a script button to my screenset, name it "Homing Cycle". Here's the sudo logic of what I'd like it to do:
1. Home Z-Axis
2. Set Z machine position (G53) to 1.000
3. Pull off limit switch to Z0 (G53)
4. Home X-Axis (slaved with A, A reversed motion)
5. Set X machine position (G53) to -1.000
6. Pull off limit switch to X0 (G53)
7. Home Y-Axis
8. Set Y machine position (G53) to -1.000
9. Pull off limit switch to Y0 (G53)
Here's my VB. It mostly works, but doesn't execute the "G0 X0" for some reason?
DoButton( 24 ) 'Z Home Axis
While IsMoving()
Wend
SetOEMDRO(802,1)
Code "G0 Z0"
While IsMoving()
Wend
Sleep 1000
RefCombination( 9 ) 'X + A Home
While IsMoving()
Wend
SetOEMDRO(800,-1)
Code "G0 X0"
While IsMoving()
Wend
Sleep 1000
DoButton( 23 ) 'Y Home Axis
While IsMoving()
Wend
SetOEMDRO(801,-1)
Code "G0 X0 Y0"
While IsMoving()
Wend
Sleep 1000
Any help would be great! Thanks very much!
-
Mostly, it seems IsMoving() breaks when I try to home my slaved axis.
-
SetOEMDRO(802,1)
This sets your G54 offset to 1, not the G53 position.
To do what you want, go to Config>Homing/Limits and enter 1 in the Home Off. column for the Z axis. This basically specifies the switch location in machine coordinates (G53).
Enter -1 for the X, Y, and A axis.
I use this code, and it works fine for me:
DoButton( 24 )
Code "G53 G0 Z0"
While IsMoving()
Wend
RefCombination(9)
Code "G53 G0 X0"
While IsMoving()
Wend
DoButton( 23 )
Code "G53 G0 Y0"
While IsMoving()
Wend
-
Hmm, doesn't work for me. I did all you said there, and it's still acting weird.
The script will:
1. Seek Z-Home switch
2. Set the offset to Z = 1.000
3. Rapid to Z 0.000
4. Seek X-Home switch
5. Set the offset to X = -1.000
Then it just finished the script. Doesn't even try to home Y. It seems to be an issue with slaving the Axis. When I just run it un-slaved (and without the RefCombination), it's fine.
-
Ok, here's what worked.
I had to set the homing switch in Inputs so X and A were sharing a homing switch. Then, here's my code:
DoButton( 24 )
While IsMoving()
Wend
Code "G53 G0 Z0"
While IsMoving()
Wend
RefCombination(9)
'DoButton( 22 )
While IsMoving()
Wend
Code "G53 G0 X0"
While IsMoving()
Wend
DoButton( 23 )
While IsMoving()
Wend
Code "G53 G0 Y0"
While IsMoving()
Wend
-
Are you using a chinese motion controller?
It may not support RefCombination.
-
I'm using a SmoothStepper, not sure which version. I did get it working though, and RefCombination is supported. I just needed to "slave" the homing input for X and A together