Request G6, Ellipse and G7, bezier curve
- Grotius
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 2251
- Thank you received: 1990
24 May 2020 10:18 - 24 May 2020 10:22 #168776
by Grotius
Request G6, Ellipse and G7, bezier curve was created by Grotius
Hi,
I have a programmer request for adding a G6, Ellipse and a G7, Bezier curve to the Linuxcnc source code.
This request is done because the cubic spline G5, is already available for Linuxcnc. For my cam software i want
the possiblily to output G5, G6 and G7 code format's. This would be inline with a uniform program output.
At this moment i see a non uniform output for linuxcnc happening :
We can output a cam G5 for spline, but we can only output fragmented linestrips to cnc a Ellipse or Bezier curve.
Attached c/c++ basic function's that can be adapted to the Linuxcnc Gcode intepreter with minimal changes.
This tiny step forward in linuxcnc source code, is a huge step for cnc cam program's. The power of
a G6 and G7 output is that the cam program does not have to facetate a ellipse into a fragmented linestrip. This results in
thousand lines of code when the cam program's calculate a very accurate cnc path. Let linuxcnc do this real time calculation
while the machine is moving.
I hope some linuxcnc programmer will pick this up and put it in the next Linuxcnc release.
WIch Gcode Numbers are used, doesn't matter for me. G6 and G6.1 are fine for example. G7 is already used for lathe.
I have a programmer request for adding a G6, Ellipse and a G7, Bezier curve to the Linuxcnc source code.
This request is done because the cubic spline G5, is already available for Linuxcnc. For my cam software i want
the possiblily to output G5, G6 and G7 code format's. This would be inline with a uniform program output.
At this moment i see a non uniform output for linuxcnc happening :
We can output a cam G5 for spline, but we can only output fragmented linestrips to cnc a Ellipse or Bezier curve.
Attached c/c++ basic function's that can be adapted to the Linuxcnc Gcode intepreter with minimal changes.
This tiny step forward in linuxcnc source code, is a huge step for cnc cam program's. The power of
a G6 and G7 output is that the cam program does not have to facetate a ellipse into a fragmented linestrip. This results in
thousand lines of code when the cam program's calculate a very accurate cnc path. Let linuxcnc do this real time calculation
while the machine is moving.
I hope some linuxcnc programmer will pick this up and put it in the next Linuxcnc release.
WIch Gcode Numbers are used, doesn't matter for me. G6 and G6.1 are fine for example. G7 is already used for lathe.
Warning: Spoiler!
void draw_3p_ellipse(double xcen, double ycen, double xend, double yend, double xinput, double yinput, double pi_angle_start, double pi_angle_end, double ratio, double red, double green, double blue, double alpha){
//ellipse center = xcen, ycen
//ellipse base right = xend, yend
//ellipse top point = xinput, yinput
double center_x = xcen;
double center_y = ycen;
//center point to endpoint mayor axis..
double radius_x = sqrt(pow(xend-xcen,2) + pow(yend-ycen,2));
//ratio minor axis to mayor axis..
double radius_y=0;
if(ratio==0){ //takes the controlpoint instead of ratio factor
radius_y = sqrt(pow(xinput-xcen,2) + pow(yinput-ycen,2));
}
if(ratio!=0){ //if ratio from dxf is available, it takes its value
radius_y = ratio*radius_x;
}
//calculate angle of ellipse
double x1=xend;
double y1=yend;
double radian = atan2(y1 - center_y, x1 - center_x);
double angle = radian * (180 / M_PI);
if (angle < 0.0)
angle += 360.0;
glColor4d(red,green,blue,alpha);
glBegin(GL_LINE_STRIP);
for(double j = pi_angle_start; j<pi_angle_end; j+=0.01)
{
//non rotated ellipse..
double non_rotated_x = /*center_x +*/ cos(j)*radius_x;
double non_rotated_y = /*center_y +*/ sin(j)*radius_y;
//glVertex2d(center_x + cos(j)*radius_x, center_y + sin(j)*radius_y);
//rotated ellipse..
double rotate_x = center_x + cos(angle * M_PI / 180.0 )* non_rotated_x - sin(angle * M_PI / 180.0 ) * non_rotated_y;
double rotate_y = center_y + sin(angle * M_PI / 180.0 )* non_rotated_x + cos(angle * M_PI / 180.0 ) * non_rotated_y;
glVertex2d(rotate_x, rotate_y);
}
glEnd();
}
//ellipse center = xcen, ycen
//ellipse base right = xend, yend
//ellipse top point = xinput, yinput
double center_x = xcen;
double center_y = ycen;
//center point to endpoint mayor axis..
double radius_x = sqrt(pow(xend-xcen,2) + pow(yend-ycen,2));
//ratio minor axis to mayor axis..
double radius_y=0;
if(ratio==0){ //takes the controlpoint instead of ratio factor
radius_y = sqrt(pow(xinput-xcen,2) + pow(yinput-ycen,2));
}
if(ratio!=0){ //if ratio from dxf is available, it takes its value
radius_y = ratio*radius_x;
}
//calculate angle of ellipse
double x1=xend;
double y1=yend;
double radian = atan2(y1 - center_y, x1 - center_x);
double angle = radian * (180 / M_PI);
if (angle < 0.0)
angle += 360.0;
glColor4d(red,green,blue,alpha);
glBegin(GL_LINE_STRIP);
for(double j = pi_angle_start; j<pi_angle_end; j+=0.01)
{
//non rotated ellipse..
double non_rotated_x = /*center_x +*/ cos(j)*radius_x;
double non_rotated_y = /*center_y +*/ sin(j)*radius_y;
//glVertex2d(center_x + cos(j)*radius_x, center_y + sin(j)*radius_y);
//rotated ellipse..
double rotate_x = center_x + cos(angle * M_PI / 180.0 )* non_rotated_x - sin(angle * M_PI / 180.0 ) * non_rotated_y;
double rotate_y = center_y + sin(angle * M_PI / 180.0 )* non_rotated_x + cos(angle * M_PI / 180.0 ) * non_rotated_y;
glVertex2d(rotate_x, rotate_y);
}
glEnd();
}
Warning: Spoiler!
void draw_4p_bezier(double xs, double ys, double zs, double xcon0, double ycon0, double zcon0, double xcon1, double ycon1, double zcon1, double xend, double yend, double zend, double red, double green, double blue, double alpha){
glLineWidth(1);
glColor4d(red,green,blue,alpha);
glBegin(GL_LINE_STRIP);
for(double t = 0; t < 1; t+=0.01){
//Calculate Point E, on the line AB
double Ex = ((1-t) * xs) + (t * xcon0);
double Ey = ((1-t) * ys) + (t * ycon0);
double Ez = ((1-t) * zs) + (t * zcon0);
//Calculate Point F, on the line BC
double Fx = ((1-t) * xcon0) + (t * xcon1);
double Fy = ((1-t) * ycon0) + (t * ycon1);
double Fz = ((1-t) * zcon0) + (t * zcon1);
//Calculate Point G, on the line CD
double Gx = ((1-t) * xcon1) + (t * xend);
double Gy = ((1-t) * ycon1) + (t * yend);
double Gz = ((1-t) * zcon1) + (t * zend);
//Calculate Point Q, on the line EF
double Qx = ((1-t) * Ex) + (t * Fx);
double Qy = ((1-t) * Ey) + (t * Fy);
double Qz = ((1-t) * Ez) + (t * Fz);
//Calculate Point R, on the line FG
double Rx = ((1-t) * Fx) + (t * Gx);
double Ry = ((1-t) * Fy) + (t * Gy);
double Rz = ((1-t) * Fz) + (t * Gz);
//Calculate Point P, on the line QR
double Px = ((1-t) * Qx) + (t * Rx);
double Py = ((1-t) * Qy) + (t * Ry);
double Pz = ((1-t) * Qz) + (t * Rz);
glVertex3d(Px, Py, Pz); //draw linestrip..
}
glEnd();
}
glLineWidth(1);
glColor4d(red,green,blue,alpha);
glBegin(GL_LINE_STRIP);
for(double t = 0; t < 1; t+=0.01){
//Calculate Point E, on the line AB
double Ex = ((1-t) * xs) + (t * xcon0);
double Ey = ((1-t) * ys) + (t * ycon0);
double Ez = ((1-t) * zs) + (t * zcon0);
//Calculate Point F, on the line BC
double Fx = ((1-t) * xcon0) + (t * xcon1);
double Fy = ((1-t) * ycon0) + (t * ycon1);
double Fz = ((1-t) * zcon0) + (t * zcon1);
//Calculate Point G, on the line CD
double Gx = ((1-t) * xcon1) + (t * xend);
double Gy = ((1-t) * ycon1) + (t * yend);
double Gz = ((1-t) * zcon1) + (t * zend);
//Calculate Point Q, on the line EF
double Qx = ((1-t) * Ex) + (t * Fx);
double Qy = ((1-t) * Ey) + (t * Fy);
double Qz = ((1-t) * Ez) + (t * Fz);
//Calculate Point R, on the line FG
double Rx = ((1-t) * Fx) + (t * Gx);
double Ry = ((1-t) * Fy) + (t * Gy);
double Rz = ((1-t) * Fz) + (t * Gz);
//Calculate Point P, on the line QR
double Px = ((1-t) * Qx) + (t * Rx);
double Py = ((1-t) * Qy) + (t * Ry);
double Pz = ((1-t) * Qz) + (t * Rz);
glVertex3d(Px, Py, Pz); //draw linestrip..
}
glEnd();
}
Last edit: 24 May 2020 10:22 by Grotius.
The following user(s) said Thank You: tommylight
Please Log in or Create an account to join the conversation.
- rodw
- Offline
- Platinum Member
Less
More
- Posts: 10807
- Thank you received: 3559
24 May 2020 11:46 #168784
by rodw
Replied by rodw on topic Request G6, Ellipse and G7, bezier curve
Grotius, I wish I knew more about the internal code but you gave me an excuse to read a bit more of it
Can you give some gcode examples of how you think these could be used in a Gcode file?
Can you give some gcode examples of how you think these could be used in a Gcode file?
The following user(s) said Thank You: Grotius
Please Log in or Create an account to join the conversation.
- Grotius
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 2251
- Thank you received: 1990
24 May 2020 12:52 #168790
by Grotius
Replied by Grotius on topic Request G6, Ellipse and G7, bezier curve
Hi Rod,
Can you give some gcode examples of how you think these could be used in a Gcode file?
Sure,
Attached example is in line with current Gcode programming style.
For ellipse the example is an open ellipse, the ellipse itself is defined under a angle. So the most difficult ellipse example
can be done in 1 line of gcode.
For bezier curve the input is like the cubic spline. I,J are first control points. P,Q are second control points.
Gcode can be done in 1 line of gcode.
Can you give some gcode examples of how you think these could be used in a Gcode file?
Sure,
Attached example is in line with current Gcode programming style.
For ellipse the example is an open ellipse, the ellipse itself is defined under a angle. So the most difficult ellipse example
can be done in 1 line of gcode.
For bezier curve the input is like the cubic spline. I,J are first control points. P,Q are second control points.
Gcode can be done in 1 line of gcode.
Attachments:
The following user(s) said Thank You: tommylight, rodw
Please Log in or Create an account to join the conversation.
- Grotius
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 2251
- Thank you received: 1990
10 Jun 2020 10:43 - 10 Jun 2020 10:50 #170942
by Grotius
Replied by Grotius on topic Request G6, Ellipse and G7, bezier curve
Okey,
After some research about the current linuxcnc G5 Cubic splines and G5.1 Quadratic splines i came to the conclusion yesterday this
type of splines are not compatible with following open source programs :
Freecad
Inkscape
Librecad (uses two types of splines)
Cadcam
The linuxcnc G5 Cubic splines and G5.1 Quadratic splines are in my opinion not preferred to use for robot trajectory.
The perfect spline to use to stay in line with above programs : mathworld.wolfram.com/CubicSpline.html
What we miss is the G code command for a Ellipse and Bezier curve and a Gcode command for
a cubic spline that is constructed of piecewise third-order polynomials.
So i can do 3 things.
1. Lean back in my chair and do nothing about it.
2. Post this on the forum and hope someone will add it to the source code.
3. Add it to the linuxcnc source code myself.
What would you do?
Imagine the above criteria is integrated in the linuxcnc source code. The G-code output will reduce with 80-96%.
The cnc machine will be more accurate to the path, because it no longer depends on interpolating the path over 1000+ line segments,
wich are not interpolated as should be in my opinion.
After some research about the current linuxcnc G5 Cubic splines and G5.1 Quadratic splines i came to the conclusion yesterday this
type of splines are not compatible with following open source programs :
Freecad
Inkscape
Librecad (uses two types of splines)
Cadcam
The linuxcnc G5 Cubic splines and G5.1 Quadratic splines are in my opinion not preferred to use for robot trajectory.
The perfect spline to use to stay in line with above programs : mathworld.wolfram.com/CubicSpline.html
What we miss is the G code command for a Ellipse and Bezier curve and a Gcode command for
a cubic spline that is constructed of piecewise third-order polynomials.
So i can do 3 things.
1. Lean back in my chair and do nothing about it.
2. Post this on the forum and hope someone will add it to the source code.
3. Add it to the linuxcnc source code myself.
What would you do?
Imagine the above criteria is integrated in the linuxcnc source code. The G-code output will reduce with 80-96%.
The cnc machine will be more accurate to the path, because it no longer depends on interpolating the path over 1000+ line segments,
wich are not interpolated as should be in my opinion.
Last edit: 10 Jun 2020 10:50 by Grotius.
Please Log in or Create an account to join the conversation.
- tommylight
- Away
- Moderator
Less
More
- Posts: 19487
- Thank you received: 6535
10 Jun 2020 10:53 #170944
by tommylight
Replied by tommylight on topic Request G6, Ellipse and G7, bezier curve
Might be better to post that question on the LinuxCNC IRC channel as most of the developer hang out there.
webchat.freenode.net/?channels=%23linuxcnc
It requires registering the nic to be able to post, due to spammer protection.
webchat.freenode.net/?channels=%23linuxcnc
It requires registering the nic to be able to post, due to spammer protection.
The following user(s) said Thank You: Grotius
Please Log in or Create an account to join the conversation.
- rodw
- Offline
- Platinum Member
Less
More
- Posts: 10807
- Thank you received: 3559
10 Jun 2020 11:37 #170951
by rodw
In my experience, the only way to make it happen is option 3. But 1 is a lot easier.
I also want to make some changes to the core code. Maybe we can work together...
I think the new G code will need to align with an existing gcode flavour so that there is post processor support.
Replied by rodw on topic Request G6, Ellipse and G7, bezier curve
Okey,
So i can do 3 things.
1. Lean back in my chair and do nothing about it.
2. Post this on the forum and hope someone will add it to the source code.
3. Add it to the linuxcnc source code myself.
.
In my experience, the only way to make it happen is option 3. But 1 is a lot easier.
I also want to make some changes to the core code. Maybe we can work together...
I think the new G code will need to align with an existing gcode flavour so that there is post processor support.
The following user(s) said Thank You: Grotius
Please Log in or Create an account to join the conversation.
- bbsr_5a
- Offline
- Platinum Member
Less
More
- Posts: 544
- Thank you received: 105
10 Jun 2020 12:18 #170956
by bbsr_5a
Replied by bbsr_5a on topic Request G6, Ellipse and G7, bezier curve
most cam will split this bezier in 2-3 regulair radius ones
never have had any problem on this on freecad or sheetcam with imported DXF
freecad draft can also make you regular rad out of bezier
never have had any problem on this on freecad or sheetcam with imported DXF
freecad draft can also make you regular rad out of bezier
The following user(s) said Thank You: Grotius
Please Log in or Create an account to join the conversation.
- Aciera
- Offline
- Administrator
Less
More
- Posts: 4025
- Thank you received: 1735
10 Jun 2020 13:08 #170958
by Aciera
Replied by Aciera on topic Request G6, Ellipse and G7, bezier curve
Sounds interesting BUT
It seems to me that NURBS-interpolation has kind of fallen by the wayside in professional machine controllers due to the increase in processing speed and memory size.
What CAM can actually output the code required for NURBS interpolation on the controller?
It seems to me that NURBS-interpolation has kind of fallen by the wayside in professional machine controllers due to the increase in processing speed and memory size.
What CAM can actually output the code required for NURBS interpolation on the controller?
The following user(s) said Thank You: Grotius
Please Log in or Create an account to join the conversation.
- Grotius
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 2251
- Thank you received: 1990
10 Jun 2020 13:46 #170961
by Grotius
Replied by Grotius on topic Request G6, Ellipse and G7, bezier curve
Hi Rod,
I also want to make some changes to the core code. Maybe we can work together...
Is oke for me. Did you already find out how to make a external c connection to hal?
If not, let me know over here. What change do you want to make?
I think the new G code will need to align with an existing gcode flavour so that there is post processor support.
I agree. But for 99% of the cam program's it will not work at this moment.
They have to improve their source code first.
For my CadCam program this new Gcode is working right away, this is how i would like to see a Cam program shitting out some gcode. High end gcode output. It opens more then only that. Pockets algoritmes, build up from splines. Wow.
@Aciera,
Sounds interesting BUT
It seems to me that NURBS-interpolation has kind of fallen by the wayside in professional machine controllers due to the increase in processing speed and memory size.
Nurbs are a kind of special. I never seen them around in dxf files. More common used one's are splines, ellipses and beziers.
I like the Nurbs idea and tested them yesterday in linuxcnc. A spline path instead of a nurb path can be considered as a good alternative.
What CAM can actually output the code required for NURBS interpolation on the controller?
That's the whole point. Now is the time to get Cam outputs in line with Cad data, and now is the time to get the EMC software up to date to do this job.
@bbsr,
most cam will split this bezier in 2-3 regulair radius ones
So far i know, sheetcam, dxf2gcode, pronest, etc will shit out thousands of line segments instead of one line of special G5 code.
And it is loosing path accuracy this way. For a cnc electron microscope, or a stealth fighter you can not interpolate this way.
never have had any problem on this on freecad or sheetcam with imported DXF
Actual, there is no real problem. There is a linuxcnc source code improvent request.
freecad draft can also make you regular rad out of bezier
But linuxcnc don't accepts this kind of shapes today. If linuxcnc has this option, you will see all cam program's will
improve their souce code.
I also want to make some changes to the core code. Maybe we can work together...
Is oke for me. Did you already find out how to make a external c connection to hal?
If not, let me know over here. What change do you want to make?
I think the new G code will need to align with an existing gcode flavour so that there is post processor support.
I agree. But for 99% of the cam program's it will not work at this moment.
They have to improve their source code first.
For my CadCam program this new Gcode is working right away, this is how i would like to see a Cam program shitting out some gcode. High end gcode output. It opens more then only that. Pockets algoritmes, build up from splines. Wow.
@Aciera,
Sounds interesting BUT
It seems to me that NURBS-interpolation has kind of fallen by the wayside in professional machine controllers due to the increase in processing speed and memory size.
Nurbs are a kind of special. I never seen them around in dxf files. More common used one's are splines, ellipses and beziers.
I like the Nurbs idea and tested them yesterday in linuxcnc. A spline path instead of a nurb path can be considered as a good alternative.
What CAM can actually output the code required for NURBS interpolation on the controller?
That's the whole point. Now is the time to get Cam outputs in line with Cad data, and now is the time to get the EMC software up to date to do this job.
@bbsr,
most cam will split this bezier in 2-3 regulair radius ones
So far i know, sheetcam, dxf2gcode, pronest, etc will shit out thousands of line segments instead of one line of special G5 code.
And it is loosing path accuracy this way. For a cnc electron microscope, or a stealth fighter you can not interpolate this way.
never have had any problem on this on freecad or sheetcam with imported DXF
Actual, there is no real problem. There is a linuxcnc source code improvent request.
freecad draft can also make you regular rad out of bezier
But linuxcnc don't accepts this kind of shapes today. If linuxcnc has this option, you will see all cam program's will
improve their souce code.
The following user(s) said Thank You: tommylight, rodw
Please Log in or Create an account to join the conversation.
- Aciera
- Offline
- Administrator
Less
More
- Posts: 4025
- Thank you received: 1735
10 Jun 2020 14:45 #170965
by Aciera
Replied by Aciera on topic Request G6, Ellipse and G7, bezier curve
I see you're an optimist! Good on ya!If linuxcnc has this option, you will see all cam program's will
improve their souce code.
The following user(s) said Thank You: tommylight, Grotius
Please Log in or Create an account to join the conversation.
Time to create page: 0.161 seconds