Converting G2 / G3 to start angle / stop angle / radius

Discussions around the CAM Add-On of QCAD.

Moderator: andrew

Post Reply
Jeff66
Newbie Member
Posts: 5
Joined: Fri Jul 03, 2020 8:02 am

Converting G2 / G3 to start angle / stop angle / radius

Post by Jeff66 » Tue Jul 14, 2020 10:06 am

Hi everyone

Everything is almost in the subject. I need to convert G2 / G3 to something like
F26 "Start Angle" "Stop Angle" "Radius" (Clockwise)
F27 "Start Angle" "Stop Angle" "Radius" (CCW)

Any usefull tips ?

CVH
Premier Member
Posts: 775
Joined: Wed Sep 27, 2017 4:17 pm
Location: Belgium; Antwerp

Re: Converting G2 / G3 to start angle / stop angle / radius

Post by CVH » Tue Jul 14, 2020 3:03 pm

Hi,
What dialect/machine is that? :o
'F', is that not the reserved code for Feed in G-code?
F26 would be: Set Feed to 26units/minute. :wink:

Exporters are configurable, so arc X to your F26/27 won't be a problem.
All the specifics are ready available. (Begin- /End angle, radius, reversed)
Andrew can explain you how.

On the other hand if the source is G-code you'll need to apply some basic trig math. e_geek
R would be sqrt(i²+j²) (and as 'distance' always positive)
G-code is consecutive and only includes the end position.
The End-angle can be found as the angle of the line from the center-point to the endpoint.
The center-point can be found by applying i and j on X and Y.
For the Begin-angle you'll need the final position of the previous command.

A trig pitfall could be the 'G2 or G3 side' where the center is located and the positive radius. :wink:

Hopes this helps a little

Regards,
CVH
QCADpro 3.24.3.0 / win7pro 32 bit / 4GB / 1e generation i7 2.6Ghz / HDD GeForce GT 520

Jeff66
Newbie Member
Posts: 5
Joined: Fri Jul 03, 2020 8:02 am

Re: Converting G2 / G3 to start angle / stop angle / radius

Post by Jeff66 » Tue Jul 14, 2020 4:24 pm

Hi CVF
Thanks for your reply.

The machine I'm using doesn't understand G-Code. It's a very specifi command made for turning. I wrote a post about it : https://www.qcad.org/rsforum/viewtopic. ... 6f31204df6

You can take a look at the various functions here : http://www.kolly.ch/wp-content/uploads/ ... nglish.pdf

You're almost right with F26 for a controller that understand GCode. On mine it's either F0 to F9 (no space) for pre-set feed values, or F xxx (with a space) wich means Feed at xxx mm/min. F26 / F27 are functions that acts like G2 / G3 with G-Code except that the syntax is F26 "Start angle" "Stop angle" "Radius".

My problem is how to write the postprocessor to translate I/J/IA/JA/RADIUS/DIAMETER/SWEEP to the values that I need.
I wonder if there is existing variables for start / end angle in QCad ? Or if someone could help me with js ?

If you have any idea / tips you're welcome
Jeff

CVH
Premier Member
Posts: 775
Joined: Wed Sep 27, 2017 4:17 pm
Location: Belgium; Antwerp

Re: Converting G2 / G3 to start angle / stop angle / radius

Post by CVH » Tue Jul 14, 2020 11:31 pm

I am not a QCAM guy.
Jeff66 wrote:
Tue Jul 14, 2020 4:24 pm
I/J/IA/JA/RADIUS/DIAMETER/SWEEP
Is that what you have to work with?
Not quite standard G-code.

In QCAD & javascript for an RArc entity you have: e_geek
RArc.getCenter()
Rarc.getRadius()
RArc.getStartAngle()
Rarc.getEndAngle()
RArc.isReversed ()
That should cover F26/27

From G2/3 X,Y,I,J the way is pure math and explaind.
I presume the relative version works with I IA J JA.
Strange that you mention and RADIUS, and DIAMETER and on top of that the SWEEP as parameters ...
Or is that the radius form.

Regards,
CVH
Last edited by CVH on Wed Jul 15, 2020 9:04 am, edited 1 time in total.
QCADpro 3.24.3.0 / win7pro 32 bit / 4GB / 1e generation i7 2.6Ghz / HDD GeForce GT 520

CVH
Premier Member
Posts: 775
Joined: Wed Sep 27, 2017 4:17 pm
Location: Belgium; Antwerp

Re: Converting G2 / G3 to start angle / stop angle / radius

Post by CVH » Wed Jul 15, 2020 8:44 am

Pictures say more then words:
The 'relative' is a big guess. :wink:
CVH
PS Remember to catch the limits of the Atan2 function.
Attachments
G-code2Polar.dxf
(118.26 KiB) Downloaded 15 times
QCADpro 3.24.3.0 / win7pro 32 bit / 4GB / 1e generation i7 2.6Ghz / HDD GeForce GT 520

Jeff66
Newbie Member
Posts: 5
Joined: Fri Jul 03, 2020 8:02 am

Re: Converting G2 / G3 to start angle / stop angle / radius

Post by Jeff66 » Wed Jul 15, 2020 2:26 pm

Thank you CVH for the drawing, it's very clear and it helps ! :wink:

My main problem is not related to trigonometry and/or understanding GCode and how G2/G3 works. Despite the fact I did some programming in my young ages e_geek , my main issue is I'm not at ease with javascript... :oops: :roll:

Example, I changed the angle to degrees using this :
this.registerVariable("arcSweep", "SWEEP", true, "", "DEFAULT", { factor: 360/Math.PI/2 });

It works. but is it the best way to do it ? Should I have used RMath.rad2deg() instead ? And how ?

Other question, you mentionned Rarc.getStartAngle(). How should I / could I use it in my postprocessor ? Where coud I find resources / explanations about this specific function ?

Generally, is there some documentation on the various CL-data ressources used by QCad ? (Or BTW a good "javascript for dummies" book... :wink: )

Finaly, since my command doesn't understand GCode, I wonder if I'd rather write my postprocessor from scratch rather than starting from a copy of GCodebase. My command is not complicated. The only difficulty I'm having is with my circular interpolation functions. If someone could help me on how to write this in the postprocessor would be very helpfull.

(Either using this RArc.getStartAngle() or using the atan() function) or any other way of getting these start / end angles)

Thanks in advance !
Jeff

User avatar
andrew
Site Admin
Posts: 6917
Joined: Fri Mar 30, 2007 6:07 am

Re: Converting G2 / G3 to start angle / stop angle / radius

Post by andrew » Wed Jul 15, 2020 3:47 pm

For the start angle / end angle of an arc:

In your constructor:

Code: Select all

// define new variables:
this.arcStartAngle = undefined;
this.registerVariable("arcStartAngle", "STARTANGLE", true, "", "DEFAULT", "DEFAULT");
this.arcEndAngle = undefined;
this.registerVariable("arcEndAngle", "ENDANGLE", true, "", "DEFAULT", "DEFAULT");

...
// use new variables for arcs:
this.arcCWMove =  ["... [STARTANGLE] [ENDANGLE] ..."];
this.firstArcCWMove = this.arcCWMove;
this.arcCCWMove =  ["... [STARTANGLE] [ENDANGLE] ..."];
this.firstArcCCWMove = this.arcCCWMove;
Override function "writeEntity":

Code: Select all

MyPostProcessor.prototype.writeEntity = function() {
    // initialize additional variables:
    if (isArcEntity(this.currentEntity)) {
        this.arcStartAngle = this.currentEntity.getStartAngle();
        this.arcEndAngle = this.currentEntity.getEndAngle();
    }
    else {
        this.arcStartAngle = undefined;
        this.arcEndAngle = undefined;
    }

    GCodeBase.prototype.writeEntity.call(this);
};
Lots of assumptions here, but that's basically how you can add entity dependent variables.

CVH
Premier Member
Posts: 775
Joined: Wed Sep 27, 2017 4:17 pm
Location: Belgium; Antwerp

Re: Converting G2 / G3 to start angle / stop angle / radius

Post by CVH » Wed Jul 15, 2020 4:03 pm

Wasn't my first question:
Post-processor or G-code translator?

Again I am not a QCAM guy, that is for Andrew.
And he replied just now ... :P
Jeff66 wrote:
Wed Jul 15, 2020 2:26 pm
Generally, is there some documentation on the various CL-data resources used by QCad ? (Or BTW a good "javascript for dummies" book... :wink: )
No, info is scarce. :(
You could try Qcad Classes: :wink:
https://www.qcad.org/doc/qcad/latest/de ... index.html

I can't find a source of GCodebase.js so I am not aware how this script acts ...
Searched 2 drives, the Qcad masters at github and the net.
Jeff66 wrote:
Wed Jul 15, 2020 2:26 pm
{ factor: 360/Math.PI/2 }
{ factor: 180/Math.PI } is one division less for start.
RMath.rad2deg() is about the same as rad2deg().
The plain version is from input.js the other is the standard Math lib parsed as RMath ...
I got the advise from Andrew to not use those from input.js but you can't avoid them everywhere.
Input.js is partially in degrees as I remember.

JavaScript isn't that hard to master a bit. :wink:
What and how to do things under QCAD is more vage. :|

Regards,
CVH
QCADpro 3.24.3.0 / win7pro 32 bit / 4GB / 1e generation i7 2.6Ghz / HDD GeForce GT 520

Post Reply

Return to “QCAD/CAM”