Introduction: Zeroing a CNC With a USB Microscope

Zeroing out the X and Y positions on your material can be tedious. Here's one way that may be able to speed up the process that is fairly accurate and repeatable. Besides, mounting more technology to your CNC machine is never a bad thing, right?

Step 1:

I used a program called MPlayer to view the WebCam video, as well as, drawing the crosshairs over the video feed. It's a pretty cool piece of software, and because of how flexible it is it is able to be embedded within a LinuxCNC GUI tab. One of the biggest problems I ran into early with using MPlayer was that while it is customizable to a fault it won't let you draw a couple of lines over this video to form crosshairs. Luckily, I found somebody on the Linux CNC forum that cleverly figured out that they could just draw two rectangles over the video feed with the following code added to your .ini file.

EMBED_TAB_NAME = Camera
EMBED_TAB_COMMAND = mplayer -wid {XID} tv://0 -vf rectangle=-1:2:-1:240,rectangle=2:-1:320:-1

And, that's it. With those two lines of code, and MPlayer installed you have an embedded video feed with crosshairs. Another great thing is that of all the different software's I've tested MPlayer is by far the least CPU intensive option I've seen, and it also gives the smoothest FPS performance as well.

Step 2:

I also programmed a custom button into my LinuxCNC GUI that runs some G-code that zeros out the X and Y axis while taking into account the offset of the cameras position in relation to the spindles position. To accomplish this I had to edit three existing files in my config folder and create a .NGC file.

o101 sub<br>(Sets X0 with offset of 1.5)
G10 L20 P1 X1.5
(Sets Y0 with offset of 1.5)
G10 L20 P1 y1.5
(Moves to Xo Y0)
G1 X0 Y0 F900
o101 endsub

It's a pretty simple O-code file really that only contains three lines of G-code. The first two lines of G code are both G10 L20 commands which sets the coordinate system. The cool thing is that it automatically takes into account the offset, in this case 1.5, when calculating where X and Y 0 are. The "P1" refers to the coordinate system which can be a number between 1 to 9. The third line of G-code is a G1 command that tells the machine to move to the X0 Y0 position at a feed rate of 900.

Step 3:

Next we go back to the .ini file and add "HALUI = halui" under the "[HAL]" section. Then, if it doesn't exist already, you need to create a "[HALUI]" section. Under this section add the line "MDI_COMMAND = o101 call" you should end up with something that looks similar to the code below.

[HAL]
HALUI = halui
HALFILE = ShapeOko_2_Conf_V4.0.hal
HALFILE = custom.hal
POSTGUI_HALFILE = custom_postgui.hal

[HALUI]
MDI_COMMAND = o101 call

Step 4:

Picture of

After that's complete, you need to add the following to your custompanel.XML file.

If you don't see this file in your configuration directory, the easiest way to get everything in place is to run through the stepconf wizard.

Step 5:

Finally, just add the following line of code to your custom_postgui.Hal file.

net remote-o101 halui.mdi-command-01 <= pyvcp.o101

Step 6:

Picture of

To find the X and Y offset of the camera position I painted a scrap piece of wood black to allow for a better contrast for the next step. With a 60° v-bit in the spindle I milled a small pip into the wood. I then, without moving the machine in either the X or Y axis, I zeroed out the X and Y axis. After doing this, I manually jogged the machine so that the video feed had the crosshairs pointed in the center of the pip. Then it was a simple task of recording the X and Y axis values, and in putting those numbers into the 101.NGC file.

Comments

alibenpuff (author)2015-10-04

Do you know how to modify the .ngc script to home to other coordinates than 0,0?

About This Instructable

4,143views

42favorites

License:

More by CalebPeters:Building a CNC Router from ScratchZeroing a CNC with a USB MicroscopeCNC Vacuum Table
Add instructable to: