Spindle Cam

More
02 Dec 2015 03:26 - 02 Dec 2015 03:29 #66196 by AnthonyT
Spindle Cam was created by AnthonyT
I have made a camera that attaches to my TAIG CNC micro mill spindle so that I can accurately locate an XY home point. I used a cheap webcam and a 3D printed housing.

I also wrote a Python script using OpenCV that allows for finding the center of rotation.

You can see it here: www.thingiverse.com/thing:1167516

This is the user interface showing centering setup:
Attachments:
Last edit: 02 Dec 2015 03:29 by AnthonyT.

Please Log in or Create an account to join the conversation.

More
05 Dec 2015 05:12 #66435 by cmorley
Replied by cmorley on topic Spindle Cam
that looks great. What distribution of linux are you using? Wheezy?

Please Log in or Create an account to join the conversation.

More
05 Dec 2015 12:43 #66451 by AnthonyT
Replied by AnthonyT on topic Spindle Cam

that looks great. What distribution of linux are you using? Wheezy?


Thank you :)

I installed LinuxCNC 2.6 (Wheezy) from here a few weeks ago.
I also tested this on Debian Jessie.

To test that the camera even works on the computer, I am using "Camorama" (available from the distribution). I could not get "Cheese" to recognize the camera on one computer, but it did on another computer.

Some people may have to change the camera number in my python script from
cap = cv2.VideoCapture(0)
to
cap = cv2.VideoCapture(1)

Older computers may run slow while the webcam (and my script) are running, it should be stopped when you are finished homing XY.

Please Log in or Create an account to join the conversation.

More
07 Dec 2015 08:47 #66546 by cgc
Replied by cgc on topic Spindle Cam
Hi,
I have played a little bit with your code.

You can start it directly from Linuxcnc with "open file"
In "Auto"mode, it will find a circle.
In "Manu"mode, you can set the cross with the right mouse button, then hold the button and change the diameter.
With cursor you can fine change the position and with PageUp and PageDown you can fine change the diameter.
With the "OK" Button, it will create a small cnc programm witch will move the maschine with the tool center to the selected camera position.
Please edit before the position offsets camera-center to tool-center and the pixelsize of the camera and optics.

Warning: Spoiler!

regards Frank

Please Log in or Create an account to join the conversation.

More
08 Dec 2015 03:52 #66608 by AnthonyT
Replied by AnthonyT on topic Spindle Cam
Hi Frank,

Thanks for your work on this!

Maybe you are using a different OpenCV than me because the code crashed with this error:
cv2.error: /build/opencv-FWWjHr/opencv-2.4.9.1+dfsg/modules/imgproc/src/hough.cpp:1025: error: (-5) The source image must be 8-bit, single-channel in function cvHoughCircles
until I changed line 150 in your code to (add cvtColor):
circles = cv2.HoughCircles(cv2.cvtColor(frameg,cv2.COLOR_BGR2GRAY), cv2.cv.CV_HOUGH_GRADIENT, 2, 150,param1=70,param2=100,minRadius=45,maxRadius=300)

I noticed that you removed the trails. The reason I used trails, is because my webcam center is not the center of the spindle, and the tiny cheap plastic lens moves the center whenever I focus it. So, spinning the camera (while attached to the spindle) was the only way I could ensure that I could see the center of rotation (where the milling bit will enter my workpiece).

Also, I never know exactly how far away the camera is from the workpiece, so I would not reliably be able to determine mm/pixel.

There is a way to put new tabs in LinuxCNC, you might be able to put your program in a tab that starts when you click that tab. Maybe there is a way to send your Gcode directly to the machine through LinuxCNC.

Thanks, Anthony

Please Log in or Create an account to join the conversation.

More
09 Dec 2015 06:29 #66665 by cgc
Replied by cgc on topic Spindle Cam
Hello Anthony,
I use a black white camera, therefore I delete the cvtColor function.

Now, I understand your trail function...

But I have not mount the camera in the spindle, my camera is fix mount at the Z axis.
I use a telecentric microskop objectiv with long working distance, small deep of sharp and low distortion.
I have a constant offset between camera and tool center.
To measure this offset, bore a small hole with the spindle, then zero the axis, then move this hole under the center of the camera.
This distance is the offset.
To calibrate the magnification, set the pixelsize to 1, then use a exact hole with known diameter, put it under the camera, make a circle and count the pixel diameter of this circle. Now divide the real diameter through this number of pixels.

It would be an elegant way to use this in a tab.

Thank you for the good template !

regards Frank

Please Log in or Create an account to join the conversation.

More
09 Dec 2015 10:37 #66673 by cmorley
Replied by cmorley on topic Spindle Cam
mmm this seems like we should add it to linuxcnc. I think opencv is available in wheezy without compiling yes?

Chris M

Please Log in or Create an account to join the conversation.

More
09 Dec 2015 13:36 #66680 by AnthonyT
Replied by AnthonyT on topic Spindle Cam
Thanks, Frank.

Maybe this link will help you for embedding in a tab:
wiki.linuxcnc.org/cgi-bin/wiki.pl?Axis_Embed_Video

Please Log in or Create an account to join the conversation.

More
09 Dec 2015 13:38 #66682 by AnthonyT
Replied by AnthonyT on topic Spindle Cam
Yes Chris, OpenCV does not need any special compilation, just apt-get.
It would be great to add it to LinuxCNC.

Please Log in or Create an account to join the conversation.

More
10 Dec 2015 06:55 #66717 by SvenH
Replied by SvenH on topic Spindle Cam
I would love to have this available as standard!

Please Log in or Create an account to join the conversation.

Time to create page: 0.130 seconds
Powered by Kunena Forum