Hello Guest it is March 28, 2024, 08:26:01 PM

Author Topic: VB Script for Homing  (Read 3487 times)

0 Members and 1 Guest are viewing this topic.

VB Script for Homing
« 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?

Code: [Select]
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!

Re: VB Script for Homing
« Reply #1 on: June 23, 2017, 02:32:26 PM »
Mostly, it seems IsMoving() breaks when I try to home my slaved axis.

Offline ger21

*
  • *
  •  6,295 6,295
    • View Profile
    • The CNC Woodworker
Re: VB Script for Homing
« Reply #2 on: June 23, 2017, 08:54:16 PM »
Quote
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
Gerry

2010 Screenset
http://www.thecncwoodworker.com/2010.html

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html
Re: VB Script for Homing
« Reply #3 on: June 26, 2017, 12:14:09 PM »
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.
Re: VB Script for Homing
« Reply #4 on: June 26, 2017, 12:15:09 PM »
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

Offline ger21

*
  • *
  •  6,295 6,295
    • View Profile
    • The CNC Woodworker
Re: VB Script for Homing
« Reply #5 on: June 26, 2017, 12:22:24 PM »
Are you using a chinese motion controller?
It may not support RefCombination.
Gerry

2010 Screenset
http://www.thecncwoodworker.com/2010.html

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html
Re: VB Script for Homing
« Reply #6 on: June 27, 2017, 11:42:18 AM »
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