简体   繁体   中英

X,Y coordinate to gcode

I'm working on a computer science project which is a CNC plotter basically all of the methods I see for getting Gcode uses Inkscape. I have already written software to convert Normal images to black and white edges only and I have pulled the coordinates from the image. Is there any way X,Y coordinates can be used to generate Gcode? or would i have to use Inkscape.

GCode is just instructions called where you can pass arguments.

The machine will execute the Gcode one by one and interpret it for moving his motors or do regulation depending on his firmware.

So if you want to create Gcode in python, just create a txt file and append commands.

You need to have the Gcode availables instructions of you machine first.

For example in Marlin :

G1 X90.6 Y13.8 ; move to 90.6mm on the X axis and 13.8mm on the Y axis

To get this file in python:

with open("myGCode.gcode", "w") as f:
    f.write("G1 X90.6 Y13.8 ;\n")
    f.write("G1 X10.6 Y3.98 ;\n")

It really depends on the machine and its controller, but most of the time, Linear interpolation like G1 or G01 usually only needs to be specified once, like

G01 X1.0 Y2.0;

And then its linear interpolation enabled already so it can just be

X1.0 Y3.0;
...

Up to the point where you wanna go back to rapid movement (G0 G00)

Or circular interpolation with (G02, G03)

But then it's still usually just coordinates are enough after switching to specific interpolation once.

Yet then I assume its for simple milling and more recent mills (I was trained for Haas) has some fancy pocketing functions, where you just specify few key points for contour and they can kinda be deducted mathematically.

It would be interesting to see your program for getting a contour out of a photo.

But specifying type of interpolation between each set of coordinates is also OK, just it might make code readability slightly more difficult.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM