# Probe Basic Lathe

Tool data lives in a single SQLite database, editable live from the tool
table UI, with typed extras/custom columns and no external Fusion library
required. This replaced the older classic `.tbl` + Fusion 360 JSON workflow
as the standard for this config.

Also present: `pb_test_xzc.ini` / `pb_test_xyzc.ini`, extra kinematics
variants (C axis added) of the same machine, sharing everything in this
folder including the tool database.


## Files specific to this config

- `probe_basic_lathe.ini` -- the machine config: `[EMCIO] DB_PROGRAM =
  ./tool_db.sh` instead of `TOOL_TABLE = lathe.tbl`, `CONFIG_FILE =
  custom_config.yml` (wires the DBToolTable plugin), and the `[RS274NGC]
  REMAP=M6` line (see "Tool change" below).
- `lathe_conv_sim_tools.db` -- the actual tool data (SQLite). Edit tools
  live from the tool table widget -- there's nothing to hand-edit in the
  database file itself.
- `custom_config.yml` -- qtpyvcp widget/screen config, wires
  `qtpyvcp.plugins.db_tool_table:DBToolTable` as the tooltable plugin.
- `tool_db.sh` -- the `DB_PROGRAM` wrapper LinuxCNC's `iocontrol` shells out
  to for tool data. Resolves `[EMCIO] TOOL_DB_FILE` relative to its own
  location, so it works if you copy this whole folder somewhere else.


## Tool change

`[RS274NGC] REMAP=M6` points at `subroutines/toolchange_manual.ngc` by
default. That file does nothing but fall through to LinuxCNC's own built-in
tool-change handling (prompt-and-wait) -- it exists purely so
`change_prolog`/`change_epilog` in `python/stdglue.py` run around every tool
change and publish the loaded tool's data as G-code parameters (see below).
**This is the correct default for manual tool change, which is most
machines.**

If you have a real automatic tool changer (turret/carousel), change the
`REMAP=M6 ... ngc=` target to `toolchange` instead
(`subroutines/toolchange.ngc`) -- that file actually indexes/rotates/clamps
hardware. Don't point a manual machine at it.

Either way, the parameter publishing below happens automatically. You don't
need to build a remap just to get it.


## Reading tool data from G-code

Every tool change (manual or ATC) writes the *currently loaded* tool's
numeric extras/custom columns to `#<_current_tool_*>` parameters --
e.g. `#<_current_tool_nose_radius>`. This always describes whatever tool is
actually in the spindle right now, not "tool N" by number -- there's no
by-tool-number lookup from G-code, only the loaded tool's data.

To see the exact parameter name for any column: right-click its header in
the tool table UI and pick "Parameter Names" -- it lists the live
`#<_current_tool_*>` name for every numeric extras/custom column on that
row, generated from whatever columns actually exist in your database (core
columns like X/Z offset aren't included there since G-code already has
native access to those via the standard tool-table words).

Text columns (holder style, notes, etc.) aren't published -- RS274NGC has no
string parameter type.


## Adding custom columns

Use the "Add Column" button in the tool table UI. Pick a type (int / float
/ bool / text) -- the editor enforces it, so you can't put a non-numeric
value in a numeric column. Numeric custom columns automatically get a
`#<_current_tool_*>` parameter the same way the built-in extras columns do;
text columns are UI/reference-only.


## Starting your own tool set from scratch

`lathe_conv_sim_tools.db` ships with the reference tools for the sim machine. To
wipe those and start empty (or reseed from a `.tbl` file), see
`~/dev/scratch/qtpyvcp/tests/seed_db_from_tbl.py` -- or just delete every
row from the tool table UI and add your own.
