addam / Export-Paper-Model-from-Blender

Python addon for creating paper models in Blender (development version)
https://blenderartists.org/t/export-paper-model/476597
408 stars 55 forks source link

Add support for exporting GCODE #59

Open manthrax opened 6 years ago

manthrax commented 6 years ago

In a perfect world.. I could take these designs and send the gcode to my cutter/engraver! The interior polygons could use 50% laser strength to merely score the material, and then the end of the cutting pass would cut out the exterior at full power. This would be soo cool, since you could completely automate the process of turning a Blender model into a craftable object!

LOVE THIS PLUGIN BTW!!

addam commented 6 years ago

I'd love to do this and it seems quite easy to do, but I don't have a CNC.

If I write the code, will you test it for me? It may take a few trials and errors before we get this right.

alpharesearch commented 6 years ago

You don't need any hardware. Have a look at camotics.org to simulate a 3 axis CNC via OSS. With this software, you can test the GCODE output all day long... ;-)

addam commented 6 years ago

Markus, thanks! Unfortunately, Camotics doesn't work for me out of the box, it gets stuck in an infinite loop. I'll have to build and debug it, apparently.

alpharesearch commented 6 years ago

Long time that I used this program. Last time the name was still OpenSCAM, probably good idea to rename it. The Debian package I just downloaded from the web site and installed is definitely not up to the Debian standards... I had to manually install libv8-3.14.5... but after that it started up and it's running ok. I'm using Linux Mint 18.3. What OS are you using?

Treehee commented 6 years ago

I'm currently digging into this, and I wonder; is there anything other than surface speed that I should let the user choose (when working with laser cutters)?

alpharesearch commented 6 years ago

I would say you can use X and Y speed to change things (cutting/scoring) for some machines that have manual laser power settings. But many lasers have strength settings that can also be controlled via GCODE. You also want a travel speed setting when not cutting. The Z axis may need to be set on the beginning so the laser focuses on the paper and one more time on the end to move out of the way. But again not all machines have a Z axis. I'm not the expert anyway, if someone is reading this that knows more please add to the conversation. I have a project here on Github that converts bitmaps to gcode for laser engraving. You may want to have a look at that.

Treehee commented 6 years ago

I meant what variables are important for the user to set while exporting? So far I came up with; surface speed (in m/min) feed rate (not entirely sure what this does on a laser cutter? Could you explain that to me?) pierce strength (in seconds of max laser power. This is done on stronger materials when starting a cut from what I found when researching the topic. It basically burns a hole in a material so it can then cut from that hole)

Treehee commented 6 years ago

@alpharesearch are laser cutters able to cut at an angle?

alpharesearch commented 6 years ago

The feed rate G01 is used for cutting or with a laser on, this is normally slower than feed (seek) rate G00 that is used to rapidly reposition. On GCODE lines you can overwrite the default feed rate with the F parameter. Here is the parameter I can think about:

Regarding the angle, most laser cutters are 2 (XY) or 3 axes (XYZ), the laser is positioned above the XY and shines straight down. There is no 4 or 5 axis to rotate the laser as far as I know. With the Z axis, you focus the laser by moving up/down. But if you look at cutting a circular look at G02/G03. And G04 can be used to dwell.

Treehee commented 6 years ago

@alpharesearch with feedrate I meant G99 and could you explain to me what it actually does? CAMotics throws an error if I don't define a feedrate.

Treehee commented 6 years ago

Ooooh engraving would be usefull for the numbers, arrows, and other text

alpharesearch commented 6 years ago

Check out this Wikipedia GCODE link. Looks like G99 is for lathes and the feedrate per revolution... not sure why CAMotics needs this? Like all controllers support G00 and G01 and you can do pretty much everything with these codes. Other codes like G41 may not be supported. But you can account for that with a corrected G01 output. I don't this G50 will be doing what you think... some controller implementation use Z for cutting but may don't move the Z axis. Other use the S spindle speed. There is not just one standard and implementation. You would need to look for example at GRBL or some other controller to see what is supported...

Treehee commented 6 years ago

@alpharesearch I was already using that link 😄 And yes, G99 is feedrate per revolution - it's the same thing you can set on G00 and G01, except it makes it the default value for your file. Yes, but for those who have a machine that does support it it is still a nice option since it is probably more accurate. as for G50 I think you may be correct. From what I can tell I can literally just omit this, as machines are not able to fire over 100%. From what I have read online most laser cutters divide the spindle speed by 255 and set that as the % of their max power (0 is off, 255 is max, 128 is half). G96 should automatically adjust the speed and power of the laser to give the same exposure to every line, ensuring a clean cut. CNC lathes appearently require G50 so they don't spin out of control, but as far as I can tell other CNC machines (like laser cutters) do not.

Treehee commented 6 years ago

@alpharesearch I did some more research and G96 doesn't do anything on laser cutters (or milling machines) as both already have a constant speed so I will just use G97 :)

Treehee commented 6 years ago

That also means I will use G94 to control feedrate

alpharesearch commented 6 years ago

My GRBL laser mode test from 2014 shows some GCODE on it's page. GRBL has a native laser mode now that is more advanced but works the same way. I have a ShapeOko V1 CNC with a 3 watt laser diode. It will cut paper and cardboard. Here is a list of all the commands I would normaly use to write a GCODE file by hand to use with my laser:

manthrax commented 6 years ago

Very cool that you're working on this! I actually have gotten a decent workflow going for this using this plugin combined with:

https://github.com/LaserWeb/LaserWeb4...

and Here is the low price laser cutter I am using:

https://www.banggood.com/2500mW-A3-30x40cm-Desktop-DIY-Violet-Laser-Engraver-Picture-CNC-Printer-Assembling-Kits-p-1003863.html?cur_warehouse=CN

This cutter is my first experience with laser cutting and I have had no major problems with it, and it seems to work well with cardstock, but I haven't tried with anything heavier due to ventilation constraints in my apartment.

But fair warning if you do get one! Use the goggles, since sometimes it will boot with the laser at full power for no good reason, so you really have to pay attention when using it!

First off, here are a few objects I've scored and cut on cardstock using my workflow:

https://files.slack.com/files-pri/T02GC8M7E-FBAV7LQ77/20180620_045949.jpg

Here is a screenshot for an intermediate tool I wrote to do some processing on the output SVG , but I ended up not neccessarily needing it, once I figured out I could change the different line colors on the object export.. more on this in a sec...

https://files.slack.com/files-pri/T02GC8M7E-FBA4GAEAC/image.png

Let me describe my workflow and perhaps it will give you some ideas...

I first export the object with rgb pure red for the object perimeter lines, green for valley folds and blue for the mountain folds... (in practice I treat both fold types the same since the laser cutter can only score one side...

This is neccesary so that LaserWeb can be configured to use different laser energies for each line type.. since it can key off the line color to select the laser power.

So then in LaserWeb, I create 2 different operation configuration sets... One called "laser cut" and the other called "laser score"

I then make two instances of the "score" operation, and one of the "cut" operation. the 2 Scoring instances are keyed off of Green and Blue, and the Cut operation is keyed off of the Red paths.

I've arranged it like this so that the scoring of the interior lines happens first, because if the cuts happened first, the piece could fall out of the cardstock and shift position, and screw up the positioning of the subsequent scoring operations.. so Scoring happens First (at low laser power) and Exterior cutting happens Last and 100% laser power.

My settings for the 2 operation types are as follows:

Scoring: Laser power: 15% Cut Rate: 3000 Segment Length: 0.3 (mm)

Cutting: Laser power: 100% Cut Rate: 1000 Segment Length: 0.3 (mm)

So from the settings above you can see that cutting vs scoring is controlled both by the laser intensity AND the Cutting rate which is the speed the printer moves the head... So scoring lines can be drawn much faster, but cutting has to happen slower to get full penetration through the cardstock.

The segment length controls the size of the minimum feature.. this turned out to be important because otherwise the generated gcode can program the path to do Very small movements, which cause the laser to dwell near the same spot for too long, and will overburn. this mostly happens at the vertices of objects, but setting the minimum feature size to 0.3 mm mostly fixed that, and now I get pretty clean and uniform cuts.

For reference, each of the objects in the screenshot above took just a couple minutes each to cut. Assembly is what takes the most time.

Treehee commented 6 years ago

@manthrax could the overburn problem also be fixed by making the gcode print those edges at different moments or would that not make a difference (ie if you have a sharp angle it cuts one edge, then cuts some other stuff, then cuts that edge at a later moment)?

If not, what does "minimum feature size" do on that program? Does it ignore smaller lines completely, or does it remove them and bring the closest two edges together, or does it increase their size? If you're not sure, what do you think would give the best results? Does it do anything about sharp angles? If so, what?