cncjs-handwheel 0.7.3 → 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 CHANGED
@@ -1,13 +1,45 @@
1
1
  # cncjs-handwheel
2
2
 
3
- Bridge between CNCjs and a serial (USB or Bluetooth) ESP32 handwheel pendant. It runs on the same machine as CNCjs.
4
-
5
- - pendant -> CNCjs: gcode lines, realtime commands, console log lines
6
- - CNCjs -> pendant: status lines (state, MPos, WPos, feed/spindle), about 10 per second
7
- - health and the pendant log as JSON on `http://127.0.0.1:8001` (for a CNCjs widget)
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
@@ -180,9 +212,32 @@ started.
180
212
  ## CNCjs widget
181
213
 
182
214
  The package ships a small [custom widget](https://github.com/cncjs/cncjs-widget-boilerplate) for CNCjs (source in
183
- `widget/`, built output in `widget/dist`). Collapsed, it is one row: a handwheel icon coloured by the link state and a
184
- short status line. Expanded (fullscreen, or the button in the widget) it adds machine position, handwheel, CNCjs and
185
- jog statistics and a live tail of the handwheel log.
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
+
186
241
 
187
242
  | Icon colour | Meaning |
188
243
  |---|---|
@@ -324,6 +379,27 @@ the machine moves) tracks the move. If no line arrives for about 1 second, treat
324
379
  - **`$$` and `$I` output at start.** Normal: CNCjs queries the controller when a client opens the CNC port.
325
380
  - **No WPos.** Grbl reports the work offset only every 10-30 status reports; the first WPos can take a few seconds.
326
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
+
327
403
  ## Testing without hardware (pendant simulator)
328
404
 
329
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).