svenhb / GRBL-Plotter

A GCode sender (not only for lasers or plotters) for up to two GRBL controller. SVG, DXF, HPGL import. 6 axis DRO.
https://grbl-plotter.de/
GNU General Public License v3.0
669 stars 176 forks source link

Get the height information of a work piece by a camera #36

Closed wwwlxs closed 5 years ago

wwwlxs commented 5 years ago

Hi Svenhb ,Can get the height information of a work piece by an USB camera’s focal distance information to getting height map data instead of the probe for faster processing?

wwwlxs commented 5 years ago

or use kinect/intel realsense dephth camera

svenhb commented 5 years ago

Finally you want an external height measurement to do offset of z axis? -How to readout camera’s focal distance information ? Sounds not very accurate. -Connecting a kinect sounds like overkill Perhaps you build an external device an connect it via "DIY control" (https://github.com/svenhb/GRBL-Plotter/wiki/DIY-control), Then I need to implement some new commands to process the information.

wwwlxs commented 5 years ago

Hi Svenhb ,Can get the height information from panasonic HG-C series measurement sensor? As compact as a photoelectric sensor, the CMOS laser sensor allows to display actual measured distance as accurately as a displacement sensor. https://www.panasonic-electric-works.com/se/hg-c-measurement-sensor.htm

svenhb commented 5 years ago

It may work, but I don't get the desired application: Usually you want to know the distance between tip of tool and workpiece at an given Z-pos. to compensate tool-offset (each tool shows different length when fixed in spindle). Then your sensor needs to measure bottom up the tip of the tool - does it work? Then you need to read the distance and put in manually into software. Or how to get the distance-information into GRBL-Plotter? (perhaps via 'DIY-Control').

Or shows the tool always the same offset and you just need to know the Z-pos of the workpiece surface? To adapt any kind of sensor, you need to build the hardware, which can be connected via COMx to the PC, sending the height information in an known format. Then I can make an interface to read and process the information.

wwwlxs commented 5 years ago

or CX-441 | Compact Photoelectric Sensor https://www3.panasonic.biz/ac/e/search_num/index.jsp?c=detail&part_no=CX-441

wwwlxs commented 5 years ago

Hi sven, There is an USB Data Acquisition Module to adapt the panasonic HG C1050 sensor,which can be connected via COMx to the PC, and sending the height information to PC in an TXT/Excel format by Labview app. It can send height data to a computer tens or thousands of times per second,But how can I combine the height data with the xy coordinates of the current position by Grbl-plotter app? Thus forming a height map.Or how to get the distance-information into GRBL-Plotter via 'DIY-Control?

wwwlxs commented 5 years ago

USB Data Acquisition Module 768ace2e-fba7-4ddb-b5d7-b212cbdcd443 ee2e2348-1d29-406d-9af6-52275516d309 ecc8d971-e05b-4488-8b95-ff78945fb0b2

wwwlxs commented 5 years ago

this is USB Data Acquisition Module video USB Data Acquisition Module mp4.zip

svenhb commented 5 years ago

I think there are two options:

  1. a lot of work for me to get and process the external height data. Because it's not compatible with the current implementation - see below.
  2. you write your own software, perhaps using the 'DIY-Control' interface. You then send xy coordinates to GRBL-Plotter, wait for idle, then check and save your height information in the format you like...

The current implementaion is: I move the specific XY position and start probing, the probing answer from grbl-hardware ([PRB:0.000,0.000,0.000:0]) triggers my heigth-measurement module to store the height information.

wwwlxs commented 5 years ago

Thanks for your help!

wwwlxs commented 5 years ago

happy new year!svenhb now i use another Arduino to send heigth-measurement (Z position with "mm") to "diy-control"interface real time, could you help me to take the heigth-measurement from"diy-control"to heigth-measurement module to store the height information instead of the probing answer from G38.3?

svenhb commented 5 years ago

Check the wiki: https://github.com/svenhb/GRBL-Plotter/wiki/DIY-control You should receive the actual Position ca. each 1/5 second. You can calculate the needed movement or action by yourself and send any gcode to set new offset.

wwwlxs commented 5 years ago

thanks i conect panasonic HG C1050 sensor to Arduino UNO, than send the actual Position to 'DIY-Control' with this code:

void setup() { Serial.begin(115200); }

void loop() { float distance; distance=map(analogRead(0),0,1023,-1500,1500); Serial.println(distance/100); delay(100); }

wwwlxs commented 5 years ago

and the DIY-control display height information like this:

Open COM18 < -8.82 < -8.82 < -8.85 < -8.91 < -8.85 < -8.85 < -8.85 < -8.85 < -8.82

svenhb commented 5 years ago

What do you need to do? Perhaps you send "G0 Z8.82" to move Z and bring you measurement close to zero? Or send "G92 Z0 " to set Z to zero right now Or send "G92 Z-8.82 " to set Z to your measurement

But you should not do it frequently every 100ms. Perhaps a trigger is needed from the GCode which will be processed?

svenhb commented 5 years ago

If a trigger is needed, a custom button could be programmed with a specific command, hidden in a GCode-comment, perhaps "($TRG1)" which could then lead to a message via the DIY control like "[TRG1]".

In a next version I will support this: Any single string from a custom button like "($abc)" will be sent via DIY-Control as "[abc]"

wwwlxs commented 5 years ago

Thank you very much!I think there are 2 designs to avoid moving the z-axis, which saves a lot of time: The first is to increase the way to get the z-position information in the grbplotter's height-map module. The position of the previous z is g38.x feedback, and now it is changed to the instantaneous z value received directly from the diy-control. This z value (in millimeters) is sent by the second Arduino through another COM. The second is Directly modify the motion module of g32.1-38.4 of grbl firmware, and replace their motion mode with "get the z value of the second arduino"

wwwlxs commented 5 years ago

Maybe send "G92 Z-8.82 " to set Z value? to make the heightmap like this: `<?xml version="1.0" encoding="utf-8"?>

-8.82 -8.82 -8.85 -8.91 -8.85 .............`
svenhb commented 5 years ago

Ahh, you want to genrerate a height-map from your z-values? Then I should modify the code for surface-scan to ask for the alternative Z-value instead of performing G38.3 ... You may send frequently the actual height as "Z-8.82" to the DIY-Control and I will take over this value for the height map...

wwwlxs commented 5 years ago

Yes, I want to genrerate a height-map from z-values by sensor,the second Arduino send hundreds of the actual height per second to Diy-control,so it just only moving XY-axis and avoid moving the z-axis by G38.3 to get the actual height.This will increase the speed by hundreds of times and save a lot of time to creat height map。

svenhb commented 5 years ago

I found following solution (in next version): you send your values in the format "(PRB:Z-5.12)" - in brackets to be processed as comment by grbl (if no streaming, this data is passed through the arduino and would move the z axis). If GRBL-Plotter received a valid message, the original probing z-value will be replaced by the new one. To speed up probing you set "Max-depth" to 0.01 and "Save height" to 0. So I don't need to change my workflow with probing.

wwwlxs commented 5 years ago

If I set "Max-depth" to 0.01 and "Save height" to 0, the z-axis will move 0.01mm, Does the machine shake and affect accuracy? OK,thanks svenhb!I am looking forward to the arrival of the next version.

svenhb commented 5 years ago

Good hint...I made a work-arround to avoid G38. Set Max-depth to 0, then an internal flag will be set. After reaching new position (status switches to IDLE) the Z value from DIY-Control will be read, so synchronization is possible (check for <IDLE, send Z value)

wwwlxs commented 5 years ago

ok,thanks svenhb!

wwwlxs commented 5 years ago

ok,thanks svenhb!

svenhb commented 5 years ago

Implemented in Version 1.2.3.x, please check functionality

wwwlxs commented 5 years ago

thanks! when ,open diy-control,"COM CNC' windows and "DIY-control"window are blinking all the time,and can not open the"creat height map'

wwwlxs commented 5 years ago

it sucessfull!thanks!thanks svenhb!

svenhb commented 5 years ago

when ,open diy-control,"COM CNC' windows and "DIY-control"window are blinking all the time,and can not open the"creat height map'

Is it still a problem? I need more information, you may have screenshots?

wwwlxs commented 5 years ago

i upload the screenshots to github but it fail,i can upload the video an screenshot to my instagram:instagram.com/wwwlxs

wwwlxs commented 5 years ago

it sucess now!faster than ever! i can send the screenshot to you email.

svenhb commented 5 years ago

I registered to instagram right now... But mail is also ok. I'm grblplotter

svenhb commented 5 years ago

Thanks for sharing. Why text font is different to my settings? Text is too long... Is it default on your PC or did you change something? image

wwwlxs commented 5 years ago

it default on my pc.my pc is macbook pro2009 with 1280x800pix,the UI and font on windows 7 can not display well

svenhb commented 5 years ago

Most text is written in the font "Microsoft Sans Serif". Perhaps you need to install this font?

wwwlxs commented 5 years ago

If the software can arrange the windows like the Photoshop UI, using a scalable windows, it should be fine. It would be better if there is a Mac OS version. In addition, ‘scan-heightmap’ will pause every point to read the Z-axis , and then read the information of the next point. If it does not stop, the speed will be faster. Sometimes such a message pops up:‘offset and lenght were out of bounds for the array or count is greater than the numbers of element from index to the end of the source collection’,Probably because of ‘delay(<200)’.

svenhb commented 5 years ago

It would be better if there is a Mac OS version.

Not from me - sorry

If it does not stop, the speed will be faster.

Also not possible - then you need a complete different algorithmus:
Move from line-beginning to line-end, in certain time-steps take a sample of the Z-value. Most probably time steps are still to long (isn't there a limit in windows of 20ms?). Perhaps you can speed-up acceleration $120 and speed $110 ?

Sometimes such a message pops up:‘offset and lenght were out of bounds for the array or count is greater than the numbers of element from index to the end of the source collection’,Probably because of ‘delay(<200)’.

What is your step-size in x and y or amount of data-points?
What do you mean with "Probably because of ‘delay(<200)’."?

wwwlxs commented 5 years ago

“Most text is written in the font "Microsoft Sans Serif". Perhaps you need to install this font?” ----yes ,I have installed "Microsoft Sans Seif",and it still shows the same effect

"Most probably time steps are still to long (isn't there a limit in windows of 20ms?). Perhaps you can speed-up acceleration $120 and speed $110 ?" ---setting:$110=2475and $120=200,$121=500

"What is your step-size in x and y or amount of data-points? ----Do you mean $110 setting? I setting $110=100,$0=10,$1=25

What do you mean with "Probably because of ‘delay(<200)’."?" -----The sencond Arduino print" (PRB Z-3.33)" to DIY-control then delay 200mS per time,it no problem. but if i setting "delay 10mS", a message pops up:‘offset and lenght were out of bounds for the array or count is greater than the numbers of element from index to the end of the source collection’

wwwlxs commented 5 years ago

Another issues:In "Setup-Graphics Import-G-code generation: Pen up/down traslation",When I chose "Z-Axis:Use Z-Axis and spindle" ,the"Z-Height save,"and"Z-height engrave" in G-code have nothings change when I "Apply Height_Map" from Surface scan.

E.g: Z-Height save:10;
Z-height engrave:-5;

(without Height map) G-code:

"( Text import by GRBL-Plotter ) ( G-Code lines: 156 ) ( Pen Down/Up : 17 times ) ( Path length : 0.0 units ) ( Duration ca.: 0.6 min. ) ( Conv. time : 00:00:00.0026323 ) G54 (Setup - GCode-Header) ( Text: 123 ) ( Font 'Serif bold italic' not found ) ( Using alternative font ) M05 G00 Z10.000 ( Char: 1) G00 X4.571 Y6.476
G01 Z-5.000 F1000 M3 S1000 G01 X2.667 Y0.000 F2000 G01 X3.429 Y0.000
M05 G00 Z10.000 G00 X5.714 Y8.000
G01 Z-5.000 F1000 ... "

when I apply Height-Map, g-code:

"( Text import by GRBL-Plotter ) ( G-Code lines: 156 ) ( Pen Down/Up : 17 times ) ( Path length : 0.0 units ) ( Duration ca.: 0.6 min. ) ( Conv. time : 00:00:00.0026323 ) G54 (Setup - GCode-Header) ( Text: 123 ) ( Font 'Serif bold italic' not found ) ( Using alternative font ) M05 G00 Z10.000 ( Char: 1) G00 X4.571 Y6.476 Z10.683 G01 Z-5.000 F1000 M3 S1000 G01 X3.619 Y3.238 Z-4.068 G01 X2.667 Y0.000 Z-3.823 G01 X3.429 Y0.000 Z-3.858 M05 G00 Z10.000 G00 X5.714 Y8.000 Z10.524 G01 Z-5.000 F1000 M3 S1000 G01 X4.952 Y6.476 Z-4.342 G01 X4.000 Y3.238 Z-4.089 G01 X3.048 Y0.000 Z-3.840 M05 ... "

"G00 Z10.000 "and "G01 Z-5.000 F1000" change nothing,So when the Pen down,it will move deeper than paper surface .

svenhb commented 5 years ago

I fixed it: https://github.com/svenhb/GRBL-Plotter/blob/master/GRBL-Plotter_1232_publish.zip

"What is your step-size in x and y or amount of data-points?

I mean the raster width for surface scan.

What do you mean with "Probably because of ‘delay(<200)’."?"

Did you try values between 100 and 200? Perhaps problem is my grbl refresh rate of 200ms (sending ?, receiving IDLE information)

svenhb commented 5 years ago

Perhaps you can speed up probing, using my first idea:

I found following solution (in next version): you send your values in the format "(PRB:Z-5.12)" - in brackets to be processed as comment by grbl (if no streaming, this data is passed through the arduino and would move the z axis). If GRBL-Plotter received a valid message, the original probing z-value will be replaced by the new one. To speed up probing you set "Max-depth" to 0.01 and "Save height" to 0. So I don't need to change my workflow with probing.

Because after probing response from grbl comes immediately, compared to the second version where we need to wait for IDLE response from ask of real time status report.

A quick test (11 x 11 raster points) without real hardware, just an Arduino with grbl, shows 14 seconds for 1st version (max depth = -0.01, sending G38, receiving [PRB:...) and 24 seconds for 2nd version (max depth = 0, waiting for IDLE).

With max depth = -0.001 I get 8 seconds....

wwwlxs commented 5 years ago

ok,thank svenhb,How to send the values to be processed as comment by grbl using 1st version?

svenhb commented 5 years ago

max depth =<0 (-0.001) -> verion 1 max depth = 0 -> version 2

wwwlxs commented 5 years ago

I mean my Z values sending to DIY-Control also in the format "(PRB:Z-5.12)" ?and set max depth to -0.001 in Surface scan windows?

svenhb commented 5 years ago

Yes keep your sent messages like "(PRB:Z-5.12)" and switch between max depth = 0 or <0 to switch between this two modes...

wwwlxs commented 5 years ago

yes!thanks! The 1st version faster than ever! Max depth can be set to-0.01,but can not be set to-0.001. I took a video on instagram

wwwlxs commented 5 years ago

Another iussus when apply height map: When Z value from height-Map bigger than Gcode Z value (Pen up /down by G00 ) ,the pen down then up ,and writting in the air. 在 2019年1月13日,上午1:54,Sven notifications@github.com 写道:

max depth =<0 (-0.001) -> verion 1 max depth = 0 -> version 2

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

wwwlxs commented 5 years ago

gcode and heightmap.zip

svenhb commented 5 years ago

Another iussus

ok thanks, I will check this soon.

wwwlxs commented 5 years ago

Thanks,Plotter suddenly stopped during the scanning height-map.After stopping suddenly, I can't continue and I have to rescan. COM window:

`[PRB:157.130,227.800,-12.875:0] [PRB:157.030,227.800,-12.875:0] [PRB:156.930,227.800,-12.875:0] < < !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! < error:24 More than one g-code command that requires axis words found in block."

< ok [PRB:156.730,227.800,-12.875:0] < ok < ok < ok`