fragmuffin / pygcode

GCODE Parser for Python
GNU General Public License v3.0
123 stars 38 forks source link

arc movement example #16

Closed giantstonex7 closed 5 years ago

giantstonex7 commented 5 years ago

Hi, in the document, we can learn how to use linear move, but no example for arc movement is provided, for example, I have a arc ( start, end, radius, cw/ccw ) etc. , how to i pass the parameters to the pygcode?

fragmuffin commented 5 years ago

@giantstonex7 You can pass the gcode parameters to the GCodeArcMoveCW & GCodeArcMoveCCW in the same way you can a GCodeRapidMove or GCodeLinearMove.

For example:

>>> start = (1, 1)
>>> end = (6, 1)
>>> radius = 2.5
>>> cw = True

>>> from pygcode.gcodes import GCodeArcMoveCW, GCodeArcMoveCCW, GCodeRapidMove
>>> arc_cls = GCodeArcMoveCW if cw else GCodeArcMoveCCW
>>> gcodes = [
...     GCodeRapidMove(X=start[0], Y=start[1]),
...     arc_cls(X=end[0], Y=end[1], R=radius),
... ]
>>> gcodes
[<GCodeRapidMove: G00{X1, Y1}>, <GCodeArcMoveCW: G02{R2.5, X6, Y1}>]

Then, depending on what you want to do with the codes, you could write them to file, or just to the screen...

>>> print('\n'.join(str(g) for g in gcodes))
G00 X1 Y1
G02 R2.5 X6 Y1

If you don't mind me asking, what are you using pygcode for? I'd like to have the time to get back on this project and make some improvements. One obvious improvement is the documentation ;)