Skip to content

Commit b71b350

Browse files
authored
Compensation by steps and Tolerance added
1 parent 9374793 commit b71b350

1 file changed

Lines changed: 110 additions & 80 deletions

File tree

UltimateRRPost.cps

Lines changed: 110 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,19 @@
44
All rights reserved.
55

66

7-
$R 1.01 $
8-
$Date: 2021-03-18 00:58:12 $
7+
$R 1.5 $
8+
$Date: 2021-03-17 20:17:38 $
99

10-
FORKID {A4D747BD-FEEF-4CE2-86CD-0D56966792FA}
1110
*/
1211

13-
description = "JINNI Post-Processor - Duet RepRap w/Tool Change";
12+
description = "JINNI Post for RepRap w/Tool Change & Backlash Compensator";
1413
vendor = "JINNITECH";
1514
vendorUrl = "http://www.jinnitech.com";
1615
legal = "Copyright (C) 2012-2018 by Autodesk, Inc.";
1716
certificationLevel = 2;
1817
minimumRevision = 24000;
1918

20-
longDescription = "JINNI's Post-Processor for Duet3D Cntrlr w/ RepRap by Bruce";
19+
longDescription = "JINNI's Post-Processor for RepRap by Bruce";
2120
setCodePage("ascii");
2221

2322
capabilities = CAPABILITY_MILLING;
@@ -82,13 +81,14 @@ properties = {
8281
useM6: false, // disable to avoid M6 output - preload is also disabled when M6 is disabled
8382
preloadTool: false, // (Unsupported)preloads next tool on tool change if any
8483
applyBacklashCompensation: true,
85-
backlashCompensationMethod: "steps",
8684
measuredBacklashXFor1mm:0, // in millimetre
8785
measuredBacklashXFor10mm:0, // in millimetre
8886
measuredBacklashYFor1mm:0, // in millimetre
8987
measuredBacklashYFor10mm:0, // in millimetre
9088
measuredBacklashZFor1mm:0, // in millimetre
9189
measuredBacklashZFor10mm:0, // in millimetre
90+
backlashCompensationMethod: "steps",
91+
backlashCompensationTolerance: 0.05,
9292
stepsPerUnitX: 400,
9393
stepsPerUnitY: 400,
9494
stepsPerUnitZ: 400,
@@ -310,23 +310,28 @@ propertyDefinitions = {
310310
{ title: "Without spindle direction", id: "without" }
311311
]
312312
},
313-
314313
applyBacklashCompensation: {
315314
title: "Apply Backlash Compensation",
316315
description: "Compensate for backlash in motion motor direction changes",
317316
group: groupNames[8],
318317
type: "boolean"
319318
},
320-
backlashCompensationMethod:{
319+
backlashCompensationMethod: {
321320
title: "Backlash Compensation Method",
322321
description: "Choose the desired methods to compensate for the backlash: Steps or Distance. Steps method (preferred) compensates with calculating and adding extra steps needed to compensate without modifying the motion distance. This preseves the tool coordinate as created by CAM. Distance methods calculates and adds slightly extra distance to affected motions to compensate for the backlash, without altering the steps. Distance method if for occassions that you don't know the Step Per Unit (set by M92) configuratin.",
323322
group: groupNames[8],
324323
type: "enum",
325324
values: [
326-
{ title: "Adding to Steps", id: "steps"},
327-
{ title: "Adding to Distance", id: "distance"}
325+
{ title: "Steps", id: "steps" },
326+
{ title: "Distance", id: "distance" }
328327
]
329328
},
329+
backlashCompensationTolerance: {
330+
title: "Accuracy tolerance",
331+
description: "Changes in motion direction for distances below the tolerance threshold won't trigger backlash compensation",
332+
group: groupNames[8],
333+
type: "number"
334+
},
330335
stepsPerUnitX: {
331336
title: "X Axis Steps Per Unit [Only for Steps Method]",
332337
description: "Get this from M92 X command in config.g ",
@@ -435,8 +440,13 @@ var bCompensation = {
435440
x10: Number(properties.measuredBacklashXFor10mm),
436441
y10: Number(properties.measuredBacklashYFor10mm),
437442
z10: Number(properties.measuredBacklashZFor10mm),
438-
stepsPerUnit: [stepsPerUnitX, stepsPerUnitY, stepsPerUnitZ],
439-
lastM92: [stepsPerUnitX, stepsPerUnitY, stepsPerUnitZ],
443+
stepsPerUnit: [
444+
Number(properties.stepsPerUnitX),
445+
Number(properties.stepsPerUnitY),
446+
Number(properties.stepsPerUnitZ)
447+
],
448+
tolerance: 0.05,
449+
lastM92: [0,0,0],
440450
firstTime: [true, true, true], // for x, y, z
441451
firstMove: [true, true, true],
442452
lastRequestedPosition: [0, 0, 0],
@@ -1043,38 +1053,40 @@ function onSection() {
10431053
// handelling dwell for catchup
10441054
// dwell for spindle rpm to settle (30Second for each 12000rpm - Min 5 sec)
10451055
// but only dwell if RPM or direction is changed
1046-
if (parseInt(bTool.lastRpm) != parseInt(tool.spindleRPM)) {
1047-
// rpms are different
1048-
var rpmDiff = parseInt(Math.abs(bTool.lastRpm - tool.spindleRPM));
1049-
// updating the last rpm value for the next use
1050-
bTool.lastRpm = parseInt(tool.spindleRPM);
1051-
// calculating required dwell duration
1052-
var bruceDwellSec = secFormat.format(rpmDiff * Number(properties.spindleRPMCatchupTime6K) / 6000);
1053-
bruceDwellSec *= catchupTimeMultiplier;
1054-
var toMilli = 1;
1055-
if (properties.dwellInSeconds) {
1056-
// system is set to milliseconds
1057-
toMilli = 1000;
1058-
} else {
1059-
toMilli = 1;
1060-
}
1061-
if (bruceDwellSec < 5) {
1062-
bruceDwellSec = 5;
1063-
}
1064-
writeComment("LOGGING-> Dwelling for Spindle RPM change to catchup");
1065-
bDialog("Dwelling for "+bruceDwellSec+" seconds, for the spindle RPM to catch up", "Dwelling "+programName, 100+bruceDwellSec, false);
1066-
// breaking dwell in smaller chunks if longer than 20 seconds to keep RepRap happy :)
1067-
if (bruceDwellSec > 20) {
1068-
while (bruceDwellSec > 15) {
1069-
onDwell(15*toMilli);
1070-
writeBlock("M450 ;LOGGING-> Here used as a harmless stalling command that reports status");
1071-
bruceDwellSec = parseInt(Number(bruceDwellSec)-15);
1056+
if (tool.spindleRPM != 0) {
1057+
if (parseInt(bTool.lastRpm) != parseInt(tool.spindleRPM)) {
1058+
// rpms are different
1059+
var rpmDiff = parseInt(Math.abs(bTool.lastRpm - tool.spindleRPM));
1060+
// updating the last rpm value for the next use
1061+
bTool.lastRpm = parseInt(tool.spindleRPM);
1062+
// calculating required dwell duration
1063+
var bruceDwellSec = secFormat.format(rpmDiff * Number(properties.spindleRPMCatchupTime6K) / 6000);
1064+
bruceDwellSec *= catchupTimeMultiplier;
1065+
var toMilli = 1;
1066+
if (properties.dwellInSeconds) {
1067+
// system is set to milliseconds
1068+
toMilli = 1000;
1069+
} else {
1070+
toMilli = 1;
1071+
}
1072+
if (bruceDwellSec < 5) {
1073+
bruceDwellSec = 5;
1074+
}
1075+
writeComment("LOGGING-> Dwelling for Spindle RPM change to catchup");
1076+
bDialog("Dwelling for "+bruceDwellSec+" seconds, for the spindle RPM to catch up", "Dwelling "+programName, 100+bruceDwellSec, false);
1077+
// breaking dwell in smaller chunks if longer than 20 seconds to keep RepRap happy :)
1078+
if (bruceDwellSec > 20) {
1079+
while (bruceDwellSec > 15) {
1080+
onDwell(15*toMilli);
1081+
writeBlock("M450 ;LOGGING-> Here used as a harmless stalling command that reports status");
1082+
bruceDwellSec = parseInt(Number(bruceDwellSec)-15);
1083+
}
1084+
}
1085+
if (parseInt(bruceDwellSec) > 1) {
1086+
onDwell(bruceDwellSec*toMilli);
10721087
}
10731088
}
1074-
if (parseInt(bruceDwellSec) > 1) {
1075-
onDwell(bruceDwellSec*toMilli);
1076-
}
1077-
}
1089+
}// If Spindle speed is set to 0 it's probably the end of the programme
10781090
} // if not tapping
10791091
} // bRprmChangeCheck
10801092

@@ -1182,9 +1194,6 @@ function onRadiusCompensation() {
11821194
}
11831195

11841196
function onRapid(_x, _y, _z) {
1185-
// var x = xOutput.format(_x);
1186-
// var y = yOutput.format(_y);
1187-
// var z = zOutput.format(_z);
11881197
bflushAcCompErPerMotionCount();
11891198
var x = xOutput.format(axialBacklashCompensation(0,_x));
11901199
var y = yOutput.format(axialBacklashCompensation(1,_y));
@@ -1200,9 +1209,6 @@ function onRapid(_x, _y, _z) {
12001209
}
12011210

12021211
function onLinear(_x, _y, _z, feed) {
1203-
// var x = xOutput.format(_x);
1204-
// var y = yOutput.format(_y);
1205-
// var z = zOutput.format(_z);
12061212
bflushAcCompErPerMotionCount();
12071213
var x = xOutput.format(axialBacklashCompensation(0,_x));
12081214
var y = yOutput.format(axialBacklashCompensation(1,_y));
@@ -1891,12 +1897,6 @@ function setupBacklashCompensation() {
18911897
bCompensation.x10 = Number(properties.measuredBacklashXFor10mm);
18921898
bCompensation.y10 = Number(properties.measuredBacklashYFor10mm);
18931899
bCompensation.z10 = Number(properties.measuredBacklashZFor10mm);
1894-
bCompensation.stepsPerUnit: [
1895-
Number(stepsPerUnitX),
1896-
Number(stepsPerUnitY),
1897-
Number(stepsPerUnitZ)
1898-
];
1899-
bCompensation.lastM92 = bCompensation.stepsPerUnit;
19001900
if (
19011901
bCompensation.x1 > 1.5 ||
19021902
bCompensation.x10 > 2.5 ||
@@ -1908,16 +1908,23 @@ function setupBacklashCompensation() {
19081908
error("Backlash is too large, you'll be better off cutting with a wooden knife than this CNC machine");
19091909
}
19101910
// bCompensation.motionCounter = Number(properties.bCompensationCount);
1911+
bCompensation.stepsPerUnit = [
1912+
Number(properties.stepsPerUnitX),
1913+
Number(properties.stepsPerUnitY),
1914+
Number(properties.stepsPerUnitZ)
1915+
];
1916+
bCompensation.tolerance = properties.backlashCompensationTolerance;
1917+
bCompensation.lastM92 = bCompensation.stepsPerUnit.slice(); // starting both arrays from the same values
19111918
if (properties.applyBacklashCompensation) {
19121919
writeln ("; ------------------------------------------------------------")
19131920
writeln ("; Backlash compensation on motor direction changes are applied");
19141921
writeln ("; Backlash values on X: " +bCompensation.x1 +"..."+ bCompensation.x10);
19151922
writeln ("; Backlash values on Y: " +bCompensation.y1 +"..."+ bCompensation.y10);
19161923
writeln ("; Backlash values on Z: " +bCompensation.z1 +"..."+ bCompensation.z10);
1917-
if (backlashCompensationMethod == "steps") {
1918-
writeln ("; - Compensation by Steps Per Unit adjustments");
1919-
writeln ("; - Steps Per Unit: M92"
1920-
+ " X"+ bCompensation.stepsPerUnit[0]
1924+
if (properties.backlashCompensationMethod == "steps") {
1925+
writeln ("; - Compensation by Steps Per Unit adjustments");
1926+
writeln ("; - Steps Per Unit: M92"
1927+
+ " X" + bCompensation.stepsPerUnit[0]
19211928
+ " Y" + bCompensation.stepsPerUnit[1]
19221929
+ " Z" + bCompensation.stepsPerUnit[2]
19231930
);
@@ -1930,46 +1937,68 @@ function setupBacklashCompensation() {
19301937
}
19311938

19321939
function axialBacklashCompensation(axis,_value) {
1933-
if (backlashCompensationMethod == "distance") {
1934-
return axialBacklashCompensationByDistance(axis,_value);
1935-
} else {
1936-
return axialBacklashCompensationBySteps (axis, _value);
1940+
if (properties.applyBacklashCompensation) {
1941+
if (properties.backlashCompensationMethod == "distance") {
1942+
return axialBacklashCompensationByDistance(axis,_value);
1943+
} else {
1944+
return axialBacklashCompensationBySteps (axis, _value);
1945+
}
19371946
}
1947+
return _value;
19381948
}
19391949

19401950
function axialBacklashCompensationBySteps (axis, _value) {
1941-
let compensationDistanceDiff;
1942-
var axisLetter = ["X", "Y", "Z"];
1943-
compensationDistanceDiff = axialBacklashCompensationByDistance(axis,_value) - _value;
1944-
if (isMoveReallyNeeded(axis,_value)) {
1945-
let compensatedNumberOfSteps = (bCompensation.stepsPerUnit[axis] * compensationDistanceDiff) + bCompensation.stepsPerUnit[axis];
1946-
if (bCompensation.lastM92[axis] != compensatedNumberOfSteps) {
1947-
writeComment("Adjusting steps/unit");
1948-
writeBlock("M92 " + axisLetter[axis] + compensatedNumberOfSteps.toString());
1949-
bCompensation.lastM92[axis] = compensatedNumberOfSteps; // for the next check
1950-
}
1951-
}
1952-
return _value; // _value is unchanged. All we do is adjusting the steps per unit via M92
1951+
if (!bCompensation.isFirstTime(axis)) {
1952+
var axisLetter = ["X", "Y", "Z"];
1953+
if (isMoveReallyNeeded(axis,_value)) {
1954+
var diff = getBacklashCompensationValue (axis, _value, bCompensation.oldPos[axis])
1955+
// calculating and setting steps per unit
1956+
if (diff != 0) {
1957+
// diff not 0 so we know direction is changed and compensation is available
1958+
let motionDistance = Math.abs(_value - bCompensation.oldPos[axis]);
1959+
if (motionDistance != 0 && motionDistance > bCompensation.tolerance) {
1960+
let compensatedSteps = (motionDistance + Math.abs(diff)) * bCompensation.stepsPerUnit[axis] / motionDistance;
1961+
if (compensatedSteps != bCompensation.lastM92[axis]) {
1962+
// setting a new M92 for this move
1963+
writeBlock("M92 "+axisLetter[axis]+compensatedSteps);
1964+
bCompensation.lastM92[axis] = compensatedSteps;
1965+
} // else current M92 is fine
1966+
}
1967+
} else {
1968+
// no direction change has taken place, so we reset steps per unit to usual
1969+
if (bCompensation.lastM92[axis] != bCompensation.stepsPerUnit[axis]) {
1970+
// avoid unneccessary M92 output
1971+
writeBlock("M92 " + axisLetter[axis] + bCompensation.stepsPerUnit[axis]);
1972+
bCompensation.lastM92[axis] = bCompensation.stepsPerUnit[axis];
1973+
}
1974+
}
1975+
} // no neccessary move - do nothing
1976+
} // this was the first move in the axis - Original M92 is fine
1977+
bCompensation.oldPos[axis] = _value; // resetting the oldValue with a new one for the next use
1978+
bCompensation.lastRequestedPosition[axis] = _value; // updating for the next round
1979+
motionBox.setBox(axis, _value);
1980+
return _value;
19531981
}
19541982

19551983
function axialBacklashCompensationByDistance(axis,_value) {
19561984
if (properties.applyBacklashCompensation) {
19571985
var _holder = _value;
1958-
var axisLetter = ["x", "y", "z"];
1959-
var isMoveReallyNeeded = isMoveReallyNeeded(axis,_value); // check to see if move really needed
1986+
var isThisMoveReallyNeeded = isMoveReallyNeeded(axis,_value); // check to see if move really needed
19601987
bCompensation.lastRequestedPosition[axis] = _value;
19611988
if (bCompensation.isFirstTime(axis)) {
19621989
bCompensation.oldPos[axis] = _holder;
19631990
} else {
1964-
if (isMoveReallyNeeded) {
1991+
if (isThisMoveReallyNeeded) {
19651992
var diff = getBacklashCompensationValue (axis, _value, bCompensation.oldPos[axis])
1966-
_value = _value + diff;
1993+
if (Math.abs(_value - bCompensation.oldPos[axis]) > bCompensation.tolerance) {
1994+
_value = _value + diff;
1995+
}
19671996
bCompensation.oldPos[axis] = _value; // resetting the oldValue with a new one for the next use
19681997
}
19691998
}
19701999
motionBox.setBox(axis, _value);
19712000
}
1972-
bToggleOutput(axis, isMoveReallyNeeded || bCompensation.isFirstTime(axis));
2001+
bToggleOutput(axis, isThisMoveReallyNeeded || bCompensation.isFirstTime(axis));
19732002
return _value;
19742003
}
19752004

@@ -2080,12 +2109,13 @@ function bFlushAccumulatedCompensationError() {
20802109
onDwell(2);
20812110
}
20822111
writeBlock("G1 H1 Z500");
2083-
if (backlashCompensationMethod == "steps") {
2112+
if (properties.backlashCompensationMethod == "steps") {
20842113
writeBlock("M92"
20852114
+ " X" + bCompensation.stepsPerUnit[0]
20862115
+ " Y" + bCompensation.stepsPerUnit[1]
20872116
+ " Z" + bCompensation.stepsPerUnit[2]
20882117
);
2118+
bCompensation.lastM92 = bCompensation.stepsPerUnit.slice(); // resets the entire array
20892119
}
20902120
writeBlock(
20912121
"G0"

0 commit comments

Comments
 (0)