Splines to Gcode from dxf file

More
10 years 1 month ago #80098 by jtc
Hi!

I'm working on a small program that reads from a dxf file the points of splines. At the moment and debugging the data read from the file I got control points and fit points





The main goal is to convert in Gcode to use with a plasma cnc. For what I have seen on the documentation ( linuxcnc.org/docs/html/gcode/g-code.html#gcode:g5 ) there are cubic splines, quadratic splines and the nurbs block.

So, what is the best way to do this? the typical order of the spline in the cad program is 3(cubic splines). Its better practice use G5, or can I obtain the same results with G5.2/G5.3?


Note that I can be able to start cut from the end beginning of the curve, but so also from the end in reverse direction, if one of the Gcodes eases this process it must be considerate.



João

Please Log in or Create an account to join the conversation.

More
10 years 1 month ago #80165 by andypugh
I have no idea, but I wold love to hear what you learn in the process. I got completely baffled trying to convert CAD data in Inventor into SVG Beziers. forums.autodesk.com/t5/inventor-customiz...ighlight/true#M54006

Please Log in or Create an account to join the conversation.

More
10 years 1 month ago #80182 by jtc
Replied by jtc on topic Splines to Gcode from dxf file

andypugh wrote: I have no idea, but I wold love to hear what you learn in the process. I got completely baffled trying to convert CAD data in Inventor into SVG Beziers. forums.autodesk.com/t5/inventor-customiz...ighlight/true#M54006


I don't have any experience with svg files, only read and write dxf files.

today I made some work, this is the first implementation with g5.2 /g5.3





the basic is working, but the splines looks different from the drawing. now its a question of understanding the L and P parameters to adjust it correctly. After this is reversing the path.

João

Please Log in or Create an account to join the conversation.

More
4 years 10 months ago - 4 years 10 months ago #230031 by Matt Hat
I would be interested in a rigorous definition of the parameters used in G5, namely what exactly is the definition of I, J, P, and Q ?
linuxcnc.org/docs/html/gcode/g-code.html#gcode:g5
The missing link: conversion of cubic polynomial coefficients to I,J,P, and Q.
The 3rd order (cubic) splines are simply defined by four polynomial coefficients. Start and end points (also called nodes) will give two constraints, two more follow from the continuity of the first and second derivatives.
My favorite tools for post-processing are GNU octave and Python. Fit of cubic splines to any curve shape is quite simple using e.g. the splinefit command within octave. So far so good.

I am uncertain how to translate the polynomial coefficients to control points required for a B-spline definition. By some method, the correct control points have to be found - as referred to in G5 commands by i,J, P and Q I assume.

Graphically speaking, this would required to draw the outside polygon for a given curve. Geometrically speaking, we have to draw tangents to all knots and intersect two subsequent tangents to obtain the control points.

Conclusively,
I am looking for a simple implementation to calculate the control points of a B-spline for a given cubic (polynomial) spline. This would allow me to mill along piecewise cubic spline trajectories using G5 command.

 Any experiences or suggestions to share?
Last edit: 4 years 10 months ago by Matt Hat. Reason: formating

Please Log in or Create an account to join the conversation.

More
4 years 10 months ago - 4 years 10 months ago #230036 by Grotius
Hi,

I often imported dxf splines and passed them into lcnc gcode.

It can be hard to get the splines look the same in different programs. I think different algo's are used.
It's a shame the acad algo is closed source. In this way you can never replicate the spline. Autodesk f.ckers.
Splines using fitpoints are my favorite.

On my github there are different spline library's. Also a 3d spline with fitpoints is over there. And a 2d spline algo made
by a mathician for me.

Programs like inkscape exports a spline to a linestrip. This is a option. A more exotic option is to
export a spline into arc segments.

This is from the dxfrw lib, the same as Freecad and others are using, line 847 to 900 gives dxf spline info.
I use this lib for importing dxf and then parse to gcode. See "big data" attachement. image missing /media/kunena/emoticons/cool.png

github release page: halcore/src/hal/components/matrix/cpp_interface/libspline => bezier_spline, cubic_spline, spline
github release page: halcore/src/hal/components/matrix/cpp_interface/libdxfrw => dxfrw lib
Not really good, but for info:
read spline: github.com/grotius-cnc/qt_cadcam_rev/blo...xf/dxf_read_spline.h
draw spline: github.com/grotius-cnc/qt_cadcam_rev/blo...er/display/display.h

Implementation of 3d splinelib, very cool:
github.com/grotius-cnc/splinelib

2d spline algo using fitpoints starting at line 185
github.com/grotius-cnc/cadcam/blob/master/opengl.cpp
Last edit: 4 years 10 months ago by Grotius.
The following user(s) said Thank You: jtc, Matt Hat

Please Log in or Create an account to join the conversation.

More
4 years 10 months ago #230050 by Matt Hat
Great, many thanks. I will look into these resources and hopefully contribute with some transportation to octave of py. They just run so smooth beside any linuxcnc installation. Anything that is free from commercial interests is fine. :)

Please Log in or Create an account to join the conversation.

Time to create page: 0.163 seconds
Powered by Kunena Forum