cncjs-handwheel 0.7.2 → 1.0.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 +113 -9
- package/bin/cncjs-handwheel +10 -1139
- package/cncjs-handwheel.config.example.json +1 -0
- package/lib/bridge.js +125 -0
- package/lib/commands.js +89 -0
- package/lib/config.js +160 -0
- package/lib/guard.js +89 -0
- package/lib/health.js +101 -0
- package/lib/http.js +77 -0
- package/lib/job-guard.js +116 -0
- package/lib/jog.js +202 -0
- package/lib/pendant-input.js +177 -0
- package/lib/pendant-link.js +234 -0
- package/lib/protocol.js +119 -0
- package/lib/status-sender.js +133 -0
- package/lib/status.js +97 -0
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -1,13 +1,45 @@
|
|
|
1
1
|
# cncjs-handwheel
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
A hardware handwheel (pendant) is the natural way to set up a machine: jog an axis by hand, touch off, move to a
|
|
4
|
+
corner, start and stop the spindle, without reaching for the mouse or the touch screen. CNCjs has no built-in way to
|
|
5
|
+
talk to such a device. Many handwheels are built to speak plain GCode over a serial link to a sender like Candle or
|
|
6
|
+
Grbl directly, and cannot be used with CNCjs as they are. This project closes that gap, so a handwheel built for a
|
|
7
|
+
GCode stream can drive a machine that is run from CNCjs, and show what the machine is doing on its own display.
|
|
8
|
+
|
|
9
|
+
It has two parts:
|
|
10
|
+
|
|
11
|
+
- **The bridge**, a small Node app that runs on the same machine as CNCjs (for example a Raspberry Pi) and
|
|
12
|
+
talks to the handwheel over a serial port (USB or Bluetooth) and to CNCjs over its socket interface.
|
|
13
|
+
It is the only part that is needed.
|
|
14
|
+
- pendant -> CNCjs: gcode lines, realtime commands, console log lines. It merges jogs so the machine does not
|
|
15
|
+
build up a queue of moves, keeps the wheel's gcode out of a running job (see "Jobs and the pendant") and
|
|
16
|
+
notices when the wheel is unplugged or switched off.
|
|
17
|
+
- CNCjs -> pendant: status lines (state, MPos, WPos, feed/spindle), about 10 per second
|
|
18
|
+
- health and the pendant log as JSON on `http://127.0.0.1:8001`
|
|
19
|
+
- **The widget**, an optional CNCjs [custom widget](#cncjs-widget) that shows the state of the handwheel, the bridge and
|
|
20
|
+
the link to CNCjs in the CNCjs UI, with a live tail of the handwheel's log.
|
|
8
21
|
|
|
9
22
|
Requires Node 20 or newer and a CNCjs that uses socket.io 2.x (current CNCjs releases do).
|
|
10
23
|
|
|
24
|
+
## Supported handwheels
|
|
25
|
+
|
|
26
|
+
<p align="center" style="float: left; margin-right: 30px; margin-top: 10px"><img src="docs/images/handwheel.jpg" alt="The handwheel next to the machine" width="400"></p>
|
|
27
|
+
|
|
28
|
+
The bridge works with any handwheel that talks to its host as a line-based serial device (USB serial or Bluetooth
|
|
29
|
+
Classic SPP) and emits a **stream of GCode**: jog lines such as `G21G91X+10F2000`, other gcode, and the single-character
|
|
30
|
+
realtime commands (`!`, `~`, `0x18`). Optionally it accepts a log line (`; text`) and a state line with the battery
|
|
31
|
+
level (`[HW:bat=74,...]`) for the widget, and it sends the handwheel status lines it can show on a display. The exact
|
|
32
|
+
lines are in [Pendant protocol](#pendant-protocol). A handwheel that already works with a GCode sender that sees the
|
|
33
|
+
machine's serial port needs little or no change.
|
|
34
|
+
|
|
35
|
+
The bridge was developed and tested for
|
|
36
|
+
[CNC-Router-Handwheel](https://github.com/thor-schueler/CNC-Router-Handwheel), an ESP32
|
|
37
|
+
based CNC router handwheel. It has axis and feed selectors, a rotary encoder, a
|
|
38
|
+
set of buttons (home, zero, unlock, spindle, ...) and an emergency stop, shows work and machine position on a
|
|
39
|
+
display, and connects by USB or Bluetooth.
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
11
43
|
## Install
|
|
12
44
|
|
|
13
45
|
npm install -g cncjs-handwheel
|
|
@@ -139,6 +171,7 @@ Start from `cncjs-handwheel.config.example.json`.
|
|
|
139
171
|
| `jog.cancelSettleMs` | wait between emptying the CNCjs feeder queue and sending the Grbl jog cancel (default 40 ms, see "Jog cancel") |
|
|
140
172
|
| `jog.stallMs` | if the controller acknowledges nothing for this long (default 2000), the unanswered lines are assumed lost: the bridge prints a warning, counts a stall and starts counting afresh |
|
|
141
173
|
| `jog.echo` | tag jog lines with `{echo: false}` as context (default `false`; other gcode is not tagged). CNCjs passes it on in its `serialport:write` event, so a console widget can hide the `feeder> $J=...` echo. Stock CNCjs ignores it (see "Quieting the CNCjs console") |
|
|
174
|
+
| `guard.duringJob` | `true` (default): while a job is running or paused (or its state is not known yet) no gcode line from the pendant is sent, see "Jobs and the pendant" |
|
|
142
175
|
| `http` | health endpoint (`enabled`, `host`, `port`) |
|
|
143
176
|
| `log.max` | pendant log lines kept for the widget |
|
|
144
177
|
|
|
@@ -179,9 +212,32 @@ started.
|
|
|
179
212
|
## CNCjs widget
|
|
180
213
|
|
|
181
214
|
The package ships a small [custom widget](https://github.com/cncjs/cncjs-widget-boilerplate) for CNCjs (source in
|
|
182
|
-
`widget/`, built output in `widget/dist`).
|
|
183
|
-
|
|
184
|
-
|
|
215
|
+
`widget/`, built output in `widget/dist`). It shows the state of the whole chain, handwheel, bridge and CNCjs, at a
|
|
216
|
+
glance, and the details when you need them.
|
|
217
|
+
|
|
218
|
+
**Collapsed**, it is a header with a handwheel icon coloured by the link state, a title, the machine state and, when a
|
|
219
|
+
handwheel is there, small counters: reconnects, errors and dropped lines (**Reconn|Err|Drop**) and jog commands in
|
|
220
|
+
flight and held back (**In flight|Held**). Below that is one row with the link type (USB or Bluetooth), the battery
|
|
221
|
+
level with the time to full or empty, and the handwheel's own status (**OK**, or **Check log** when it reports a
|
|
222
|
+
problem). The three states:
|
|
223
|
+
|
|
224
|
+
<div style="margin-left: 5%; width: 80%">
|
|
225
|
+
|
|
226
|
+
| Handwheel disconnected | Handwheel off | Handwheel connected |
|
|
227
|
+
|---|---|---|
|
|
228
|
+
| <p align="center"><img src="docs/images/widget-disconnected.png" alt="Handwheel disconnected" width="350"></p> | <p align="center"><img src="docs/images/widget-switched-off.png" alt="Handwheel switched off" width="350"></p> | <p align="center"><img src="docs/images/widget-connected.png" alt="Handwheel connected" width="350"></p> |
|
|
229
|
+
| Red. The bridge cannot open the handwheel's serial port: it is unplugged, out of Bluetooth range or off. There is nothing to count, so the counters and battery are blank. | Grey. The handwheel is plugged in but its power is off (see [Detecting a switched-off handwheel](#detecting-a-switched-off-handwheel)). The link type is still shown. | Green. The handwheel is connected, CNCjs is reachable and the machine port is open, with the battery, charging state and the counters. Amber if CNCjs or the machine port is not available. |
|
|
230
|
+
|
|
231
|
+
</div>
|
|
232
|
+
|
|
233
|
+
**Expanded** (fullscreen from the CNCjs widget menu, or the button in the widget) it adds cards for the machine
|
|
234
|
+
(state, work position, feed and spindle), the connection (port, power, bridge version and uptime, last line in and out),
|
|
235
|
+
the handwheel (free heap, stack warnings, reconnects, errors, dropped lines, status to the pendant), CNCjs (socket,
|
|
236
|
+
machine port, device, controller, dropped commands) and jogging (sent and merged, discarded, in flight and held,
|
|
237
|
+
cancels and stalls), and below them the handwheel log, a live tail of what the handwheel and the bridge report.
|
|
238
|
+
|
|
239
|
+
<p align="center"><img src="docs/images/widget-expanded.png" alt="The expanded widget" width="60%"></p>
|
|
240
|
+
|
|
185
241
|
|
|
186
242
|
| Icon colour | Meaning |
|
|
187
243
|
|---|---|
|
|
@@ -264,7 +320,7 @@ Pendant to bridge:
|
|
|
264
320
|
| Line | Effect |
|
|
265
321
|
|---|---|
|
|
266
322
|
| `G21G91X+10F2000` | jog (sent as `$J=...`); any other line that looks like gcode (words such as `G10 L20 P1 Z15.05`, a Grbl `$` command, a CNCjs `%` line) is sent to the controller as gcode. Other text is not sent: it is shown in the widget's log as `[not gcode, not sent] ...` and counted (`pendant.strayLines`, and in `garbageLines`, the widget's Drop). Turn that off with `device.strictGcode: false` |
|
|
267
|
-
| `!` / `~` / `^X` (0x18) | feed hold / cycle start / reset, each as a line of its own (reset at most once per 2 s) |
|
|
323
|
+
| `!` / `~` / `^X` (0x18) | feed hold / cycle start / reset, each as a line of its own (reset at most once per 2 s). While a job is running `!` is sent as CNCjs `gcode:pause` and while it is paused `~` as `gcode:resume` (see "Jobs and the pendant"); otherwise they are `feedhold` and `cyclestart` |
|
|
268
324
|
| `$X` | unlock; sent to CNCjs as its `unlock` command, because a gcode line is dropped by CNCjs while the machine is in Alarm |
|
|
269
325
|
| `... ; comment` | as in gcode, everything after a `;` that is not at the start of the line is a comment: it is not sent, only the part before it is the command. So `0x18; Reset the machine` is a reset and `$X; Unlock` an unlock. (A line that starts with `;` is a log entry) |
|
|
270
326
|
| `0x85` (the single byte, as a line of its own) or `JOGCANCEL` | cancel the jog in progress (Grbl only), see "Jog cancel" below |
|
|
@@ -280,6 +336,7 @@ Bridge to pendant:
|
|
|
280
336
|
| `<Idle\|MPos:x,y,z\|WPos:x,y,z\|FS:feed,spindle>` | status: at most about 3 per second, at least every 400 ms, and shortly after every command |
|
|
281
337
|
| `<Disconnected>` | the bridge is up, but CNCjs or the CNC port is not |
|
|
282
338
|
| `ERR:CNCJS_NOT_READY` | a command was dropped because the CNC port is not open |
|
|
339
|
+
| `ERR:JOB_ACTIVE` | a gcode line was dropped because a job is running or paused (at most once a second), see "Jobs and the pendant" |
|
|
283
340
|
| `PONG` | answer to `PING` |
|
|
284
341
|
|
|
285
342
|
The status right after a command shows where the machine was at that moment; Grbl's `ok` only means the move was
|
|
@@ -322,6 +379,27 @@ the machine moves) tracks the move. If no line arrives for about 1 second, treat
|
|
|
322
379
|
- **`$$` and `$I` output at start.** Normal: CNCjs queries the controller when a client opens the CNC port.
|
|
323
380
|
- **No WPos.** Grbl reports the work offset only every 10-30 status reports; the first WPos can take a few seconds.
|
|
324
381
|
|
|
382
|
+
## Source layout
|
|
383
|
+
|
|
384
|
+
`bin/cncjs-handwheel` only reads the command line and starts the bridge. The rest is in `lib/`:
|
|
385
|
+
|
|
386
|
+
| File | What it does |
|
|
387
|
+
|---|---|
|
|
388
|
+
| `bridge.js` | creates the parts below and connects them to the CNCjs socket events |
|
|
389
|
+
| `config.js` | defaults, and how `~/.cncrc`, the config file and the command line are merged |
|
|
390
|
+
| `protocol.js` | what a line from the pendant means: gcode or not, jog translation and splitting, the pendant's status report (no state) |
|
|
391
|
+
| `pendant-input.js` | splits the serial stream into lines and handles each one |
|
|
392
|
+
| `pendant-link.js` | the pendant's serial port: open, reconnect, write, power line |
|
|
393
|
+
| `commands.js` | commands to CNCjs, and the answer to the pendant |
|
|
394
|
+
| `jog.js` | the jog governor (merging, in-flight limit, cancel) |
|
|
395
|
+
| `guard.js`, `job-guard.js` | the decisions of the job guard, and what is done with them |
|
|
396
|
+
| `status.js`, `status-sender.js` | the status line (positions, format), and when it is sent |
|
|
397
|
+
| `health.js`, `http.js` | counters, the pendant log, and the `/status` and `/log` endpoint |
|
|
398
|
+
| `service.js` | `install-service` / `uninstall-service` |
|
|
399
|
+
|
|
400
|
+
The parts do not import each other. They share one context object and call each other through it, which also lets the tests
|
|
401
|
+
replace the neighbours of one part with stubs (see `test/jog.test.js`). `npm test` runs the tests, `npm run check` checks the syntax.
|
|
402
|
+
|
|
325
403
|
## Testing without hardware (pendant simulator)
|
|
326
404
|
|
|
327
405
|
`tools/pendant-sim.js` emulates the handwheel on a serial port, so you can exercise the bridge from a dev machine (it lives in the repository only; it is not part of the npm package).
|
|
@@ -369,6 +447,32 @@ Two other sources of console noise can be reduced from the bridge's side:
|
|
|
369
447
|
Set `status.pollAfterCommand` to `false`; CNCjs polls the controller by itself and the pendant still gets status lines.
|
|
370
448
|
- The `ok` for every jog is echoed by CNCjs (`serialport:read`); only a console filter can hide those.
|
|
371
449
|
|
|
450
|
+
## Jobs and the pendant
|
|
451
|
+
|
|
452
|
+
When a job is paused in CNCjs only the job itself is held, not the queue that other commands go through. A jog, a button's
|
|
453
|
+
gcode or a macro sent from the pendant during the pause is written to Grbl at once; Grbl does not run it before the job is
|
|
454
|
+
resumed, and then it runs *between two program lines*. It also upsets the accounting of the sender (the `ok` of the injected
|
|
455
|
+
line is counted for a program line) and, if it fails, pauses the job again with a misleading error.
|
|
456
|
+
|
|
457
|
+
The bridge therefore follows the CNCjs workflow state (`workflow:state`: `idle`, `running`, `paused`) and, unless it is `idle`
|
|
458
|
+
(or not known yet, for example just after a reconnect):
|
|
459
|
+
|
|
460
|
+
- drops every gcode line from the pendant: jogs, button gcode, each line of a macro, `$X`. The pendant gets `ERR:JOB_ACTIVE`
|
|
461
|
+
(at most once a second), the widget's log shows `[a job is paused, not sent] ...`, and `/status` counts them under
|
|
462
|
+
`guard.dropped`;
|
|
463
|
+
- lets the real-time commands through: `!`, `~`, `^X`, `?` and jog cancel. With a job on, `!` pauses the job (CNCjs `gcode:pause`) and `~` resumes a paused one (`gcode:resume`) instead of the plain `feedhold` / `cyclestart`, so the CNCjs workflow follows the machine, and an `M0` / `M6` pause can be continued from the pendant;
|
|
464
|
+
- turns **`M5`** and **`M3`** into Grbl's real-time *toggle spindle stop* (`0x9E`) instead of sending them as gcode. Grbl
|
|
465
|
+
accepts that byte only while the machine is in **Hold** (a job paused with a feed hold); the spindle then stops, and
|
|
466
|
+
Grbl switches it on again by itself when the job is resumed. `M5` stops the spindle, `M3` (with or without `S`, which
|
|
467
|
+
cannot be applied) switches on again a spindle that the bridge stopped. Because `0x9E` is a toggle, a second `M5` and an
|
|
468
|
+
`M3` without a stop before are ignored. Outside Hold, and for controllers other than Grbl, they are dropped like other
|
|
469
|
+
gcode.
|
|
470
|
+
|
|
471
|
+
`/status` shows the workflow state under `cncjs.workflow` and the counters under `guard` (`dropped`, `spindle`, `lastAgeMs`).
|
|
472
|
+
`guard.duringJob: false` turns all this off. The byte is written through CNCjs (`write`); CNCjs sends a string, which a
|
|
473
|
+
serial port encodes as UTF-8, so Grbl sees `0xC2 0x9E`. Grbl 1.1 ignores the extended-ASCII byte it does not know (`0xC2`) and
|
|
474
|
+
acts on `0x9E`, as it does for the override buttons of CNCjs; check once on your machine.
|
|
475
|
+
|
|
372
476
|
## Jog cancel
|
|
373
477
|
|
|
374
478
|
For real jogging the pendant sends one long jog when the wheel or button starts (`$J=G21G91X1000F2000`) and a jog cancel when
|