Skip to content

A script that will sketch the shapes made by G-codes used in CNC machines using Python using python's turtle and regular expressions (re) library.

Notifications You must be signed in to change notification settings

pUrGe12/G-code-visualisation-using-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Project: to visualise G-codes used by CNC machines using python.

Aim is to trace the shape given by the G-code commands. Hence, I will skip over the Z axis line codes, and ignore the M-codes related to spindle movements and cutting.
The speed of the movements defined by G00 and G01 will be predefined and variable depending on user.

Preassumtions:
1. G17 (XY plane) unless G18 or G19 specified.
2. G40 --> cancel cutter compensation (since we are only tracing)
3. G64 --> continous path mode (tolerance may be specified)

The G-codes taken into consideration are:
1. G00 --> rapid move from (x,y) to (x+x0, y+y0), may not be a straight line motion (goto specific position while not sketching)
2. G01 --> controlled move from (x,y) to (x+x0, y+y0), straight line motion
3. G02 --> clockwise curve
4. G03 --> anti-clockwise curve
5. G21 --> metric mode
6. G20 --> imperial mode 
7. G90 --> absolute distancing
8. G91 --> incremental distancing
9. G94 --> feed rate in inches/mm per min
10. G53 --> machine coordinates
11. G54 --> coordinate system
12. G64 --> specify tolerance (P)

Note: Since machine configuration, kinematics and control systems are unknown, I will be assuming the G00 command to be the same as G01 command, i.e. a straight line motion. (Not that it would matter anyway, since G00 is for positioning) 

The M-codes and letter codes taken into consideration are:
1. M0 --> pause machine
2. M2 --> end program
3. M30 --> end program and loop to first line
4. R --> radius in G02 and G03
5. X --> x coordinate specification
6. Y --> y coordinate specification
7. N --> line number
8. I --> radius specification for a circle

The libraries used in python are turtle, re (regular expressions) and math. Note, for the code to run, you need the turtle library.
To install turtle use:

  $pip install turtle

on the command prompt, or linux terminal.

About

A script that will sketch the shapes made by G-codes used in CNC machines using Python using python's turtle and regular expressions (re) library.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages