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

Discussions around the CAM Add-On of QCAD.

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Indicate the post processor used.

Attach drawing files and screenshots.

Post one question per topic.

CVH
Premier Member
Posts: 3415
Joined: Wed Sep 27, 2017 4:17 pm

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

Post by CVH » Thu Oct 15, 2020 9:13 am

Jeff66 wrote:
Thu Oct 15, 2020 6:54 am
I solved it by changing it on my prototype
Simply 'rad2deg(val)' is the method from input.js
These are used for math expressions in many UI input fields.

I don't know if the rule aplies to QCAM.
Andrew has advised not to use these in scripting.
He advised to use RMath.rad2deg(val). e_geek

But one can find the use of both in the QCAD project scripts.

input.js implements two functions called 'rad2deg(val)' and 'deg2rad(val)'
library.js also implements two functions called 'rad2deg(val)' and 'deg2rad(val)'
Finally Rmath.ccp has similar entries addressed with RMath.
The only differences are how the factor is aplied: 2*PI for 360 or PI for 180.
I would preffer the short route. :roll:

RMath.deg2rad has 26 hits in 19 files of 1014
Except for input.js, library.js and the simple scripts only InvoluteSpur.js and Counter.js use the method without the RMath.
The first is of hands of Iain Hibbert and the latter is by Robert S.
Most other scripts are from the hand of Andrew.

I would stick to RMath.rad2deg(val) & RMath.deg2rad(val) even with the '2*PI for 360'. :wink:

Regards
CVH

Jeff66
Junior Member
Posts: 10
Joined: Fri Jul 03, 2020 8:02 am

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

Post by Jeff66 » Thu Oct 15, 2020 10:27 am

Basically my postprocessor is working except for this leading 0 issue. I tried various ways but none of them work. I'm must say I'm not at ease with js nor with the derivation from GCodeBase and prototype ... I'm able to generate the toolpath but I get no output in my cn file.

My postprocessor is based on CamExporterV2 :

function ERICodeBase(cadDocumentInterface, camDocumentInterface) {
// call constructor of base class 'CamExporterV2':
CamExporterV2.call(this, cadDocumentInterface, camDocumentInterface);

...

I added some variables definition :

// Start and End angle definiton for F26 and F27 circular interpolation
this.arcStartAngle = undefined;
this.arcEndAngle = undefined;
this.feedRate2 = undefined;
this.textfeedRate = undefined ;
this.textfeedRate2 = undefined ;
...
this.registerVariable("feedRate", "F", false, "", 0);
this.registerVariable("feedRate2", "F2", false, "", "DEFAULT", "DEFAULT");
...


Since I do the conversion later, my variables look like this in the postprocessor :

this.registerVariable("arcStartAngle", "STARTANGLE", true, "", "DEFAULT", "DEFAULT");
this.registerVariable("arcEndAngle", "ENDANGLE", true, "", "DEFAULT", "DEFAULT");


This is working as well :

this.firstArcCWMove = [
"F25 [F2!] F26 [STARTANGLE] [ENDANGLE] [RADIUS]"
];


And this is what I have in my prototype :

ERICodeMM.prototype.writeEntity = function() {
// initialize additional variables:
if (isArcEntity(this.currentEntity)) {
this.arcStartAngle = (rad2deg(this.currentEntity.getStartAngle()) + 90) % 360;
this.arcEndAngle = (rad2deg(this.currentEntity.getEndAngle()) + 90) % 360;
}
else {
this.arcStartAngle = undefined;
this.arcEndAngle = undefined;
}

// Initialize FeedRate2 for Circular interpolation
this.feedRate2 = this.feedRate / 2;


---> It works down to here, but as soon as I try to use some of the code below, despite I'm still able to genereate the toolpath, my output .nc file is empty. Any idea ?

/*
// Converting feedRate and feedRate2 to 3 digits - Version 1
this.num = undefined ;
this.size = undefined ;

function pad(num , size) {
num = num.toString();
while (num.length < size) num = "0" + num;
return num;
}

this.feedRate = pad(feedRate,3);
this.feedRate2 = pad(feedRate2,3);
*/

/*
// Converting feedRate and feedRate2 to 3 digits - Version 2
textfeedRate = "0" + feedRate ;
feedRate = textfeedRate.right(3) ;

textfeedRate2 = "0" + feedRate2 ;
feedRate2 = textfeedRate2.sub(-3);
*/
ERICodeBase.prototype.writeEntity.call(this);
};


CVH
Premier Member
Posts: 3415
Joined: Wed Sep 27, 2017 4:17 pm

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

Post by CVH » Thu Oct 15, 2020 3:03 pm

First : 'feedrate' is not equal to 'this.feedrate' ... and 'this' relies on the scope.
Nor is 'feedrate2' equal to 'this.feedrate2'.

Second : Good practice is to declare new variables with var.


Jeff66 wrote:
Thu Oct 15, 2020 10:27 am
function pad(num , size) {
num = num.toString();
while (num.length < size) num = "0" + num;
return num;
}
A: One doesn't have to make it a string first ... "0" + num will result in a string if num is a valid number or a string itself.
B: The While will run once and return num directly on the first run.
It is: do { .... } while (cond); or while (cond) { .... };


Don't think that padding is implemented under our ECMAscript.


If this works:
Jeff66 wrote:
Thu Oct 15, 2020 10:27 am
// Initialize FeedRate2 for Circular interpolation
this.feedRate2 = this.feedRate / 2;
What does this do?

Code: Select all

// Initialize FeedRate2 for Circular interpolation
var textFeed;
textFeed = "000" + Math.round(this.feedRate);
this.feedRate = textFeed.right(3);
textFeed = "000" + Math.round(this.feedRate / 2);
this.feedRate2 = textFeed.right(3);
Regards,
CVH

Jeff66
Junior Member
Posts: 10
Joined: Fri Jul 03, 2020 8:02 am

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

Post by Jeff66 » Fri Oct 16, 2020 12:59 pm

Many thanks, it works !

Post Reply

Return to “QCAD/CAM”