B4J Question Turtle Gcode reader

HansEman

Member
Licensed User
Longtime User
I see Turtle as a very simple yet accomplished display/viewer of vectors. It could be used to make a G-code reader & display tool.

CNC machine code is Gcode like this (a 200x100mm rertangle with 5mm radius corners starting at 50x50):
[Toolpath name: Profile 1]
[Tool: End Mill (0.125 inch)]
[Depth: 0.394 @ Feed: F25]
[X/Y Feed rate: F80]
[Set Surface sensor to: 0.394]
[---= Begin Job =---]

G90
M3
G53 Z0
[End Mill (0.125 inch)]
G0X1.9685Y2.1654
G0Z0.2000
G1Z-0.3937F25
G1Y5.7087F80
G2X2.1654Y5.9055I0.1969J0.0000
G1X9.6457
G2X9.8425Y5.7087I0.0000J-0.1969
G1Y2.1654
G2X9.6457Y1.9685I-0.1969J0.0000
G1X2.1654
G2X1.9685Y2.1654I0.0000J0.1969
[End Mill (0.125 inch)]
G0
G0Z0.2000
G0Z0.8000
M5
G53Z0
M2
---
How would I scale the display to fit the X & Y coordinates and how would I handle arcs (G2 & G3 in Gcode)?

Thanks all.
 

HansEman

Member
Licensed User
Longtime User
G code is a text format that drives CNC machines.
It is used by CAM software to design jobs by creating a new toolpath (center line) from vector format designs ie. DXF, EPS, DWG etc.

A reader (graphic viewer) would only use X & Y coordinates for a flat view, or X, Y & Z for a 3D representation of the G code toolpath.
The file parsing would omit all other text inputs except:
G0 (move with pen up)
G1 (move with pen down)
G2 (Clockwise arc: X & Y = arc endpoint, I = Arc center X, J = arc center Y)
One could use different colors and line type (dashed and solid) for the penup and pendown moves.
My problem is scaling the whole job onto the panel and how to handle the G2 (Arc).

--- G code ---
[Toolpath name: Profile 1]
[---= Begin Job =---]

G90
M3
G53 Z0
[End Mill (6 mm)]
G0X1.9685Y2.1654
G0Z0.2000
[End Mill (6 mm)]
G0
G0Z0.0000
G1Z-0.3937F47
G1Y5.7087F142
G2X2.1654Y5.9055I0.1969J0.0000
G1X9.6457
G2X9.8425Y5.7087I0.0000J-0.1969
G1Y2.1654
G2X9.6457Y1.9685I-0.1969J0.0000
G1X2.1654
G2X1.9685Y2.1654I0.0000J0.1969
[End Mill (6 mm)]
G0
G0Z0.2000
G0Z0.2000
M5
G53Z0
M2
---
 

Attachments

  • Profile1.png
    Profile1.png
    17.1 KB · Views: 160
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Scaling should be done with a sub that takes the job coordinates and maps them to the canvas coordinates. Something like:
B4X:
Sub GToTurtle (cord As Float) As Float
 Return cord / ratio
End Sub

Where ratio is the relation between the Max(G height / Turtle.Height, G width / Turtle.Width)

You can use Turtle.Arc to draw arcs.
 
Upvote 0
Top