LaserWeb / deprecated-LaserWeb1

Deprecated: use http://github.com/openhardwarecoza/LaserWeb3 instead
186 stars 45 forks source link

Need help implementing Gcode Writer to New DXF Library! #42

Closed prcdslnc13 closed 8 years ago

prcdslnc13 commented 8 years ago

Arcs and trimmed circles in polylines come out with incorrect radii or are skipped entirely when opening .dxfs. The .dxfs are generated in the latest version of DraftSight on windows 10.

arc-test.zip

ghost commented 8 years ago

Thanks, will invesigate, would be in millcrums dxf parser, dxf.js.

prcdslnc13 commented 8 years ago

acad output.zip

Tried a drawing from autocad and got similar but actually less consistent results. 1 of the arcs at the lower right corner actually output correctly, which is interesting.

ghost commented 8 years ago

Ties in with https://github.com/openhardwarecoza/LaserWeb/issues/27 to a degree

ghost commented 8 years ago

My personal workflow is sketchup -> Guitarlist plugin as polyline dxf -> Laserweb Sketchup renders arcs and circles as line segments anyway - always much easier. Arcs is tough, since the standard is "each has their own standard"

ghost commented 8 years ago

https://github.com/openhardwarecoza/LaserWeb/blob/master/i/millcrum/inc/dxf.js#L201 would be where to start digging, along with http://www.autodesk.com/techpubs/autocad/acad2000/dxf/arc_dxf_06.htm and some sample files to check. Anyone want to help?

ghost commented 8 years ago

@prcdslnc13, in autocad, can you try https://knowledge.autodesk.com/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2016/ENU/AutoCAD-Core/files/GUID-0C422AA9-23DD-4650-AD66-68E9D7989E3F-htm.html = split the Arcs into Polylines? Revert with feedback

I fixed a bug in the 3D viewer's handling of G3 arcs, but still looks like a DXF parser issue in your case

ghost commented 8 years ago

@buserror - I note you too have been playing with Millcrum.

Any chance you can assist in fixing some bugs in the Arc handling - Andrew doesnt want to spend any time on it anymore and I don't have the skills

prcdslnc13 commented 8 years ago

@openhardwarecoza that is actually what I do for all these. It makes LaserCAD and most of the CNC software I use work right. Ill pull down the latest version, Im curious what happens when I explode the lines and what they look like. But right now everything is a poly line.

prcdslnc13 commented 8 years ago

@openhardwarecoza exploded lines and arcs dont process at all so thats a bad plan. I did a quick try of different dxf versions. r12 2000-2002, 02-04, and 2013 in both binary and ascii. Binary didnt process at all in any of the versions. R12 didnt bring the polylines over. The 00-02, 02-04 versions had the issue I sent earlier. I typically use 00-02. The 2013 failed. I can try again and copy some of the errors if its useful. Sorry I looked at the code but I am not a coder by heart so its a bit over my head. I sent it to a fiend of mine thats a big js guy. He may or may not be able to help.

cojarbi commented 8 years ago

Some DXF with arcs, done in inkscape. Export via regular save as and openscad dxf output plugin Archive.zip

buserror commented 8 years ago

@openhardwarecoza well not sure, I submitted a small merge request a few weeks ago and he hasn't replied, or merged so I don't see the point at the minute..

ghost commented 8 years ago

Thanks @buserror , sadly https://github.com/openhardwarecoza/LaserWeb/issues/27#issuecomment-167587329 is the reason I guess. Well, I'll follow you here (: If you do anything cool with CAM let me know (:

ghost commented 8 years ago

Ok, so today I sat down and started playing with this:

  1. I added https://github.com/gdsestimating/dxf-parser
  2. I set it to run when a DXF is opened https://github.com/openhardwarecoza/LaserWeb/blob/master/i/main.js#L1192 (before the cutting params / gcode step here https://github.com/openhardwarecoza/LaserWeb/blob/master/i/main.js#L1290 -> https://github.com/openhardwarecoza/LaserWeb/blob/master/i/main.js#L1298) just to see what it parses
  3. Initial impression, AWESOME: Picks up my most complicated DXF and draws it perfectly;

large dxf

  1. I compared the raw data from both MC's dxf parser and from the new one: https://github.com/openhardwarecoza/LaserWeb/blob/master/i/dxf/renderer.js#L175 and from https://github.com/openhardwarecoza/LaserWeb/blob/master/i/millcrum/dxf.js#L262

Both find the same data ... so millcrum's dxf.js isnt broken too badly in the parsing department - it is lacking a few entity types though so I think we will move away from it still if possible (plus upstream support is a big plus we need - someone who actually merges pulls, and helps fix bugs)

Where MC then presumably chokes completely would be in the code where it takes 'arcs' and converts them to 'polylines' or rather a bunch of G1 moves. We don't really need that, I think. Grbl, Marlin, Smoothie all have G2/G3 arc support? I presume MC used the lines to more easily calculate paths (since the original purpose of dxf.js was to parse dxfs to millcrum for use on millcrum.com - not really as a direct to gcode generator)

So to push forward with this we need to take: https://github.com/openhardwarecoza/LaserWeb/blob/master/i/dxf/renderer.js and for each of:

https://github.com/openhardwarecoza/LaserWeb/blob/master/i/dxf/renderer.js#L113 https://github.com/openhardwarecoza/LaserWeb/blob/master/i/dxf/renderer.js#L173 https://github.com/openhardwarecoza/LaserWeb/blob/master/i/dxf/renderer.js#L259 (Text is a tricky one - easy to do in three.js but not easy to do in gcode) https://github.com/openhardwarecoza/LaserWeb/blob/master/i/dxf/renderer.js#L241 (solid - I dont think we want to support that one) https://github.com/openhardwarecoza/LaserWeb/blob/master/i/dxf/renderer.js#L204

we need to just add gcode writers (currently it creates three.js objects)

simply gcode += 'G.......F....' is all I need to integrate it deeper into laserweb...

My new setup would then be (since this can draw straight to three.js)

  1. Open DXF
  2. Run the parser and draw these to three.js, each layer in a different color! Also at this time generate the gcode moves and store with placeholders for laser power/speed (s+= 'G1 ....' )
  3. Open the cutting params modal (its draggable) and you can see the colors on the layers as well as the canvas - so you can visually select params to match for the layers you want
  4. When you click Prepare for cutting, we parse the s= ' ' data and replace the placeholders for S???? and F???? with the values selected in the modal (just like we do now - except now we place those into MC code then run MC to convert that to gcode. If we have gcode already in step 2 we save a step! and several seconds)
  5. Later we can add optimisation like traveling salesman. For laser even keeping "paths" in an object is pointless - its not like a CNC that run in paths to do chip clearing etc - so technically we could just do nearest next G1 move (; - realistically though we'd start from the inside and work our way out - small circles first - but thats laters worry
ghost commented 8 years ago

@bzuillsmith - we love your library!

ghost commented 8 years ago

@cojarbi - this new library even opens the Inkscape DXFs! WOW!

inkscape

ghost commented 8 years ago

dxfs.zip

heres a few trouble DXFs you can test with - laserweblogo works in Millcrums doesnt work in dxf-parser+https://github.com/gdsestimating/three-dxf) (Because dxf-parser/three-dxf does not have polyline support - see https://github.com/gdsestimating/three-dxf/issues/1) - hope we can help the upstream author and add it (:

The rest works not at all in millcrum (or works but displays totally wrong) but draws really nicely in dxf-parser+https://github.com/gdsestimating/three-dxf)

cojarbi commented 8 years ago

Will try it today

ghost commented 8 years ago

@cojarbi read the rest of what i wrote above it. Nowhere near testing phase. We know it can read it. But its not spitting gcode just yet

bzuillsmith commented 8 years ago

@openhardwarecoza Thanks! Haven't had as much time to continue developing three-dxf (just had a baby!) but if you post some issues, I will certainly continue to do so when I have time. I also take pull requests. Posting some issues to dxf-parser and three-dxf would also motivate me to continue the work. I think it mainly handles lightweight (LW) dxf entities and not the more complex stuff yet.

ghost commented 8 years ago

Congrats on the little one! Mines turning 6 this year. Sleep does return! But i will be very forgiving of slow Replies (:

Your lib is knocking the socks of the one we use at the moment. Just need to sit down, crunch through, and add the gcode writers. But having three.js in there (and its already a big part of laserweb) just fits the two together like a glove!

ghost commented 8 years ago

Ps: if you have a to do list, open an issue on your projects. We have around 10-12 people here contributing code and about 20+ testing (: - would be beneficial to plough back some effort to you too (:

bzuillsmith commented 8 years ago

Great, Just opened a couple. The biggest ones are about block insert support. Currently they are not supported, but I don't think it would take too much effort to get some basic block support going.

bzuillsmith commented 8 years ago

PS: I also enjoy pair/mob programming, so if any of you would like to do that for any dxf-parser/three-dxf stuff, you can find me on Google Hangouts

ghost commented 8 years ago

(: better than teaming up with a rubber ducky

ghost commented 8 years ago

https://github.com/gdsestimating/three-dxf/issues/1 explains why laserweblogo.dxf in the zipped samples above doesnt show up (: - thats just polylines

kaosat-dev commented 8 years ago

Also started taking a closer look at the code & issue, thanks for the detailed writeup & examples !

ghost commented 8 years ago

I finally got the SVG issues sorted, so hopefully I can start looking at this one soon (:

ghost commented 8 years ago

Hi All.

Just checking in if anyone has made any headway with adding gcode output

(https://github.com/openhardwarecoza/LaserWeb/issues/42#issuecomment-170259893 relates)

@kaosat-dev @bzuillsmith

We have a potential sponsor for an extra laser diode, @cojarbi approached JJohnson@jtechphotonics.com - hold thumbs. It could go to the community to help polish out this feature

ghost commented 8 years ago

I've commented out the new lib for the time being - new users got tripped up when they see a render.

As a side note, any Fusion 360 users who can test drive this and report back?

https://apps.autodesk.com/FUSION/en/Detail/HelpDoc?id=appstore.exchange.autodesk.com%3Adxfsplinetopolyline_windows64%3Aen

athulsnair commented 8 years ago

Got an error while cutting a Dxf file material thickness=6mm Z down per pass=2 circle.zip

Machine stopped during the 3rd pass error: Bad number format

dxf file generated using sketchup and scaled down to 20% in laserweb

@openhardwarecoza that app didn't work for me, I will try again

ghost commented 8 years ago

Thanks for the feedback (: - would have been nice if it did. No worries, @bzuillsmith 's three-dxf has no problems reading it, so we just need to add the gcode writing (;

I'll check the circle shortly

ghost commented 8 years ago

Something is changing the S param during scaling. Bug indeed but not in the DXF, thats in the transform tool! Will fix asap

ghost commented 8 years ago

I have asked @johnlauer over in thread on https://groups.google.com/forum/#!topic/chilipeppr/VWho6tuvLJM about the possibility of working together on getting dxf support into CP (first)

ghost commented 8 years ago

@kaosat-dev @bzuillsmith - i had a sponsor approach me today and he offered a new 40w CO2 Tube + Mirrors to me to donate to a contributor. As soon as he offered, this issue sprung to mind. Any chance either of you would be up for some free bounty in exchange for adding gcode output to three-dxf (or a new library based off it) - we have so much success parsing test dxfs with @bzuillsmits 's dxf-parser and three-dxf, its really just gcode output thats missing.

funinthefalls commented 8 years ago

If your bribe of the 40W tube is not wanted, I could really use a new tube, mine has just about completely failed. Can barely engrave, let alone cut anything. I wouldn't need the mirrors, my mechanicals are all working good.

ghost commented 8 years ago

Hi Guys

@johnlauer released a new SVG -> Gcode widget for Chilipeppr today that contained some golden code! A function to take three-js geometry from a three-js group and convert it to gcode! See https://github.com/chilipeppr/widget-svg2gcode/blob/master/widget.js#L452

This was part of the missing link we have had so far. @bzuillsmith 's library already works perfectly to get dxf data into three-js geometry. Three.js already contains code to do the heavy lifting of breaking arcs/circles into line segments (https://github.com/mrdoob/three.js/blob/ddab1fda4fd1e21babf65aa454fc0fe15bfabc33/src/extras/geometries/CircleBufferGeometry.js - also a big thanks to Ben for pointing this out to me) so with John's code, the magic storm is brewing and we are very very close to having the best DXF -> gcode parser the world has ever seen!

So far I have a tat for tat equivalent to the old millcrum code so good riddance to that (; - I'll make the frontend switch today

What is still broken is that the line segments in arcs/circles above are drawn relative to point 0,0,0 at the moment - and LocaltoWorld() function of DXF doesnt seem to be able to find their world coordinates.

Investigating, but i am already celebrating. Fixing this will be easier than fixing the old millcrum code, and most of the hard work of a new DXF library is done

funinthefalls commented 8 years ago

Great job Peter! This was an important function to get working, and it seems that you are almost all the way there.

prcdslnc13 commented 8 years ago

This is awesome news! I've been head hunting people but have had issues finding people that are as interested in this stuff as we are. Glad you are making headway Peter!

On Mon, Feb 29, 2016 at 10:33 AM, Anthony Bolgar notifications@github.com wrote:

Great job Peter! This was an important function to get working, and it seems that you are almost all the way there.

— Reply to this email directly or view it on GitHub https://github.com/openhardwarecoza/LaserWeb/issues/42#issuecomment-190279184 .

Thanks, Joe Spanier

       "*No Trees were harmed in the sending of this email, but a great

number of electrons were terribly inconvenienced" *

ghost commented 8 years ago

And this now LIVE!

I temporarilly disabled OpenJSCAD (will switch it to the new toolchain over the next few days) - but please jump in and start testing DXFs!

If you find funnies, post the DXF in a new issue. Closing this Issue since it is now WRITTEN!

PS: You all owe @johnlauer a beer!