@duet3d/monacotokens 3.5.0 → 3.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -16
- package/dist/monaco-gcode.d.ts +1 -5
- package/dist/monaco-gcode.js +7 -9
- package/package.json +1 -1
- package/dist/analysis.d.ts +0 -22
- package/dist/analysis.js +0 -42
- package/dist/fft.d.ts +0 -7
- package/dist/fft.js +0 -203
- package/dist/shapers.d.ts +0 -41
- package/dist/shapers.js +0 -153
package/README.md
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
# MonacoTokens
|
|
2
2
|
|
|
3
|
-
TypeScript library that holds syntax highlighting files for the Monaco editor
|
|
3
|
+
TypeScript library that holds syntax highlighting files for the Monaco editor
|
|
4
|
+
|
|
5
|
+
Currently supported Monaco languages:
|
|
6
|
+
|
|
7
|
+
- `gcode-fdm` (RRF G-code to be used in FFF mode)
|
|
8
|
+
- `gcode-cnc` (RRF G-code to be used in CNC and Laser mode)
|
|
4
9
|
|
|
5
10
|
## Bug reports
|
|
6
11
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import "./monaco-gcode";
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
18
|
-
__exportStar(require("./monaco-gcode"), exports);
|
|
3
|
+
require("./monaco-gcode");
|
package/dist/monaco-gcode.d.ts
CHANGED
package/dist/monaco-gcode.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setMonacoGCodeOptions = void 0;
|
|
4
3
|
const monaco = require("monaco-editor/esm/vs/editor/editor.api");
|
|
5
4
|
/**
|
|
6
|
-
*
|
|
5
|
+
* Generate a Monarch language for RRF-style G-code
|
|
7
6
|
* @param cncMode If true, comments in parentheses are allowed
|
|
8
7
|
*/
|
|
9
|
-
function
|
|
10
|
-
|
|
8
|
+
function generateMonarchLanguage(fdmMode) {
|
|
9
|
+
return {
|
|
11
10
|
consts: ["true", "false", "iterations", "line", "null", "pi", "result", "input"],
|
|
12
11
|
functions: ["abs", "acos", "asin", "atan", "atan2", "cos", "degrees", "exists", "fileexists", "fileread", "floor", "isnan", "max",
|
|
13
12
|
"min", "mod", "radians", "random", "sin", "sqrt", "tan", "vector"],
|
|
@@ -134,9 +133,8 @@ function setMonacoGCodeOptions(fdmMode) {
|
|
|
134
133
|
[/\n/, "", "@popall"]
|
|
135
134
|
]
|
|
136
135
|
}
|
|
137
|
-
}
|
|
136
|
+
};
|
|
138
137
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
monaco.languages.
|
|
142
|
-
setMonacoGCodeOptions(true);
|
|
138
|
+
// Register both gcode-fdm and gcode-cnc languages
|
|
139
|
+
monaco.languages.setMonarchTokensProvider("gcode-fdm", generateMonarchLanguage(true));
|
|
140
|
+
monaco.languages.setMonarchTokensProvider("gcode-cnc", generateMonarchLanguage(false));
|
package/package.json
CHANGED
package/dist/analysis.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Result of a frequency analysis
|
|
3
|
-
*/
|
|
4
|
-
export interface FrequencyAnalysisResult {
|
|
5
|
-
/**
|
|
6
|
-
* Determined frequencies (in Hz)
|
|
7
|
-
*/
|
|
8
|
-
frequencies: number[];
|
|
9
|
-
/**
|
|
10
|
-
* Amplitudes of each axis
|
|
11
|
-
*/
|
|
12
|
-
amplitudes: number[][];
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Analyze the given accelerometer data by computing the ringing frequencies from the samples at a given sampling rate.
|
|
16
|
-
* This effectively performs an FFT on the given data set
|
|
17
|
-
* @param samples Accelerometer samples of each axis
|
|
18
|
-
* @param samplingRate Sampling rate in Hz
|
|
19
|
-
* @param wideBand Perform wide-band analysis (more frequencies)
|
|
20
|
-
* @returns Frequency vs. amplitude per axis
|
|
21
|
-
*/
|
|
22
|
-
export declare function analyzeAccelerometerData(samples: number[][], samplingRate: number, wideBand?: boolean): FrequencyAnalysisResult;
|
package/dist/analysis.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.analyzeAccelerometerData = void 0;
|
|
4
|
-
const fft_1 = require("./fft");
|
|
5
|
-
/**
|
|
6
|
-
* Analyze the given accelerometer data by computing the ringing frequencies from the samples at a given sampling rate.
|
|
7
|
-
* This effectively performs an FFT on the given data set
|
|
8
|
-
* @param samples Accelerometer samples of each axis
|
|
9
|
-
* @param samplingRate Sampling rate in Hz
|
|
10
|
-
* @param wideBand Perform wide-band analysis (more frequencies)
|
|
11
|
-
* @returns Frequency vs. amplitude per axis
|
|
12
|
-
*/
|
|
13
|
-
function analyzeAccelerometerData(samples, samplingRate, wideBand = false) {
|
|
14
|
-
if (samples.length < 1) {
|
|
15
|
-
throw new Error("Too few samples to perform frequency analysis");
|
|
16
|
-
}
|
|
17
|
-
// Determine number of axes, frequency resolution, and number of frequencies to compute
|
|
18
|
-
const numSamples = samples[0].length, freqResolution = samplingRate / numSamples;
|
|
19
|
-
const numFreqs = Math.floor(Math.min(numSamples / 2, (wideBand ? (samplingRate / 2) : 200) / freqResolution));
|
|
20
|
-
// Prepare result
|
|
21
|
-
const result = {
|
|
22
|
-
frequencies: new Array(numFreqs),
|
|
23
|
-
amplitudes: new Array(samples.length)
|
|
24
|
-
};
|
|
25
|
-
for (let i = 0; i < numFreqs; i++) {
|
|
26
|
-
result.frequencies[i] = i * freqResolution + freqResolution / 2;
|
|
27
|
-
}
|
|
28
|
-
for (let axis = 0; axis < samples.length; axis++) {
|
|
29
|
-
// Perform FFT on the samples per axis
|
|
30
|
-
const real = samples[axis].slice(), imag = new Array(numSamples);
|
|
31
|
-
imag.fill(0);
|
|
32
|
-
(0, fft_1.transform)(real, imag);
|
|
33
|
-
// Compute amplitudes
|
|
34
|
-
const amplitudes = new Array(numFreqs);
|
|
35
|
-
for (let k = 1; k <= numFreqs; k++) {
|
|
36
|
-
amplitudes[k - 1] = Math.sqrt(real[k] * real[k] + imag[k] * imag[k]) / numSamples;
|
|
37
|
-
}
|
|
38
|
-
result.amplitudes[axis] = amplitudes;
|
|
39
|
-
}
|
|
40
|
-
return result;
|
|
41
|
-
}
|
|
42
|
-
exports.analyzeAccelerometerData = analyzeAccelerometerData;
|
package/dist/fft.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare function transform(real: Array<number> | Float64Array, imag: Array<number> | Float64Array): void;
|
|
2
|
-
export declare function inverseTransform(real: Array<number> | Float64Array, imag: Array<number> | Float64Array): void;
|
|
3
|
-
export declare function transformRadix2(real: Array<number> | Float64Array, imag: Array<number> | Float64Array): void;
|
|
4
|
-
export declare function transformBluestein(real: Array<number> | Float64Array, imag: Array<number> | Float64Array): void;
|
|
5
|
-
export declare function convolveReal(xvec: Array<number> | Float64Array, yvec: Array<number> | Float64Array, outvec: Array<number> | Float64Array): void;
|
|
6
|
-
export declare function convolveComplex(xreal: Array<number> | Float64Array, ximag: Array<number> | Float64Array, yreal: Array<number> | Float64Array, yimag: Array<number> | Float64Array, outreal: Array<number> | Float64Array, outimag: Array<number> | Float64Array): void;
|
|
7
|
-
export declare function newArrayOfZeros(n: number): Array<number>;
|
package/dist/fft.js
DELETED
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Free FFT and convolution (TypeScript)
|
|
4
|
-
*
|
|
5
|
-
* Copyright (c) 2022 Project Nayuki. (MIT License)
|
|
6
|
-
* https://www.nayuki.io/page/free-small-fft-in-multiple-languages
|
|
7
|
-
*
|
|
8
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
9
|
-
* this software and associated documentation files (the "Software"), to deal in
|
|
10
|
-
* the Software without restriction, including without limitation the rights to
|
|
11
|
-
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
12
|
-
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
13
|
-
* subject to the following conditions:
|
|
14
|
-
* - The above copyright notice and this permission notice shall be included in
|
|
15
|
-
* all copies or substantial portions of the Software.
|
|
16
|
-
* - The Software is provided "as is", without warranty of any kind, express or
|
|
17
|
-
* implied, including but not limited to the warranties of merchantability,
|
|
18
|
-
* fitness for a particular purpose and noninfringement. In no event shall the
|
|
19
|
-
* authors or copyright holders be liable for any claim, damages or other
|
|
20
|
-
* liability, whether in an action of contract, tort or otherwise, arising from,
|
|
21
|
-
* out of or in connection with the Software or the use or other dealings in the
|
|
22
|
-
* Software.
|
|
23
|
-
*/
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.newArrayOfZeros = exports.convolveComplex = exports.convolveReal = exports.transformBluestein = exports.transformRadix2 = exports.inverseTransform = exports.transform = void 0;
|
|
26
|
-
/*
|
|
27
|
-
* Computes the discrete Fourier transform (DFT) of the given complex vector, storing the result back into the vector.
|
|
28
|
-
* The vector can have any length. This is a wrapper function.
|
|
29
|
-
*/
|
|
30
|
-
function transform(real, imag) {
|
|
31
|
-
const n = real.length;
|
|
32
|
-
if (n != imag.length)
|
|
33
|
-
throw new RangeError("Mismatched lengths");
|
|
34
|
-
if (n == 0)
|
|
35
|
-
return;
|
|
36
|
-
else if ((n & (n - 1)) == 0) // Is power of 2
|
|
37
|
-
transformRadix2(real, imag);
|
|
38
|
-
else // More complicated algorithm for arbitrary sizes
|
|
39
|
-
transformBluestein(real, imag);
|
|
40
|
-
}
|
|
41
|
-
exports.transform = transform;
|
|
42
|
-
/*
|
|
43
|
-
* Computes the inverse discrete Fourier transform (IDFT) of the given complex vector, storing the result back into the vector.
|
|
44
|
-
* The vector can have any length. This is a wrapper function. This transform does not perform scaling, so the inverse is not a true inverse.
|
|
45
|
-
*/
|
|
46
|
-
function inverseTransform(real, imag) {
|
|
47
|
-
transform(imag, real);
|
|
48
|
-
}
|
|
49
|
-
exports.inverseTransform = inverseTransform;
|
|
50
|
-
/*
|
|
51
|
-
* Computes the discrete Fourier transform (DFT) of the given complex vector, storing the result back into the vector.
|
|
52
|
-
* The vector's length must be a power of 2. Uses the Cooley-Tukey decimation-in-time radix-2 algorithm.
|
|
53
|
-
*/
|
|
54
|
-
function transformRadix2(real, imag) {
|
|
55
|
-
// Length variables
|
|
56
|
-
const n = real.length;
|
|
57
|
-
if (n != imag.length)
|
|
58
|
-
throw new RangeError("Mismatched lengths");
|
|
59
|
-
if (n == 1) // Trivial transform
|
|
60
|
-
return;
|
|
61
|
-
let levels = -1;
|
|
62
|
-
for (let i = 0; i < 32; i++) {
|
|
63
|
-
if (1 << i == n)
|
|
64
|
-
levels = i; // Equal to log2(n)
|
|
65
|
-
}
|
|
66
|
-
if (levels == -1)
|
|
67
|
-
throw new RangeError("Length is not a power of 2");
|
|
68
|
-
// Trigonometric tables
|
|
69
|
-
let cosTable = new Array(n / 2);
|
|
70
|
-
let sinTable = new Array(n / 2);
|
|
71
|
-
for (let i = 0; i < n / 2; i++) {
|
|
72
|
-
cosTable[i] = Math.cos(2 * Math.PI * i / n);
|
|
73
|
-
sinTable[i] = Math.sin(2 * Math.PI * i / n);
|
|
74
|
-
}
|
|
75
|
-
// Bit-reversed addressing permutation
|
|
76
|
-
for (let i = 0; i < n; i++) {
|
|
77
|
-
const j = reverseBits(i, levels);
|
|
78
|
-
if (j > i) {
|
|
79
|
-
let temp = real[i];
|
|
80
|
-
real[i] = real[j];
|
|
81
|
-
real[j] = temp;
|
|
82
|
-
temp = imag[i];
|
|
83
|
-
imag[i] = imag[j];
|
|
84
|
-
imag[j] = temp;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
// Cooley-Tukey decimation-in-time radix-2 FFT
|
|
88
|
-
for (let size = 2; size <= n; size *= 2) {
|
|
89
|
-
const halfsize = size / 2;
|
|
90
|
-
const tablestep = n / size;
|
|
91
|
-
for (let i = 0; i < n; i += size) {
|
|
92
|
-
for (let j = i, k = 0; j < i + halfsize; j++, k += tablestep) {
|
|
93
|
-
const l = j + halfsize;
|
|
94
|
-
const tpre = real[l] * cosTable[k] + imag[l] * sinTable[k];
|
|
95
|
-
const tpim = -real[l] * sinTable[k] + imag[l] * cosTable[k];
|
|
96
|
-
real[l] = real[j] - tpre;
|
|
97
|
-
imag[l] = imag[j] - tpim;
|
|
98
|
-
real[j] += tpre;
|
|
99
|
-
imag[j] += tpim;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
// Returns the integer whose value is the reverse of the lowest 'width' bits of the integer 'val'.
|
|
104
|
-
function reverseBits(val, width) {
|
|
105
|
-
let result = 0;
|
|
106
|
-
for (let i = 0; i < width; i++) {
|
|
107
|
-
result = (result << 1) | (val & 1);
|
|
108
|
-
val >>>= 1;
|
|
109
|
-
}
|
|
110
|
-
return result;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
exports.transformRadix2 = transformRadix2;
|
|
114
|
-
/*
|
|
115
|
-
* Computes the discrete Fourier transform (DFT) of the given complex vector, storing the result back into the vector.
|
|
116
|
-
* The vector can have any length. This requires the convolution function, which in turn requires the radix-2 FFT function.
|
|
117
|
-
* Uses Bluestein's chirp z-transform algorithm.
|
|
118
|
-
*/
|
|
119
|
-
function transformBluestein(real, imag) {
|
|
120
|
-
// Find a power-of-2 convolution length m such that m >= n * 2 + 1
|
|
121
|
-
const n = real.length;
|
|
122
|
-
if (n != imag.length)
|
|
123
|
-
throw new RangeError("Mismatched lengths");
|
|
124
|
-
let m = 1;
|
|
125
|
-
while (m < n * 2 + 1)
|
|
126
|
-
m *= 2;
|
|
127
|
-
// Trigonometric tables
|
|
128
|
-
let cosTable = new Array(n);
|
|
129
|
-
let sinTable = new Array(n);
|
|
130
|
-
for (let i = 0; i < n; i++) {
|
|
131
|
-
const j = i * i % (n * 2); // This is more accurate than j = i * i
|
|
132
|
-
cosTable[i] = Math.cos(Math.PI * j / n);
|
|
133
|
-
sinTable[i] = Math.sin(Math.PI * j / n);
|
|
134
|
-
}
|
|
135
|
-
// Temporary vectors and preprocessing
|
|
136
|
-
let areal = newArrayOfZeros(m);
|
|
137
|
-
let aimag = newArrayOfZeros(m);
|
|
138
|
-
for (let i = 0; i < n; i++) {
|
|
139
|
-
areal[i] = real[i] * cosTable[i] + imag[i] * sinTable[i];
|
|
140
|
-
aimag[i] = -real[i] * sinTable[i] + imag[i] * cosTable[i];
|
|
141
|
-
}
|
|
142
|
-
let breal = newArrayOfZeros(m);
|
|
143
|
-
let bimag = newArrayOfZeros(m);
|
|
144
|
-
breal[0] = cosTable[0];
|
|
145
|
-
bimag[0] = sinTable[0];
|
|
146
|
-
for (let i = 1; i < n; i++) {
|
|
147
|
-
breal[i] = breal[m - i] = cosTable[i];
|
|
148
|
-
bimag[i] = bimag[m - i] = sinTable[i];
|
|
149
|
-
}
|
|
150
|
-
// Convolution
|
|
151
|
-
let creal = new Array(m);
|
|
152
|
-
let cimag = new Array(m);
|
|
153
|
-
convolveComplex(areal, aimag, breal, bimag, creal, cimag);
|
|
154
|
-
// Postprocessing
|
|
155
|
-
for (let i = 0; i < n; i++) {
|
|
156
|
-
real[i] = creal[i] * cosTable[i] + cimag[i] * sinTable[i];
|
|
157
|
-
imag[i] = -creal[i] * sinTable[i] + cimag[i] * cosTable[i];
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
exports.transformBluestein = transformBluestein;
|
|
161
|
-
/*
|
|
162
|
-
* Computes the circular convolution of the given real vectors. Each vector's length must be the same.
|
|
163
|
-
*/
|
|
164
|
-
function convolveReal(xvec, yvec, outvec) {
|
|
165
|
-
const n = xvec.length;
|
|
166
|
-
if (n != yvec.length || n != outvec.length)
|
|
167
|
-
throw new RangeError("Mismatched lengths");
|
|
168
|
-
convolveComplex(xvec, newArrayOfZeros(n), yvec, newArrayOfZeros(n), outvec, newArrayOfZeros(n));
|
|
169
|
-
}
|
|
170
|
-
exports.convolveReal = convolveReal;
|
|
171
|
-
/*
|
|
172
|
-
* Computes the circular convolution of the given complex vectors. Each vector's length must be the same.
|
|
173
|
-
*/
|
|
174
|
-
function convolveComplex(xreal, ximag, yreal, yimag, outreal, outimag) {
|
|
175
|
-
const n = xreal.length;
|
|
176
|
-
if (n != ximag.length || n != yreal.length || n != yimag.length
|
|
177
|
-
|| n != outreal.length || n != outimag.length)
|
|
178
|
-
throw new RangeError("Mismatched lengths");
|
|
179
|
-
xreal = xreal.slice();
|
|
180
|
-
ximag = ximag.slice();
|
|
181
|
-
yreal = yreal.slice();
|
|
182
|
-
yimag = yimag.slice();
|
|
183
|
-
transform(xreal, ximag);
|
|
184
|
-
transform(yreal, yimag);
|
|
185
|
-
for (let i = 0; i < n; i++) {
|
|
186
|
-
const temp = xreal[i] * yreal[i] - ximag[i] * yimag[i];
|
|
187
|
-
ximag[i] = ximag[i] * yreal[i] + xreal[i] * yimag[i];
|
|
188
|
-
xreal[i] = temp;
|
|
189
|
-
}
|
|
190
|
-
inverseTransform(xreal, ximag);
|
|
191
|
-
for (let i = 0; i < n; i++) { // Scaling (because this FFT implementation omits it)
|
|
192
|
-
outreal[i] = xreal[i] / n;
|
|
193
|
-
outimag[i] = ximag[i] / n;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
exports.convolveComplex = convolveComplex;
|
|
197
|
-
function newArrayOfZeros(n) {
|
|
198
|
-
let result = [];
|
|
199
|
-
for (let i = 0; i < n; i++)
|
|
200
|
-
result.push(0);
|
|
201
|
-
return result;
|
|
202
|
-
}
|
|
203
|
-
exports.newArrayOfZeros = newArrayOfZeros;
|
package/dist/shapers.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Supported input shaper types
|
|
3
|
-
* TODO: Replace this with enum from @duet3d/objectmodel
|
|
4
|
-
*/
|
|
5
|
-
export declare enum InputShaperType {
|
|
6
|
-
ei2 = "ei2",
|
|
7
|
-
ei3 = "ei3",
|
|
8
|
-
mzv = "mzv",
|
|
9
|
-
zvd = "zvd",
|
|
10
|
-
zvdd = "zvdd",
|
|
11
|
-
zvddd = "zvddd"
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Computed factors of an input shaper
|
|
15
|
-
*/
|
|
16
|
-
export interface InputShaperFactors {
|
|
17
|
-
/**
|
|
18
|
-
* Input shaper amplitudes (coefficients)
|
|
19
|
-
*/
|
|
20
|
-
amplitudes: number[];
|
|
21
|
-
/**
|
|
22
|
-
* Input shaper durations (in s)
|
|
23
|
-
*/
|
|
24
|
-
durations: number[];
|
|
25
|
-
}
|
|
26
|
-
/***
|
|
27
|
-
* Compute input shaper amplitudes and durations like RepRapFirmware does
|
|
28
|
-
* @param type Input shaper type
|
|
29
|
-
* @param frequency Target frequency (in Hz)
|
|
30
|
-
* @param dampingFactor Optional damping factor (zeta)
|
|
31
|
-
* @returns Input shaper factors
|
|
32
|
-
*/
|
|
33
|
-
export declare function getInputShaperFactors(type: InputShaperType, frequency: number, dampingFactor?: number): InputShaperFactors;
|
|
34
|
-
/**
|
|
35
|
-
* Compute the damping for the given frequencies with the given input shaper amplitudes and durations
|
|
36
|
-
* @param frequencies Frequencies to compute the damping for
|
|
37
|
-
* @param amplitudes Input shaper amplitudes (coefficients)
|
|
38
|
-
* @param durations Input shaper durations (in s)
|
|
39
|
-
* @returns Damping factor (0..1) per frequency
|
|
40
|
-
*/
|
|
41
|
-
export declare function getInputShaperDamping(frequencies: number[], amplitudes: number[], durations: number[]): number[];
|
package/dist/shapers.js
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getInputShaperDamping = exports.getInputShaperFactors = exports.InputShaperType = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Supported input shaper types
|
|
6
|
-
* TODO: Replace this with enum from @duet3d/objectmodel
|
|
7
|
-
*/
|
|
8
|
-
var InputShaperType;
|
|
9
|
-
(function (InputShaperType) {
|
|
10
|
-
InputShaperType["ei2"] = "ei2";
|
|
11
|
-
InputShaperType["ei3"] = "ei3";
|
|
12
|
-
InputShaperType["mzv"] = "mzv";
|
|
13
|
-
InputShaperType["zvd"] = "zvd";
|
|
14
|
-
InputShaperType["zvdd"] = "zvdd";
|
|
15
|
-
InputShaperType["zvddd"] = "zvddd";
|
|
16
|
-
})(InputShaperType || (exports.InputShaperType = InputShaperType = {}));
|
|
17
|
-
/***
|
|
18
|
-
* Compute input shaper amplitudes and durations like RepRapFirmware does
|
|
19
|
-
* @param type Input shaper type
|
|
20
|
-
* @param frequency Target frequency (in Hz)
|
|
21
|
-
* @param dampingFactor Optional damping factor (zeta)
|
|
22
|
-
* @returns Input shaper factors
|
|
23
|
-
*/
|
|
24
|
-
function getInputShaperFactors(type, frequency, dampingFactor = 0.1) {
|
|
25
|
-
const result = {
|
|
26
|
-
amplitudes: [],
|
|
27
|
-
durations: []
|
|
28
|
-
};
|
|
29
|
-
const sqrtOneMinusZetaSquared = Math.sqrt(1 - Math.pow(dampingFactor, 2));
|
|
30
|
-
const dampedFrequency = frequency * sqrtOneMinusZetaSquared;
|
|
31
|
-
const dampedPeriod = 1 / dampedFrequency;
|
|
32
|
-
const k = Math.exp(-dampingFactor * Math.PI / sqrtOneMinusZetaSquared);
|
|
33
|
-
switch (type) {
|
|
34
|
-
case InputShaperType.mzv:
|
|
35
|
-
{
|
|
36
|
-
// Klipper gives amplitude steps of [a3 = k^2 * (1 - 1/sqrt(2)), a2 = k * (sqrt(2) - 1), a1 = 1 - 1/sqrt(2)] all divided by (a1 + a2 + a3)
|
|
37
|
-
// Rearrange to: a3 = k^2 * (1 - sqrt(2)/2), a2 = k * (sqrt(2) - 1), a1 = (1 - sqrt(2)/2)
|
|
38
|
-
const kMzv = Math.exp(-dampingFactor * 0.75 * Math.PI / sqrtOneMinusZetaSquared);
|
|
39
|
-
const a1 = 1.0 - 0.5 * Math.sqrt(2);
|
|
40
|
-
const a2 = (Math.sqrt(2) - 1) * kMzv;
|
|
41
|
-
const a3 = a1 * kMzv * kMzv;
|
|
42
|
-
const sum = (a1 + a2 + a3);
|
|
43
|
-
result.amplitudes.push(a3 / sum);
|
|
44
|
-
result.amplitudes.push((a2 + a3) / sum);
|
|
45
|
-
}
|
|
46
|
-
result.durations.push(0.375 * dampedPeriod);
|
|
47
|
-
result.durations.push(0.375 * dampedPeriod);
|
|
48
|
-
break;
|
|
49
|
-
case InputShaperType.zvd:
|
|
50
|
-
{
|
|
51
|
-
const j = Math.pow(1 + k, 2);
|
|
52
|
-
result.amplitudes.push(1 / j);
|
|
53
|
-
result.amplitudes.push(1 / j + 2 * k / j);
|
|
54
|
-
}
|
|
55
|
-
result.durations.push(0.5 * dampedPeriod);
|
|
56
|
-
result.durations.push(0.5 * dampedPeriod);
|
|
57
|
-
break;
|
|
58
|
-
case InputShaperType.zvdd:
|
|
59
|
-
{
|
|
60
|
-
const j = Math.pow(1 + k, 3);
|
|
61
|
-
result.amplitudes.push(1 / j);
|
|
62
|
-
result.amplitudes.push(result.amplitudes[0] + 3 * k / j);
|
|
63
|
-
result.amplitudes.push(result.amplitudes[1] + 3 * Math.pow(k, 2) / j);
|
|
64
|
-
}
|
|
65
|
-
result.durations.push(0.5 * dampedPeriod);
|
|
66
|
-
result.durations.push(0.5 * dampedPeriod);
|
|
67
|
-
result.durations.push(0.5 * dampedPeriod);
|
|
68
|
-
break;
|
|
69
|
-
case InputShaperType.zvddd:
|
|
70
|
-
{
|
|
71
|
-
const j = Math.pow(1 + k, 4);
|
|
72
|
-
result.amplitudes.push(1 / j);
|
|
73
|
-
result.amplitudes.push(result.amplitudes[0] + 4 * k / j);
|
|
74
|
-
result.amplitudes.push(result.amplitudes[1] + 6 * Math.pow(k, 2) / j);
|
|
75
|
-
result.amplitudes.push(result.amplitudes[2] + 4 * Math.pow(k, 3) / j);
|
|
76
|
-
}
|
|
77
|
-
result.durations.push(0.5 * dampedPeriod);
|
|
78
|
-
result.durations.push(0.5 * dampedPeriod);
|
|
79
|
-
result.durations.push(0.5 * dampedPeriod);
|
|
80
|
-
result.durations.push(0.5 * dampedPeriod);
|
|
81
|
-
break;
|
|
82
|
-
case InputShaperType.ei2: // see http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.465.1337&rep=rep1&type=pdf. United States patent #4,916,635.
|
|
83
|
-
{
|
|
84
|
-
const zetaSquared = Math.pow(dampingFactor, 2), zetaCubed = zetaSquared * dampingFactor;
|
|
85
|
-
result.amplitudes.push((0.16054) + (0.76699) * dampingFactor + (2.26560) * zetaSquared + (-1.22750) * zetaCubed);
|
|
86
|
-
result.amplitudes.push((0.16054 + 0.33911) + (0.76699 + 0.45081) * dampingFactor + (2.26560 - 2.58080) * zetaSquared + (-1.22750 + 1.73650) * zetaCubed);
|
|
87
|
-
result.amplitudes.push((0.16054 + 0.33911 + 0.34089) + (0.76699 + 0.45081 - 0.61533) * dampingFactor + (2.26560 - 2.58080 - 0.68765) * zetaSquared + (-1.22750 + 1.73650 + 0.42261) * zetaCubed);
|
|
88
|
-
result.durations.push(((0.49890) + (0.16270) * dampingFactor + (-0.54262) * zetaSquared + (6.16180) * zetaCubed) * dampedPeriod);
|
|
89
|
-
result.durations.push(((0.99748 - 0.49890) + (0.18382 - 0.16270) * dampingFactor + (-1.58270 + 0.54262) * zetaSquared + (8.17120 - 6.16180) * zetaCubed) * dampedPeriod);
|
|
90
|
-
result.durations.push(((1.49920 - 0.99748) + (-0.09297 - 0.18382) * dampingFactor + (-0.28338 + 1.58270) * zetaSquared + (1.85710 - 8.17120) * zetaCubed) * dampedPeriod);
|
|
91
|
-
}
|
|
92
|
-
break;
|
|
93
|
-
case InputShaperType.ei3: // see http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.465.1337&rep=rep1&type=pdf. United States patent #4,916,635
|
|
94
|
-
{
|
|
95
|
-
const zetaSquared = Math.pow(dampingFactor, 2);
|
|
96
|
-
const zetaCubed = zetaSquared * dampingFactor;
|
|
97
|
-
result.amplitudes.push((0.11275) + 0.76632 * dampingFactor + (3.29160) * zetaSquared + (-1.44380) * zetaCubed);
|
|
98
|
-
result.amplitudes.push((0.11275 + 0.23698) + (0.76632 + 0.61164) * dampingFactor + (3.29160 - 2.57850) * zetaSquared + (-1.44380 + 4.85220) * zetaCubed);
|
|
99
|
-
result.amplitudes.push((0.11275 + 0.23698 + 0.30008) + (0.76632 + 0.61164 - 0.19062) * dampingFactor + (3.29160 - 2.57850 - 2.14560) * zetaSquared + (-1.44380 + 4.85220 + 0.13744) * zetaCubed);
|
|
100
|
-
result.amplitudes.push((0.11275 + 0.23698 + 0.30008 + 0.23775) + (0.76632 + 0.61164 - 0.19062 - 0.73297) * dampingFactor + (3.29160 - 2.57850 - 2.14560 + 0.46885) * zetaSquared + (-1.44380 + 4.85220 + 0.13744 - 2.08650) * zetaCubed);
|
|
101
|
-
result.durations.push(((0.49974) + (0.23834) * dampingFactor + (0.44559) * zetaSquared + (12.4720) * zetaCubed) * dampedPeriod);
|
|
102
|
-
result.durations.push(((0.99849 - 0.49974) + (0.29808 - 0.23834) * dampingFactor + (-2.36460 - 0.44559) * zetaSquared + (23.3990 - 12.4720) * zetaCubed) * dampedPeriod);
|
|
103
|
-
result.durations.push(((1.49870 - 0.99849) + (0.10306 - 0.29808) * dampingFactor + (-2.01390 + 2.36460) * zetaSquared + (17.0320 - 23.3990) * zetaCubed) * dampedPeriod);
|
|
104
|
-
result.durations.push(((1.99960 - 1.49870) + (-0.28231 - 0.10306) * dampingFactor + (0.61536 + 2.01390) * zetaSquared + (5.40450 - 17.0320) * zetaCubed) * dampedPeriod);
|
|
105
|
-
}
|
|
106
|
-
break;
|
|
107
|
-
default:
|
|
108
|
-
// Other shaper types are not supported
|
|
109
|
-
return result;
|
|
110
|
-
}
|
|
111
|
-
return result;
|
|
112
|
-
}
|
|
113
|
-
exports.getInputShaperFactors = getInputShaperFactors;
|
|
114
|
-
/**
|
|
115
|
-
* Compute the damping for the given frequencies with the given input shaper amplitudes and durations
|
|
116
|
-
* @param frequencies Frequencies to compute the damping for
|
|
117
|
-
* @param amplitudes Input shaper amplitudes (coefficients)
|
|
118
|
-
* @param durations Input shaper durations (in s)
|
|
119
|
-
* @returns Damping factor (0..1) per frequency
|
|
120
|
-
*/
|
|
121
|
-
function getInputShaperDamping(frequencies, amplitudes, durations) {
|
|
122
|
-
// Perform input check
|
|
123
|
-
if (amplitudes.length < 1) {
|
|
124
|
-
throw new Error("Insufficient number of amplitudes");
|
|
125
|
-
}
|
|
126
|
-
if (amplitudes.length !== durations.length) {
|
|
127
|
-
throw new Error("Number of amplitudes must match the number of durations");
|
|
128
|
-
}
|
|
129
|
-
// Compute step sizes
|
|
130
|
-
const stepSizes = [amplitudes[0]];
|
|
131
|
-
for (let i = 1; i < amplitudes.length; i++) {
|
|
132
|
-
stepSizes[i] = amplitudes[i] - amplitudes[i - 1];
|
|
133
|
-
}
|
|
134
|
-
stepSizes.push(1 - amplitudes[amplitudes.length - 1]);
|
|
135
|
-
// Compute the accumulated times in seconds
|
|
136
|
-
const accTimes = [0];
|
|
137
|
-
for (let duration of durations) {
|
|
138
|
-
accTimes.push(duration + accTimes[accTimes.length - 1]);
|
|
139
|
-
}
|
|
140
|
-
// Calculate the actual damping per frequency
|
|
141
|
-
const result = new Array(frequencies.length);
|
|
142
|
-
for (let i = 0; i < frequencies.length; i++) {
|
|
143
|
-
const frequency = frequencies[i];
|
|
144
|
-
let totalSine = 0, totalCosine = 0;
|
|
145
|
-
for (let k = 0; k < stepSizes.length; k++) {
|
|
146
|
-
totalSine += stepSizes[k] * Math.sin(2 * Math.PI * frequency * accTimes[k]);
|
|
147
|
-
totalCosine += stepSizes[k] * Math.cos(2 * Math.PI * frequency * accTimes[k]);
|
|
148
|
-
}
|
|
149
|
-
result[i] = Math.sqrt(totalSine * totalSine + totalCosine * totalCosine);
|
|
150
|
-
}
|
|
151
|
-
return result;
|
|
152
|
-
}
|
|
153
|
-
exports.getInputShaperDamping = getInputShaperDamping;
|