Another tab for WebCam
- eslavko
- Offline
- Elite Member
-
- Posts: 267
- Thank you received: 4
The top image is centered in 'hole' within 0.03mm tolerance (webcam vs probe). And probe itself differ for 0.02mm in sucesive diameter reading. So cam is pretty good.
The botom image is harder to center and tolerance is more than 0.05mm.
Problems?
for both images I should use better light at 1'st place.
Centering the hole is 'easy' work to jog near center and then size circle to fit hole. The drawback is image size when 'size' slider is visible. it's such reduced...
The slot centering is harder as just little arc touching the image edge.
The problem solution?!
I see solution for slot centering to have other one croshair aperture (not circle) but two lines in offset from centerline. The ofset is adjusted like 'size' for circle and there are need to other one adjuster named angle. So we can folow angle and set exact size.
Now as image is just little to small when all that widgets is oppened I think that that two sliders (size and angle) should be in panel like CamOffset is. (probably one above other where currently I have DRO) I can put here two sliders but I think the passing walue can be problematic.
Someone think that I go in right direction...?!?
Please Log in or Create an account to join the conversation.
- andypugh
-
- Offline
- Moderator
-
- Posts: 23475
- Thank you received: 4993
Now, one thing I have seen a similar setup do is find the centre of a circle from three points, so you could centre the crosshair on three points around the circumference and it would tell you where the middle is. This would be handy for finding the middle of bores that are too big for the field of view.
Please Log in or Create an account to join the conversation.
- eslavko
- Offline
- Elite Member
-
- Posts: 267
- Thank you received: 4
Nice!
Now, one thing I have seen a similar setup do is find the centre of a circle from three points, so you could centre the crosshair on three points around the circumference and it would tell you where the middle is. This would be handy for finding the middle of bores that are too big for the field of view.
Good idea.
Anyway I have one more button in mind. Do not know how to implement it yet but WANT it here. In EMC is one script named Teach-in.py. It's used to save current coordinate to file. I use it a lot but is unpractical handling. EMC must be started 1'st and then that script in 'right environment'. Thew we have two window's flying around screen. One is EMC itself and other has no more than one button to save coordinates. But with WEBCAM we want as big as posible image so windows overlaps. So my idea id to have one buton to just append current coordinate to file. Ie action should be 1.Open predefined file 2.Save (append to the end of the file) current coordinate 3.close file. Then whatever application can use that coordinates as is needed. So little deeper in menu can be button to recalculate center from last 3 entry's or from last 4 entry's (and to show missalignment.) or anithing similar.
Please Log in or Create an account to join the conversation.
- andypugh
-
- Offline
- Moderator
-
- Posts: 23475
- Thank you received: 4993
EMC2 has a way to log positions to file (PROBEOPEN, filename.txt)
Please Log in or Create an account to join the conversation.
- eslavko
- Offline
- Elite Member
-
- Posts: 267
- Thank you received: 4
Have a look at linuxcnc.org/docs/html/gcode_main.html#s...38.2:-Straight-Probe
EMC2 has a way to log positions to file (PROBEOPEN, filename.txt)
I know that Andy.
But if I use Camera instead probe then I must JOG to the correct position and click some button or similar to signal that 'probe' is in place. The output should be some file as is practical for some other applications. I find PROBEOPEN to be problematic as it overwrite the old file and had to be manualy oppened and closed.
So I like to startup EMC and JOG to position and click 'SaveLocation' button, then jog to next position and click. and so for many locations.
In each click I wan't to be file oppened for adding (not overwrite) position saved and file closed.
After few JOGs I have coordinate's in end of the file and can call some 3'rd party software to do something with it. For example:
I has saved last 4 coordinates for 4 holes in corners of printed circuit board. As I have no reference I just start custom program and read last 4 positions, then fit that to the image of PCB onscreen and I got perfectly scaled and rotated G code for drilling.
For now I use teach-in and if I forget to exit that utility I got problem as my application read nonsense value from file already oppened and can mess all thing if I don't see difference. (that's reason why I don't want oppened file until manualy closed)
Of course running other application like centerfinder will find the center of hole by last few (selected) point's.
I find Webcam very ussable as save a lot of time. But to work like that it must be permanently on machine not as attachment to put in spindle.
Please Log in or Create an account to join the conversation.
- eslavko
- Offline
- Elite Member
-
- Posts: 267
- Thank you received: 4
Please Log in or Create an account to join the conversation.
- eslavko
- Offline
- Elite Member
-
- Posts: 267
- Thank you received: 4
All button's now work. And little explanation What can do and how.
The top slider resize aperture (circle here in image but can be paralel lines too)
The botom slider change angle of aperture (usable with paralel lines as aperture)
G43H99 checkbox Just do what is says. Ie introduce offset for camera (is not mounted on spindle) and move machine to camera just see position was under the tool. (When unchecking the all is done in reverse - the tool goes where cam was)
SaveXYZ Button just save coordinates to the file (log) so some tracing is possible and some other things can be done too. The last 4 coordinates are saved in internal variables too.
Center3 button means that clicking on that machine find center of circle from last 3 points and Center4 button is for centering with 4 points (top, bottom and left, right).
All that with great help from Pavel Shramov (psha) Thanks.
Please Log in or Create an account to join the conversation.
- eslavko
- Offline
- Elite Member
-
- Posts: 267
- Thank you received: 4
(just little comment on picture. The micrometer is oppened to have 3um gap. So anybody can see how precise cheap webcam can be.)
The system works on Ubuntu Hardy heron and EMC2 is version 2.5.0~pre (latest 2.4.x should work too).
So for the start we need to check if our cam is recongnized/woorking. So the right package is 'camview' and is available form web. (link)
If cam is working then just save that configuration (from camview) to file 'camviewcfg' in EMC2 machine folder.
Now we need the 'camview-emc' package (link)
Then we need to say AXIS that we want CAMERA tab and this is way how to get it.
Edit the machine INI file and add in [DISPLAY] section
[DISPLAY]
EMBED_TAB_NAME = CAM_View
EMBED_TAB_COMMAND = camview-emc -C camviewcfg -w {XID}
Start EMC and there should be camera window.
So the next steep is to add some widgets in that window. Change the line from
EMBED_TAB_COMMAND = camview-emc -C camviewcfg -w {XID}
to
EMBED_TAB_COMMAND = camview-emc -C camviewcfg -g togle-caa.ui -H campins.hal -w {XID}
and download the file 'togle-caa.ui' from (link). The file can be created with GladeVCP too.
And we need to make another HAL file for cam support. The file should be in machine INI folder.
Here is my version of that file. The OneShoot is needed to create just right sequence for executing subs
'
campins.hal file
#CamView pins
loadrt oneshot names=forOn,forOff
addf forOn servo-thread
addf forOff servo-thread
setp forOn.width .1
setp forOff.width .1
setp forOff.falling 1
setp forOff.rising 0
net forOnNet camview.hal_checkbutton1 => forOn.in forOff.in
net cam1 forOn.out => halui.mdi-command-00
net cam2 forOff.out => halui.mdi-command-01
net cam3 camview.hal_button1 => halui.mdi-command-02
net cam4 camview.hal_button2 => halui.mdi-command-03
net cam5 camview.hal_button3 => halui.mdi-command-04
'
we must add the few lines to machine INI file in HALUI section
[HALUI]
MDI_COMMAND=o<_camon>call
MDI_COMMAND=o<_camoff>call
MDI_COMMAND=o<_camstore>call
MDI_COMMAND=o<_camcenter3>call
MDI_COMMAND=o<_camcenter4>call
Every action just start that custom file located in PROGRAM_PREFIX folder.
And my files are:
_camon.ngc
When checkbox (G43H99) is checked this is executed.
It moves the machine in such way to position camera in place where tool was before.
The camera offset (from tool holder) is defined as Tool 99 offset in tolltable.
'
o<_camon> sub
g92 x0 y0 z0
g92.2
#<_CamOfsX> = #5211
#<_CamOfsY> = #5212
g92.1
g43 h99
g92 x0 y0 z0
g92.2
#<_CamOfsX> = [#<_CamOfsX> - #5211]
#<_CamOfsY> = [#<_CamOfsY> - #5212]
g92.1
g91 g0 x#<_CamOfsX> y #<_CamOfsY>
g90
o<_camon> endsub
M2
'
_camoff.ngc
When checkbox (G43H99) is unchecked this is executed.
It moves the machine in such way to position tool back where camera is pointing.
'
o<_camoff> sub
g43 h99 g91 g0 x[-#<_CamOfsX>] y-[#<_CamOfsY>]
g90 g49
o<_camoff> endsub
M2
'
_camstore.ngc
When SaveXYZ is clicked the machine store current position in file and preserve last 4 coordinate as variables too
The EMC2 should be patched to have LOGAPPEND command available. (Latest version should already be patched)
'
o<_camstore> sub
g92 x0 y0 z0
g92.2
#3999=[#3999+1] ;next parameter
O100 if[#3999 EQ 1]
#<_CamX1> = #5211
#<_CamY1> = #5212
O100 endif
O101 if[#3999 EQ 2]
#<_CamX2> = #<_CamX1>
#<_CamY2> = #<_CamY1>
#<_CamX1> = #5211
#<_CamY1> = #5212
O101 endif
O102 if[#3999 EQ 3]
#<_CamX3> = #<_CamX2>
#<_CamY3> = #<_CamY2>
#<_CamX2> = #<_CamX1>
#<_CamY2> = #<_CamY1>
#<_CamX1> = #5211
#<_CamY1> = #5212
O102 endif
O103 if[#3999 GE 4]
#<_CamX4> = #<_CamX3>
#<_CamY4> = #<_CamY3>
#<_CamX3> = #<_CamX2>
#<_CamY3> = #<_CamY2>
#<_CamX2> = #<_CamX1>
#<_CamY2> = #<_CamY1>
#<_CamX1> = #5211
#<_CamY1> = #5212
#3999=4
O103 endif
(LOGAPPEND,_CAMlog)
(LOG, X=#5211, Y=#5212, Z=#5213)
(LOGCLOSE)
g92.1
(MSG, CAM position stored.)
o<_camstore> endsub
M2
'
_camcenter3.ngc
When Center3 is clicked the last 3 saved point is used to calculate circle center.
The routine isn't perfect and throw Nonsense coordinates when can't calculate it.
(in most case this is when X or Y coordinates of point lie in same line.) The machine does move to the calculated center!
'
o<_camcenter3> sub
O99 if[#3999 GE 3]
#<ok> = 0
#<m1>=[#<_Camy2> - #<_Camy1>]
O100 if[#<m1> EQ 0]
#<m1>=1
#<ok>=1
O100 endif
#<m2>=[#<_Camy3> - #<_Camy2>]
O101 if[#<m2> EQ 0]
#<m2>=1
#<ok>=1
O101 endif
#<m1> =[[#<_CamX1> - #<_CamX2>] / #<m1>]
#<m2> =[[#<_CamX2> - #<_CamX3>] / #<m2>]
#<ix> =[#<m1> - #<m2>]
O102 if[#<ix> EQ 0]
#<ix>=1
#<ok>=1
O102 endif
#<b1> =[#<_CamY1> + #<_CamY2>] / 2] - [#<m1> * [#<_CamX1> + #<_CamX2>] /2
#<b2> =[#<_CamY2> + #<_CamY3>] / 2] - [#<m2> * [#<_CamX2> + #<_CamX3>] /2
#<ix>=[[#<b2> - #<b1>] / #<ix>]
#<iy>=[#<m1> * #<ix> + #<b1>]
O200 if[#<ok> EQ 0]
G0 X[#<ix>] Y[#<iy>]
(MSG,Centered)
O200 else
(MSG,Nonsense coordinates!)
O200 endif
#3999 = 0
O99 else
(MSG,Must have 3 points saved!)
O99 endif
o<_camcenter3> endsub
M2
'
_camcenter4.ngc
When Center4 is clicked the last 4 saved point is used to calculate center coordinate.
This one is pretty stupid as just expect left-right and up-down pair and find middle position from that. The machine move here!
'
o<_camcenter4> sub
O99 if[#3999 EQ 4]
#<ok> = 0
O100 if#<_CamX1> EQ #<_CamX2>] AND [#<_CamY3> EQ #<_CamY4>
G0 X[[#<_CamX3> + #<_CamX4>]/2] Y[[#<_CamY1> + #<_CamY2>]/2]
#<ok>= 1
O100 endif
O101 if#<_CamX3> EQ #<_CamX4>] AND [#<_CamY1> EQ #<_CamY2>
G0 X[[#<_CamX1> + #<_CamX2>]/2] Y[[#<_CamY3> + #<_CamY4>]/2]
#<ok>= 1
O101 endif
O200 if[#<ok> EQ 1]
(MSG,Centered)
O200 else
(MSG,Nonsense coordinates!)
O200 endif
#3999 = 0
O99 else
(MSG,Must have 4 points saved!)
O99 endif
o<_camcenter4> endsub
M2
'
That's all.
And the big thanks to Pavel Shramov (psha)
Please Log in or Create an account to join the conversation.
- eslavko
- Offline
- Elite Member
-
- Posts: 267
- Thank you received: 4
Please Log in or Create an account to join the conversation.
- marzetti
- Offline
- New Member
-
- Posts: 9
- Thank you received: 0
Thanks,
Greg
Please Log in or Create an account to join the conversation.