dechatter 0.1.0 → 0.2.0

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 CHANGED
@@ -1,241 +1,281 @@
1
- # dechatter
2
-
3
- dechatter finds the fastest chatter-free cut for one tool on one milling machine. It writes a
4
- G-code program of test cuts, listens while the machine runs it, and decides from the sound
5
- which cuts chattered. From that it either plans a finer round of cuts or reports the best
6
- stable speeds and widths.
7
-
8
- It runs as a widget inside [cncjs](https://cnc.js.org), entirely in the browser and recording
9
- with that computer's microphone, or from the command line with a recording made on a phone.
10
- The G-code is
11
- plain Grbl dialect (`G0`, `G1`, `G4`, `M3`, `M5`), written for FluidNC and usable on Grbl and
12
- grblHAL.
13
-
14
- ## What it measures
15
-
16
- Chatter depends on the machine, the holder, the cutter and how far the cutter sticks out.
17
- Machine weight, spindle power and material cannot predict it. They only bound the search:
18
- the speed range, the power cap and the starting chip load. The cuts are the measurement, and
19
- a result applies to that one tool assembly. Change the stickout and you start a new session.
20
-
21
- Each round holds chip load and axial depth constant and varies spindle speed and radial width,
22
- one pass per combination, cutting along the front face of a block held in the vise. Feed
23
- follows speed so the chip load stays put.
24
-
25
- ### Comparing depths
26
-
27
- A deep, narrow cut and a shallower, wider one can remove the same amount, and only cutting
28
- tells which your machine prefers. List shallower depths in the wizard's Cut step (or
29
- `other_depths_mm` in `setup.toml`) and the session continues with them once the deepest depth
30
- is settled, deepest first. A width that was stable in a deeper cut is taken as stable in a
31
- shallower one, so each further depth starts from those widths and only looks for how much
32
- wider it can go. A depth is left once no cut within the power cap that would beat the best
33
- one found keeps a fair chance of being stable. The results list the best cuts of all depths
34
- together.
35
-
36
- The depths run deepest first because a shallower cut leaves the face flat only above its own
37
- depth. Planning a deeper cut on such a block is refused: mount fresh stock for it.
38
-
39
- ## Use in cncjs
40
-
41
- ```sh
42
- npm install dechatter
43
- cncjs --mount "/dechatter:$(npm root)/dechatter/web" # PowerShell or a POSIX shell
44
- ```
45
-
46
- The npm package is the widget as a static folder, about 30 MB. To build that folder from
47
- source instead:
48
-
49
- ```sh
50
- uv tool install git+https://github.com/pedropaulovc/dechatter
51
-
52
- dechatter widget ~/dechatter-widget
53
- cncjs --mount /dechatter:$HOME/dechatter-widget
54
- ```
55
-
56
- In cncjs, open Manage Widgets, enable the Custom widget, and set its URL to `/dechatter/` in
57
- the widget's settings. Open cncjs at `http://localhost:8000` or over HTTPS: browsers only give
58
- a page the microphone on those. Then, in the widget:
59
-
60
- 1. Create a session. A short wizard asks for the machine, the tool, the cut and the stock. It
61
- shows lengths in inches when the machine is in G20 and in millimetres when it is in G21,
62
- or with no machine connected. Its last step holds the planner's settings, which rarely
63
- need changing. Saving from the wizard rewrites the session's setup file without comments.
64
- Programs are always in millimetres (G21); one run on an inch machine switches it back to
65
- G20 before it ends. A job you stop part-way leaves the machine in G21: the wizard keeps
66
- showing inches and tells you to send G20, or you can choose to carry on in mm.
67
- 2. Plan a round. Round 1 is a coarse grid of speeds and widths.
68
- 3. Set the work zero at the left end of the stock, on its front face, at the top.
69
- 4. Load the program into cncjs and press play in cncjs. The widget never starts the machine.
70
- 5. Recording starts when the job starts and stops when it ends. The widget then shows each
71
- pass as stable or chatter, the stability map and the best cuts so far.
72
- 6. If your ears disagree with a verdict, change it in the table. Plan the next round and
73
- repeat until the widget reports convergence.
74
-
75
- Everything runs in the browser tab. The same Python that the command line uses runs there
76
- under [Pyodide](https://pyodide.org), which `dechatter widget` downloads once and copies into
77
- the folder, so the shop PC needs no Python and no internet. The microphone is the browser's,
78
- on whichever computer shows cncjs, opened with echo cancellation, noise suppression and
79
- automatic gain switched off. The widget shows its level before any cutting and warns if the
80
- browser kept any of that processing on.
81
-
82
- Sessions are stored in that browser (IndexedDB), per cncjs address. Export saves one as a zip
83
- holding `setup.toml` and each round's plan, program, `recording.wav`, results and the job
84
- timeline cncjs reported. Import loads it in another browser, and unzipped it is a session
85
- folder the command line reads. Keep the tab open while a round runs: the recording lives in
86
- the page until the job ends.
87
-
88
- ### Manual spindle
89
-
90
- If the spindle is started and set by hand, choose "me, by hand" on the wizard's first step
91
- (`spindle = "manual"` under `[machine]` in a setup file). The program then never commands the
92
- spindle. It stops with `M0` before each speed, with
93
- the cutter clear of the work, and the widget (and cncjs) shows the speed to set. Set it and
94
- press resume in cncjs. Cuts are grouped by speed, lightest first, so a round has one stop per
95
- speed: five in round 1. The first stop is where you start the spindle, and you stop it yourself
96
- after the program ends.
97
-
98
- Set the speed within 5% of what is asked; the detector finds the actual speed inside that
99
- range. The stability map is built on the requested speeds, so a dial that reads off by a
100
- constant amount shifts the whole map by that amount.
101
-
102
- ## Use from the command line
103
-
104
- Without cncjs, record on a phone and run the same session by hand:
105
-
106
- ```sh
107
- dechatter plan al-10mm # writes al-10mm/round-01/program.nc
108
- ```
109
-
110
- Set the work zero at the left end of the stock, on its front face, at the top. Start one
111
- continuous recording, run the program, stop recording after `M30`. Then:
112
-
113
- ```sh
114
- dechatter analyze al-10mm recording.wav # classifies each pass
115
- dechatter plan al-10mm # next round, or "converged"
116
- dechatter report al-10mm # stability map and best cuts so far
117
- ```
118
-
119
- Repeat until `plan` reports convergence. WAV, FLAC, OGG and MP3 load directly. Phone formats
120
- such as M4A need `ffmpeg` on the path.
121
-
122
- Round 1 is a coarse grid of speeds and widths. Later rounds are chosen from what was measured.
123
- Every program orders its passes from the narrowest cut to the widest, starts with a light
124
- truing pass, and tells you where the front face will end up.
125
-
126
- ## Safety
127
-
128
- The program looks for chatter on purpose, so later passes are heavier than earlier ones and
129
- some of them will chatter. Feed-hold and abort when a cut gets violent. Analyze the recording
130
- anyway: the passes that ran still count, the aborted one is marked as such, and the next
131
- round starts by clearing the step it left on the face.
132
-
133
- Every planned cut stays under a power cap (60% of rated spindle power by default) and inside
134
- the material's surface-speed limit. The built-in cutting data (`dechatter materials`) is a
135
- conservative starting point. Override `chip_load_mm` and the speed range when you know better.
136
-
137
- ## How a pass is classified
138
-
139
- Forced vibration sits on harmonics of the spindle rotation. Chatter is a strong tone anywhere
140
- else. For each pass dechatter estimates the true spindle speed from the tooth-passing
141
- harmonics, removes every spindle harmonic from the spectrum, and takes the strongest peak
142
- left over. The pass is unstable when that peak is at least 27 dB above the median of the
143
- remaining spectrum and at least 10 dB above the same frequency in the dwell just before the
144
- pass, when the spindle was turning in air. The second test rejects tones the machine makes
145
- without cutting, such as drive whine.
146
-
147
- Passes are found in the recording by level, then matched in order to the planned passes by
148
- how long each cut should last. A quiet pass that goes undetected is reported as missing and
149
- does not shift the others. If matching fails, mark the cuts yourself and pass
150
- `--segments labels.txt` (start and end seconds per pass; an Audacity label export works).
151
-
152
- `results.json` in each round holds the verdicts and the numbers behind them. If your ears
153
- disagree with a verdict, change it in the widget or edit it there before planning the next
154
- round.
155
-
156
- ### How well it works
157
-
158
- `validation/purdue.py` scores the detector against the
159
- [Purdue CNC cutting sound dataset](https://github.com/purduelamm/mt_cutting_dataset): 583 cuts
160
- in steel and aluminium on a Hurco VM20i, each labelled by two operators.
161
-
162
- | Operators say | Cuts | Detector agrees |
163
- |---|---|---|
164
- | chatter (both) | 169 | 142 (84%) |
165
- | no chatter (both) | 254 | 233 (92%) |
166
- | slight, or they disagree | 160 | not scored |
167
-
168
- The 27 dB threshold was chosen on this same data, so these numbers are a fit and the detector
169
- has not been scored on a second dataset. Most of those cuts last about a second; dechatter's
170
- own passes are longer, which gives a finer spectrum. Removing the spindle harmonics matters:
171
- without that step the best achievable balanced accuracy on this data falls from 88% to 75%.
172
-
173
- It has not yet been run on a real machine end to end. The planner and the audio pipeline are
174
- tested against a simulated machine with stability lobes (`tests/synth.py`), where a session
175
- converges in about three rounds and 27 cuts to within 10% of the true best removal rate. The
176
- widget was driven through that same session in Chrome against cncjs 1.11.5 and a simulated
177
- Grbl (`e2e/`), with the simulated machine's sound played into the widget in place of the
178
- microphone. Capture from a real webcam microphone was checked separately, without cutting.
179
-
180
- Known limits:
181
-
182
- - A chatter tone that lands within a few hertz of a spindle harmonic is hidden. Its sidebands
183
- usually still trip the detector, but the reported frequency is then off by the tooth-passing
184
- frequency. This is likeliest at low speed, where the harmonics are close together.
185
- - Flood coolant and a noisy shop raise the noise floor. Record close to the spindle.
186
- - Variable-pitch cutters break the assumption that tooth passing is one frequency.
187
-
188
- ## How the next round is chosen
189
-
190
- The planner follows Karandikar et al., "Evaluation of automated stability testing in machining
191
- through closed-loop control and Bayesian machine learning"
192
- ([MSSP 181, 2022](https://doi.org/10.1016/j.ymssp.2022.109531)). It keeps a probability of
193
- stability over the speed and width grid, starting from "wider is less likely to be stable".
194
- A stable cut raises the probability of everything narrower near that speed, and an unstable
195
- cut lowers everything wider. The next cuts are the ones with the highest expected improvement
196
- in removal rate, and the session has converged when no cut promises 5% more.
197
-
198
- Three things differ from the paper, which tests one cut at a time under closed-loop control:
199
-
200
- - A round is a batch with no feedback between cuts. Later cuts in a batch assume the earlier
201
- ones pass, so widths can ramp at one speed, but each must also be at least 50% likely to be
202
- stable on measured data alone. A cut that builds on no earlier cut in the batch must be at
203
- least 80% likely.
204
- - The paper does not give its likelihood. Here each speed has a distribution over its
205
- stability limit, each verdict is assumed wrong 5% of the time, and evidence fades with
206
- distance in speed (1.5% of the speed, one standard deviation).
207
- - Chatter frequency is used. A chatter tone at `f` Hz predicts stable pockets where tooth
208
- passing divides it, at `60 f / (flutes k)` rpm. Those speeds get partial credit for the
209
- width that was stable where the chatter was heard, so the planner tries them.
210
-
211
- The stock runs out before the search does on small blocks. `plan` then asks for fresh stock;
212
- mount it, reset the face to `Y0` and run `dechatter plan --new-stock`.
213
-
214
- ## Development
215
-
216
- ```sh
217
- uv sync
218
- uv run pytest
219
- uv run ruff check .
220
- uv run validation/purdue.py ~/purdue-cache # downloads about 370 MB once
221
- ```
222
-
223
- `e2e/` runs real cncjs against a simulated Grbl inside WSL, for driving the widget without a
224
- machine. See `e2e/README.md`.
225
-
226
- To release, set the same version in `pyproject.toml` and `package.json`, merge to `main`, and
227
- push a tag `vX.Y.Z` on that commit. The `release` workflow tests on Linux and Windows, builds
228
- the widget once and publishes that build to npm. npm trusts the workflow itself, so no token
229
- is stored; version 0.1.0 was published by hand, because that trust can only be registered
230
- for a package that exists.
231
-
232
- ## Related work
233
-
234
- [Harmonizer](https://taptest.co/harmonizer) and
235
- [ChatterPro Mobile](https://www.malinc.com/products/chatterpro-mobile/) are commercial phone
236
- apps that recommend a speed from the sound of a cut. The test method, constant chip load with
237
- stepped speed and width, is described in CNCCookbook's
238
- [chatter article](https://www.cnccookbook.com/chatter-in-machining-milling-lathe-vibration/).
239
-
240
- MIT licensed. The npm package also carries Pyodide, CPython, NumPy and SciPy under their own
241
- licences; see `THIRD_PARTY_NOTICES.md`.
1
+ # dechatter
2
+
3
+ dechatter finds the fastest chatter-free cut for one tool on one milling machine. It writes a
4
+ G-code program of test cuts, listens while the machine runs it, and decides from the sound
5
+ which cuts chattered. From that it either plans a finer round of cuts or reports the best
6
+ stable speeds and widths.
7
+
8
+ It runs as a widget inside [cncjs](https://cnc.js.org), entirely in the browser and recording
9
+ with that computer's microphone, or from the command line with a recording made on a phone.
10
+ The G-code is
11
+ plain Grbl dialect (`G0`, `G1`, `G4`, `M3`, `M5`), written for FluidNC and usable on Grbl and
12
+ grblHAL.
13
+
14
+ ## What it measures
15
+
16
+ Chatter depends on the machine, the holder, the cutter and how far the cutter sticks out.
17
+ Machine weight, spindle power and material cannot predict it. They only bound the search:
18
+ the speed range, the power cap and the starting chip load. The cuts are the measurement, and
19
+ a result applies to that one tool assembly. Change the stickout and you start a new session.
20
+
21
+ Each round holds chip load and axial depth constant and varies spindle speed and radial width,
22
+ one pass per combination, cutting along the front face of a block held in the vise. Feed
23
+ follows speed so the chip load stays put.
24
+
25
+ ### Comparing depths
26
+
27
+ A deep, narrow cut and a shallower, wider one can remove the same amount, and only cutting
28
+ tells which your machine prefers. List shallower depths in the wizard's Cut step (or
29
+ `other_depths_mm` in `setup.toml`) and the session continues with them once the deepest depth
30
+ is settled, deepest first. A width that was stable in a deeper cut is taken as stable in a
31
+ shallower one, so each further depth starts from those widths and only looks for how much
32
+ wider it can go. A depth is left once no cut within the power cap that would beat the best
33
+ one found keeps a fair chance of being stable. The results list the best cuts of all depths
34
+ together.
35
+
36
+ The depths run deepest first because a shallower cut leaves the face flat only above its own
37
+ depth. Planning a deeper cut on such a block is refused: mount fresh stock for it.
38
+
39
+ ## Use in cncjs
40
+
41
+ ```sh
42
+ npm install dechatter
43
+ cncjs --mount "/dechatter:$(npm root)/dechatter/web" # PowerShell or a POSIX shell
44
+ ```
45
+
46
+ The npm package is the widget as a static folder, about 30 MB. To build that folder from
47
+ source instead:
48
+
49
+ ```sh
50
+ uv tool install git+https://github.com/pedropaulovc/dechatter
51
+
52
+ dechatter widget ~/dechatter-widget
53
+ cncjs --mount /dechatter:$HOME/dechatter-widget
54
+ ```
55
+
56
+ In cncjs, open Manage Widgets, enable the Custom widget, and set its URL to `/dechatter/` in
57
+ the widget's settings. Open cncjs at `http://localhost:8000` or over HTTPS: browsers only give
58
+ a page the microphone on those. Then, in the widget:
59
+
60
+ 1. Create a session. A short wizard asks for the machine, the tool, the cut and the stock. It
61
+ shows lengths in inches when the machine is in G20 and in millimetres when it is in G21,
62
+ or with no machine connected. Its last step holds the planner's settings, which rarely
63
+ need changing. Settings with a sensible default or a computed value (the machine's name,
64
+ the holder, the cut's limits and chip load, the program's dwell, clearance, plunge feed,
65
+ truing width and coolant, and the planner) sit in a collapsed Advanced section of their
66
+ step, showing what an empty entry becomes. A section holding a changed setting opens by
67
+ itself. Every field has an (i) button with a longer explanation: what it changes, its
68
+ default, and whether it may change after a cut. Saving from the wizard rewrites the
69
+ session's setup file without comments.
70
+ Programs are written in the machine's units too (G20 or G21, as cncjs reports it), so a
71
+ job never changes them, even one stopped part-way. Their comments, like the plan and the
72
+ results, stay in millimetres.
73
+ Nothing is planned until the wizard has been saved: a new session holds only an example
74
+ setup. Each round keeps a copy of the setup it was planned from. Once a round has been
75
+ cut, the setup can no longer change in anything that shapes the cut or its sound (the
76
+ machine's weight and spindle control, the tool, the work material, depth, direction and
77
+ chip load, the stock length, the dwell and the coolant), since the stability map belongs
78
+ to the setup it was measured with: start a new session instead. What only bounds the
79
+ search may still change (the machine's speed range and power, the cut's speed and width
80
+ limits and shallower depths), as may the machine's name, the safe height, clearance,
81
+ plunge feed, truing width, stock width and the planner's settings. Cuts outside narrowed
82
+ bounds stay in their round but are not recommended, nor are cuts over a lowered power
83
+ cap. On the map, a stable cut wider than a narrowed width limit counts as stable at the
84
+ widest width searched; chatter that wide, and cuts at speeds outside the limits, are left
85
+ out. A round
86
+ planned but not yet run is discarded when the setup changes its program, so the next
87
+ plan uses the new setup. `dechatter plan` refuses the same changes made by hand.
88
+ 2. Plan a round. Round 1 is a coarse grid of speeds and widths.
89
+ 3. Set the work zero at the left end of the stock, on its front face, at the top.
90
+ 4. Load the program into cncjs and press play in cncjs. The widget never starts the machine.
91
+ 5. Recording starts when the job starts and stops when it ends. The widget then shows each
92
+ pass as stable or chatter, the stability map and the best cuts so far.
93
+ 6. If your ears disagree with a verdict, change it in the table. Plan the next round and
94
+ repeat until the widget reports convergence.
95
+ 7. Optionally, plan the chip-load sweep it then offers: the best cut once more at five
96
+ chip loads, from 0.6 to 1.7 times the session's (both Advanced planner settings), lightest
97
+ first and inside the power cap. The result is the highest chip load that stayed stable,
98
+ with its feed. Its cuts do not change the map, which stays at the session's chip load.
99
+ 8. Download the report: one HTML page to print (Letter or A4, black and white) and keep with
100
+ the tool. It holds the recommended cuts per depth with feed, removal rate and spindle
101
+ power, the stability map, every round's passes (marking verdicts set by hand) and the
102
+ setup. Lengths follow the machine's G20/G21, with mm beside. It is offered on convergence
103
+ and any time beside the best cuts.
104
+
105
+ Everything runs in the browser tab. The same Python that the command line uses runs there
106
+ under [Pyodide](https://pyodide.org), which `dechatter widget` downloads once and copies into
107
+ the folder, so the shop PC needs no Python and no internet. The microphone is the browser's,
108
+ on whichever computer shows cncjs, opened with echo cancellation, noise suppression and
109
+ automatic gain switched off. The widget shows its level before any cutting and warns if the
110
+ browser kept any of that processing on.
111
+
112
+ Sessions are stored in that browser (IndexedDB), per cncjs address. Export saves one as a zip
113
+ holding `setup.toml` and each round's plan, program, `recording.wav`, results and the job
114
+ timeline cncjs reported, plus `report.html`. Import loads it in another browser, and unzipped it is a session
115
+ folder the command line reads. Keep the tab open while a round runs: the recording lives in
116
+ the page until the job ends.
117
+
118
+ ### Manual spindle
119
+
120
+ If the spindle is started and set by hand, choose "me, by hand" on the wizard's first step
121
+ (`spindle = "manual"` under `[machine]` in a setup file). The program then never commands the
122
+ spindle. It stops with `M0` before each speed, with
123
+ the cutter clear of the work, and the widget (and cncjs) shows the speed to set. Set it and
124
+ press resume in cncjs. Cuts are grouped by speed, lightest first, so a round has one stop per
125
+ speed: five in round 1. The first stop is where you start the spindle, and you stop it yourself
126
+ after the program ends.
127
+
128
+ Set the speed within 5% of what is asked; the detector finds the actual speed inside that
129
+ range. The stability map is built on the requested speeds, so a dial that reads off by a
130
+ constant amount shifts the whole map by that amount.
131
+
132
+ ## Use from the command line
133
+
134
+ Without cncjs, record on a phone and run the same session by hand:
135
+
136
+ ```sh
137
+ dechatter plan al-10mm # writes al-10mm/round-01/program.nc
138
+ ```
139
+
140
+ Set the work zero at the left end of the stock, on its front face, at the top. Start one
141
+ continuous recording, run the program, stop recording after `M30`. Then:
142
+
143
+ ```sh
144
+ dechatter analyze al-10mm recording.wav # classifies each pass
145
+ dechatter plan al-10mm # next round, or "converged"
146
+ dechatter plan al-10mm --sweep # once converged: chip-load sweep of the best cut
147
+ dechatter report al-10mm # stability map and best cuts so far
148
+ dechatter report al-10mm --html al-10mm.html --units in # printable report
149
+ ```
150
+
151
+ Repeat until `plan` reports convergence. WAV, FLAC, OGG and MP3 load directly. Phone formats
152
+ such as M4A need `ffmpeg` on the path.
153
+
154
+ Round 1 is a coarse grid of speeds and widths. Later rounds are chosen from what was measured.
155
+ Every program orders its passes from the narrowest cut to the widest, starts with a light
156
+ truing pass, and tells you where the front face will end up.
157
+
158
+ ## Safety
159
+
160
+ The program looks for chatter on purpose, so later passes are heavier than earlier ones and
161
+ some of them will chatter. Feed-hold and abort when a cut gets violent. Analyze the recording
162
+ anyway: the passes that ran still count, the aborted one is marked as such, and the next
163
+ round starts by clearing the step it left on the face.
164
+
165
+ Every planned cut stays under a power cap (60% of rated spindle power by default) and inside
166
+ the material's surface-speed limit. The built-in cutting data (`dechatter materials`) is a
167
+ conservative starting point. Override `chip_load_mm` and the speed range when you know better.
168
+
169
+ ## How a pass is classified
170
+
171
+ Forced vibration sits on harmonics of the spindle rotation. Chatter is a strong tone anywhere
172
+ else. For each pass dechatter estimates the true spindle speed from the tooth-passing
173
+ harmonics, removes every spindle harmonic from the spectrum, and takes the strongest peak
174
+ left over. The pass is unstable when that peak is at least 27 dB above the median of the
175
+ remaining spectrum and at least 10 dB above the same frequency in the dwell just before the
176
+ pass, when the spindle was turning in air. The second test rejects tones the machine makes
177
+ without cutting, such as drive whine.
178
+
179
+ Passes are found in the recording by level, then matched in order to the planned passes by
180
+ how long each cut should last. A quiet pass that goes undetected is reported as missing and
181
+ does not shift the others. If matching fails, mark the cuts yourself and pass
182
+ `--segments labels.txt` (start and end seconds per pass; an Audacity label export works).
183
+
184
+ `results.json` in each round holds the verdicts and the numbers behind them. If your ears
185
+ disagree with a verdict, change it in the widget or edit it there before planning the next
186
+ round.
187
+
188
+ ### How well it works
189
+
190
+ `validation/purdue.py` scores the detector against the
191
+ [Purdue CNC cutting sound dataset](https://github.com/purduelamm/mt_cutting_dataset): 583 cuts
192
+ in steel and aluminium on a Hurco VM20i, each labelled by two operators.
193
+
194
+ | Operators say | Cuts | Detector agrees |
195
+ |---|---|---|
196
+ | chatter (both) | 169 | 142 (84%) |
197
+ | no chatter (both) | 254 | 233 (92%) |
198
+ | slight, or they disagree | 160 | not scored |
199
+
200
+ The 27 dB threshold was chosen on this same data, so these numbers are a fit and the detector
201
+ has not been scored on a second dataset. Most of those cuts last about a second; dechatter's
202
+ own passes are longer, which gives a finer spectrum. Removing the spindle harmonics matters:
203
+ without that step the best achievable balanced accuracy on this data falls from 88% to 75%.
204
+
205
+ It has not yet been run on a real machine end to end. The planner and the audio pipeline are
206
+ tested against a simulated machine with stability lobes (`tests/synth.py`), where a session
207
+ converges in about three rounds and 27 cuts to within 10% of the true best removal rate. The
208
+ widget was driven through that same session in Chrome against cncjs 1.11.5 and a simulated
209
+ Grbl (`e2e/`), with the simulated machine's sound played into the widget in place of the
210
+ microphone. Capture from a real webcam microphone was checked separately, without cutting.
211
+
212
+ Known limits:
213
+
214
+ - A chatter tone that lands within a few hertz of a spindle harmonic is hidden. Its sidebands
215
+ usually still trip the detector, but the reported frequency is then off by the tooth-passing
216
+ frequency. This is likeliest at low speed, where the harmonics are close together.
217
+ - Flood coolant and a noisy shop raise the noise floor. Record close to the spindle.
218
+ - Variable-pitch cutters break the assumption that tooth passing is one frequency.
219
+
220
+ ## How the next round is chosen
221
+
222
+ The planner follows Karandikar et al., "Evaluation of automated stability testing in machining
223
+ through closed-loop control and Bayesian machine learning"
224
+ ([MSSP 181, 2022](https://doi.org/10.1016/j.ymssp.2022.109531)). It keeps a probability of
225
+ stability over the speed and width grid, starting from "wider is less likely to be stable".
226
+ A stable cut raises the probability of everything narrower near that speed, and an unstable
227
+ cut lowers everything wider. The next cuts are the ones with the highest expected improvement
228
+ in removal rate, and the session has converged when no cut promises 5% more.
229
+
230
+ Three things differ from the paper, which tests one cut at a time under closed-loop control:
231
+
232
+ - A round is a batch with no feedback between cuts. Later cuts in a batch assume the earlier
233
+ ones pass, so widths can ramp at one speed, but each must also be at least 50% likely to be
234
+ stable on measured data alone. A cut that builds on no earlier cut in the batch must be at
235
+ least 80% likely.
236
+ - The paper does not give its likelihood. Here each speed has a distribution over its
237
+ stability limit, each verdict is assumed wrong 5% of the time, and evidence fades with
238
+ distance in speed (1.5% of the speed, one standard deviation).
239
+ - Chatter frequency is used. A chatter tone at `f` Hz predicts stable pockets where tooth
240
+ passing divides it, at `60 f / (flutes k)` rpm. Those speeds get partial credit for the
241
+ width that was stable where the chatter was heard, so the planner tries them.
242
+
243
+ The stock runs out before the search does on small blocks. `plan` then asks for fresh stock;
244
+ mount it, reset the face to `Y0` and run `dechatter plan --new-stock`.
245
+
246
+ ## Development
247
+
248
+ ```sh
249
+ uv sync
250
+ uv run pytest
251
+ uv run ruff check .
252
+ uv run validation/purdue.py ~/purdue-cache # downloads about 370 MB once
253
+ ```
254
+
255
+ `e2e/` runs real cncjs against a simulated Grbl inside WSL, for driving the widget without a
256
+ machine. See `e2e/README.md`.
257
+
258
+ Every change users can notice adds a line under `## [Unreleased]` in
259
+ [`CHANGELOG.md`](CHANGELOG.md), in the same pull request: what they will notice and, for a
260
+ breaking change, what to do about it.
261
+
262
+ To release, set the same version in `src/dechatter/__init__.py` (`__version__`, which
263
+ `pyproject.toml` reads) and `package.json`, rename `## [Unreleased]` in `CHANGELOG.md` to
264
+ `## [X.Y.Z] - YYYY-MM-DD` above a fresh empty Unreleased section (and update the links at
265
+ its end), merge to `main`, and push a tag `vX.Y.Z` on that commit. The `release` workflow
266
+ refuses a tag without that dated section, tests on Linux and Windows, builds the widget
267
+ once, publishes that build to npm, and creates the GitHub release with the section as its
268
+ notes. npm trusts the workflow itself, so no token
269
+ is stored; version 0.1.0 was published by hand, because that trust can only be registered
270
+ for a package that exists.
271
+
272
+ ## Related work
273
+
274
+ [Harmonizer](https://taptest.co/harmonizer) and
275
+ [ChatterPro Mobile](https://www.malinc.com/products/chatterpro-mobile/) are commercial phone
276
+ apps that recommend a speed from the sound of a cut. The test method, constant chip load with
277
+ stepped speed and width, is described in CNCCookbook's
278
+ [chatter article](https://www.cnccookbook.com/chatter-in-machining-milling-lathe-vibration/).
279
+
280
+ MIT licensed. The npm package also carries Pyodide, CPython, NumPy and SciPy under their own
281
+ licences; see `THIRD_PARTY_NOTICES.md`.
@@ -1,24 +1,24 @@
1
- # Third-party software in the npm package
2
-
3
- dechatter's own code is MIT licensed (see `LICENSE`). The npm package also redistributes the
4
- software below in `web/pyodide/`, so that the widget runs in a browser tab without a server.
5
- The exact versions are the ones pinned in `src/dechatter/export.py` and listed in
6
- `web/pyodide/pyodide-lock.json`.
7
-
8
- | Files | Software | Licence | Source |
9
- | --- | --- | --- | --- |
10
- | `pyodide.js`, `pyodide.asm.js`, `pyodide.asm.wasm`, `pyodide-lock.json` | Pyodide | MPL-2.0 | https://github.com/pyodide/pyodide |
11
- | `python_stdlib.zip`, and the interpreter inside `pyodide.asm.wasm` | CPython | PSF-2.0 | https://github.com/python/cpython |
12
- | `numpy-*.whl` | NumPy | BSD-3-Clause AND 0BSD AND MIT AND Zlib AND CC0-1.0, as the wheel declares | https://github.com/numpy/numpy |
13
- | `scipy-*.whl` | SciPy | BSD-3-Clause, with bundled components under their own licences | https://github.com/scipy/scipy |
14
-
15
- Two of the files are renamed copies: `pyodide.js` and `pyodide.asm.js` are Pyodide's
16
- `pyodide.mjs` and `pyodide.asm.mjs`, and the one reference between them is renamed to match,
17
- because cncjs serves `.mjs` files with a type browsers refuse to run. Nothing else is changed.
18
-
19
- The Pyodide runtime also contains the libraries it is built with; their licence texts are in
20
- the Pyodide repository. Each wheel is a zip archive and carries the licence texts of its
21
- project and of what it bundles: in `*.dist-info/` and beside the bundled components.
22
-
23
- The source code for the Pyodide files, which the MPL-2.0 asks to be made available, is at the
24
- repository above under the tag of the pinned version.
1
+ # Third-party software in the npm package
2
+
3
+ dechatter's own code is MIT licensed (see `LICENSE`). The npm package also redistributes the
4
+ software below in `web/pyodide/`, so that the widget runs in a browser tab without a server.
5
+ The exact versions are the ones pinned in `src/dechatter/export.py` and listed in
6
+ `web/pyodide/pyodide-lock.json`.
7
+
8
+ | Files | Software | Licence | Source |
9
+ | --- | --- | --- | --- |
10
+ | `pyodide.js`, `pyodide.asm.js`, `pyodide.asm.wasm`, `pyodide-lock.json` | Pyodide | MPL-2.0 | https://github.com/pyodide/pyodide |
11
+ | `python_stdlib.zip`, and the interpreter inside `pyodide.asm.wasm` | CPython | PSF-2.0 | https://github.com/python/cpython |
12
+ | `numpy-*.whl` | NumPy | BSD-3-Clause AND 0BSD AND MIT AND Zlib AND CC0-1.0, as the wheel declares | https://github.com/numpy/numpy |
13
+ | `scipy-*.whl` | SciPy | BSD-3-Clause, with bundled components under their own licences | https://github.com/scipy/scipy |
14
+
15
+ Two of the files are renamed copies: `pyodide.js` and `pyodide.asm.js` are Pyodide's
16
+ `pyodide.mjs` and `pyodide.asm.mjs`, and the one reference between them is renamed to match,
17
+ because cncjs serves `.mjs` files with a type browsers refuse to run. Nothing else is changed.
18
+
19
+ The Pyodide runtime also contains the libraries it is built with; their licence texts are in
20
+ the Pyodide repository. Each wheel is a zip archive and carries the licence texts of its
21
+ project and of what it bundles: in `*.dist-info/` and beside the bundled components.
22
+
23
+ The source code for the Pyodide files, which the MPL-2.0 asks to be made available, is at the
24
+ repository above under the tag of the pinned version.