Hello Guest it is July 08, 2020, 12:56:06 AM

Author Topic: Code snippets  (Read 391 times)

0 Members and 1 Guest are viewing this topic.

Offline PeteG

*
  •  33 33
    • View Profile
Code snippets
« on: December 21, 2019, 07:15:20 AM »
Where can I find G Code examples? e.g. interpolation of a 6mm cutter to cut a 10mm hole.

I haven't done programming for a while and that was VB, but when I was doing it I found the best way for me to learn was to download a code snippet then read it, make changes etc... and see what worked.

Cheers

Offline Tweakie.CNC

*
  • *
  •  8,350 8,350
  • Super Kitty
    • View Profile
    • Tweakie.CNC
Re: Code snippets
« Reply #1 on: December 21, 2019, 07:43:40 AM »
Hi Peter,

I think the best and easiest way is to use a CAD/CAM software to draw your part (or import the .dxf / drawing file) then it can create the Gcode for you automatically applying the tool radius and offsets, etc. Actually writing the Gcode by hand seems a bit outdated nowadays.

One of the most popular range of CAD/CAM programs is made by Vectric; https://www.vectric.com/ (for what it does it is worth every penny).
There are also many FREE softwares, one I use a lot is F-Engrave; https://www.scorchworks.com/Fengrave/fengrave.html

Perhaps Google free CAD/CAM software.

Tweakie.
KEEP SAFE !

Offline BR549

*
  •  6,932 6,932
    • View Profile
Re: Code snippets
« Reply #2 on: December 21, 2019, 10:29:09 AM »
There are MANY ways to do this . Here is just one way.

G0 X0 Y0 Z0 (Centerpoint of hole)
( first pass of depth)
G1 Z-1 F10 (lower Z in center of hole)
G1 X2 F10 (move to Radius of hole)
G2 X2 Y0 I-2 J0 F10 ( Cut circle at 5mm { 3mm tool and 2 mm offset =5mm radius} radius from centerpoint)
G0 X0Y0 (return to centerpoint)

(2nd pass of depth)

G1 Z-2 F10
G1 X2 F10
G2 X2 Y0 I-2 J0 F10
G0 X0Y0

M30

It is always a good point to learn Gcode IF your machine uses it to control motion.

Hope that helps (;-) TP

Offline PeteG

*
  •  33 33
    • View Profile
Re: Code snippets
« Reply #3 on: December 21, 2019, 11:15:07 AM »
Thanks, I will try this.

Offline PeteG

*
  •  33 33
    • View Profile
Re: Code snippets
« Reply #4 on: December 30, 2019, 01:37:11 PM »
A weird thing happened today. I used the code and experimented with it by changing some parameters and it was working well, but suddenly it didn't work. I had run the code 20 or so times, then when it got to the line G1 Z-1 F10 (move to radius of hole) it stopped and would not go to the next line, even though I had not changed anything on that line, and it had been working fine.

I checked some other files with similar Z and X movements and they all worked.

Any ideas as to why this happened?

Best regards

Peter
Re: Code snippets
« Reply #5 on: December 31, 2019, 01:28:00 PM »
A weird thing happened today. I used the code and experimented with it by changing some parameters and it was working well, but suddenly it didn't work. I had run the code 20 or so times, then when it got to the line G1 Z-1 F10 (move to radius of hole) it stopped and would not go to the next line, even though I had not changed anything on that line, and it had been working fine.

I checked some other files with similar Z and X movements and they all worked.

Any ideas as to why this happened?

Best regards

Peter
May be a typo, you do not have an X or Y direction, you have it Feeding down to Z-1 and that is it (no feeding on the X/Y plane)

Offline PeteG

*
  •  33 33
    • View Profile
Re: Code snippets
« Reply #6 on: January 01, 2020, 04:09:11 AM »
Hi Guntruck 1776

Thanks for the reply, this was the code supplied to me by BR549:

G0 X0 Y0 Z0 (Centerpoint of hole)
( first pass of depth)
G1 Z-1 F10 (lower Z in center of hole)
G1 X2 F10 (move to Radius of hole)
G2 X2 Y0 I-2 J0 F10 ( Cut circle at 5mm { 3mm tool and 2 mm offset =5mm radius} radius from centerpoint)
G0 X0Y0 (return to centerpoint)

(2nd pass of depth)

G1 Z-2 F10
G1 X2 F10
G2 X2 Y0 I-2 J0 F10
G0 X0Y0

M30

This was working fine with me changing various values to see what happened - I was trying to cut a 10mm hole with a 6MM cutter - with no success (I am new to this)

I changed the feed rate on this line to F20:
G2 X2 Y0 I-2 J0 F10 ( Cut circle at 5mm { 3mm tool and 2 mm offset =5mm radius} radius from centerpoint)

It was after I changed it back to F10 that the issue occurred even though the G1 X2 F10 line hadn't been changed in any way.

I went back to the original file and the same problem occurred, yet other files with similar Z & X movements are working OK

Like I said, I am new to this, so forgive any glaring ignorance on my part.

Cheers and happy new year

Peter

Offline BR549

*
  •  6,932 6,932
    • View Profile
Re: Code snippets
« Reply #7 on: January 01, 2020, 10:56:30 AM »
DID you happen to interject a G90 or G91 into teh mix ? That code would have been for G90 code (absolute). Look on teh status line and see what is set G90 or G91.

(;-) TP
Re: Code snippets
« Reply #8 on: January 02, 2020, 11:53:40 AM »
G90 is absolute mode and G91 is incremental mode.

In G90 mode say you have
G1 X1.0;
Y1.0;
X2.0;
Y2.0;
You are now 2.0 in the X from where you started and 2.0 in the Y from where you started.

In G91 mode, say you have
G1 X1.0;
Y1.0;
X2.0;
Y2.0;
You are now 3.0 in the X from where you started and 3.0 in the Y from where you started.

That would cause a problem or a crash, I personally have never used G91

Offline PeteG

*
  •  33 33
    • View Profile
Re: Code snippets
« Reply #9 on: January 07, 2020, 02:29:35 AM »
Hi Peter,

I think the best and easiest way is to use a CAD/CAM software to draw your part (or import the .dxf / drawing file) then it can create the Gcode for you automatically applying the tool radius and offsets, etc. Actually writing the Gcode by hand seems a bit outdated nowadays.

One of the most popular range of CAD/CAM programs is made by Vectric; https://www.vectric.com/ (for what it does it is worth every penny).
There are also many FREE softwares, one I use a lot is F-Engrave; https://www.scorchworks.com/Fengrave/fengrave.html

Perhaps Google free CAD/CAM software.

Tweakie.

Hi Tweakie

I took your advice and purchased Vcarve, it's very good isn't it. You are quite right about manual coding being a bit too old school; my first project was cutting foam to hold a Shure IEM beltpack - I work in live music and AV production. The code for what is essentially a 70 x 88 mm hole with a few other cutouts was over 1000 lines of Gcode!

Cheers

Peter