- Posts: 648
- Thank you received: 0
Lathe Chuck Table
2 weeks 5 days ago #350209
by anfänger
Lathe Chuck Table was created by anfänger
While getting my linuxcnc rettrofit lathe running again after moving shop. I wanted to turn close to the spindle. But my soft limits protect me from doing this. Of course you can ignore limits, but I was thinking about a "chuck table" with some more details on it like:
diameter, max rpm, z_limit, number of jaws and weight.
My concept so far...
Files:
diameter, max rpm, z_limit, number of jaws and weight.
My concept so far...
Files:
- chucks.json – Stores your database of chucks, limits, and parameters.
- current_chuck.json – Automatically created/updated to persist the currently active chuck across reboots.
- chuck_manager.py – The Python handler script linked to your custom tab.
Widgets:
Widget TypeObject Name (objectName)Description
QComboBoxchuck ComboBoxDropdown showing line numbers and chuck names (synced with the table)
QPushButton activateChuckBtn confirmation button to apply limits and save state.
QTableWidget chuckTable 7-column interactive table to view, add, edit, and delete chuck profiles.
QPushButton addChuckBtn Button to insert a new blank row into the table.
QPushButton saveTableBtn Button to save table modifications permanently back to chucks.json.
QPushButton deleteChuckBtn Button to remove the currently selected row.
QLabel lblMaxRpm Displays the maximum allowed spindle RPM for the selected chuck.
QLabel lblZLimit Displays the active Z-axis soft limit (ini.z.min_limit).
QLabel lblDiameter Displays the chuck body diameter.
QLabel lblJaws Displays the number of jaws.
QLabel lblJawsDisplays the number of jaws.QLabellbl Weight Displays the chuck weight in kilograms.
At the moment I have four chucks:
{
"Standard 3-Jaw Chuck (250mm)": {
"max_rpm": 2400,
"z_limit": -45.0,
"diameter": 250,
"jaws": 3,
"weight_kg": 25.5
},
"centric 4-jaw Chuck (160mm)": {
"max_rpm": 3000,
"z_limit": -60.0,
"diameter": 160,
"jaws": 4,
"weight_kg": 4.2
},
"Heavy 4-jaw Chuck (400mm)": {
"max_rpm": 800,
"z_limit": -30.0,
"diameter": 400,
"jaws": 4,
"weight_kg": 40.0
}
"Power chuck (250mm)": {
"max_rpm": 2400,
"z_limit": -45.0,
"diameter": 250,
"jaws": 3,
"weight_kg": 50.0
}
"Spindle": {
"max_rpm": 3000,
"z_limit": -110.0,
"diameter": 60,
"jaws": 0,
"weight_kg": 0.0
}
}
Next is writing and debugging the script.
- current_chuck.json – Automatically created/updated to persist the currently active chuck across reboots.
Please Log in to join the conversation.
2 weeks 4 days ago #350217
by anfänger
Replied by anfänger on topic Lathe Chuck Table
I Cheated and used Claude in the end.If anyone wants to use soothing like this also here is a manual and the necessary files
OverviewThis UserTab lets a lathe operator pick the mounted chuck from a list and enforce that chuck's limits in HAL: a maximum spindle speed and a Z soft limit. It is built for Probe Basic Lathe (QtPyVCP) and tested on a Mesa 7i97 machine, but nothing in it is hardware-specific.
HAL pins) and Probe Basic Lathe with UserTab support. Check the Z pin exists with
.
The folder name,
name and
name must match. The JSON files live in the config directory, not in the tab folder; the tab finds it through the
environment variable that LinuxCNC sets.Step 1: HALLinuxCNC has no writable HAL pin for the maximum spindle speed, so a
component is inserted into the speed command chain. The Z soft limit needs no HAL change: the tab writes the existing
pin.Find the line in your main HAL file that takes
(or
) to your output stage. Insert the clamp between them. Example for a chain that ends in a
component:
Without a gearbox, connect
to whatever
fed before (a PWM generator, a scale component, a VFD pin). The clamp sits after the spindle override and before the gearbox, so it limits the real chuck speed and the override knob cannot push past it.The pins are named
and
, without underscore. The
source declares them as
/
, but
strips the trailing underscore.
aborts LinuxCNC startup with "parameter or pin not found".After a restart, check with
.Step 2: install the UserTab files
The values in the example are placeholders. Take max RPM from the chuck's rating plate or datasheet, and measure the Z limit on your machine. Z is in machine coordinates, so its sign depends on your machine's travel and home position.Step 3: configure and testFour constants at the top of
control the behaviour:ConstantDefaultMeaning
Re-apply the saved chuck to HAL at startup without a dialog.
only logs a warning and marks nothing active.
Pin for the Z soft limit.
Pin for the RPM clamp from Step 1.
Lowest Z limit a chuck may have, in mm.
disables the check. Set it a few tenths of a mm inside the physical limit switch once you have measured it.The chuck limit can only make the machine more restrictive. LinuxCNC still enforces
and
from the INI, so a chuck Z limit below them has no effect. Set the INI values to the real travel and let the chucks narrow it.Test before cutting:
a
, so an empty combo box is falsy.
returns before the first item is added.Test widgets with
/
, never by truthiness.
behaves the same.LinuxCNC aborts: "parameter or pin 'chuck-rpm-limit.min_' not found"
strips a trailing underscore from pin names.Use
/
.Activation seems to work but the spindle is not limited
does not exist;
ignored the error.Clamp in HAL (Step 1) and check the
return code.A button does nothingIts objectName in the
(e.g.
after copy/paste) differs from the name in the code.Keep the names in the table below.
on a LED pin failsQtPyVCP turns
in a widget name into
in the pin name: widget
becomes
.Look up pin names with
.Object names the code expects in the
:WidgetobjectNameQComboBox
QPushButton
,
,
,
QTableWidget
QLabel
,
,
,
,
If
is missing from the
, the code creates one and inserts it into the layout named
.
- Chuck table: add, edit, delete and save chucks (name, max RPM, Z limit, diameter, jaws, weight). Data lives in
in the config directory.Code:chucks.json
- Dropdown + info line: select a chuck and see its data at a glance. The active chuck is highlighted green in the table.
- Activation with confirmation: one button writes both limits to HAL after a Yes/No dialog. If
fails, the chuck is not marked active and an error dialog appears.Code:halcmd
- Plausibility check: rejects RPM <= 0, RPM above
, Z at or aboveCode:[SPINDLE_0] MAX_FORWARD_VELOCITY, and optionally Z below a configurable floor.Code:[AXIS_Z] MAX_LIMIT
- Persistence: the active chuck is stored in
and re-applied automatically at startup, so the display and HAL never disagree after a restart.Code:current_chuck.json
- Fail-safe RPM clamp: the spindle clamp is a HAL component with a conservative default, so the low limit holds even if the GUI never starts.
Code:
ini.<axis>.min_limit
Code:
halcmd show pin ini.z.min_limit
Code:
~/linuxcnc/configs/<your-config>/
├── <your-machine>.ini
├── <your-main>.hal # gets the RPM clamp (Step 1)
├── chucks.json # chuck database (created on first save)
├── current_chuck.json # active chuck (written by the tab)
└── user_tabs/
└── chuck_manager/
├── chuck_manager.py # logic (class UserTab)
└── chuck_manager.ui # Qt Designer layout
Code:
.py
Code:
.ui
Code:
CONFIG_DIR
Code:
limit1
Code:
ini.z.min_limit
Code:
spindle.0.speed-out-abs
Code:
speed-out
Code:
gearchange
Code:
# --- load (with your other loadrt lines) ---
loadrt limit1 names=chuck-rpm-limit
# --- thread: AFTER motion-controller, BEFORE whatever reads the speed,
# and BEFORE hm2_xxx.write ---
addf chuck-rpm-limit servo-thread
# --- wiring ---
# before: net spindle-vel-cmd-rpm-abs spindle.0.speed-out-abs => gearchange.0.speed-in
net spindle-vel-cmd-rpm-abs spindle.0.speed-out-abs => chuck-rpm-limit.in
net spindle-rpm-limited chuck-rpm-limit.out => gearchange.0.speed-in
# --- fail-safe default until the GUI activates a chuck ---
setp chuck-rpm-limit.min 0
setp chuck-rpm-limit.max 500 # RPM of your weakest chuck
Code:
chuck-rpm-limit.out
Code:
speed-out-abs
Code:
min
Code:
max
Code:
limit1
Code:
min_
Code:
max_
Code:
halcompile
Code:
setp chuck-rpm-limit.max_
Code:
halcmd show pin chuck-rpm-limit
- Create
in your config directory and copyCode:user_tabs/chuck_manager/andCode:chuck_manager.pyinto it.Code:chuck_manager.ui
- Point Probe Basic at the folder in your INI, if it is not there yet:
Code:[DISPLAY] USER_TABS_PATH = user_tabs/
- Optionally copy the example
into the config directory. Without it the table starts empty and the file is created on the first "Save Changes".Code:chucks.json
Code:
{
"3-Jaw 160": {
"max_rpm": 3000,
"z_limit": 5.0,
"diameter": 160,
"jaws": 3,
"weight_kg": 12.0
},
"4-Jaw 250 Heavy": {
"max_rpm": 1200,
"z_limit": 25.0,
"diameter": 250,
"jaws": 4,
"weight_kg": 38.0
}
}
Code:
chuck_manager.py
Code:
AUTO_APPLY_ON_START
Code:
True
Code:
False
Code:
HAL_PIN_Z_MIN
Code:
"ini.z.min_limit"
Code:
HAL_PIN_RPM_MAX
Code:
"chuck-rpm-limit.max"
Code:
Z_LIMIT_FLOOR
Code:
None
Code:
None
Code:
[JOINT_n] MIN_LIMIT
Code:
[AXIS_Z] MIN_LIMIT
- Start LinuxCNC and open the tab. The dropdown and the table must show your chucks.
- Activate a chuck. Then run
and check both values arrived.Code:halcmd show pin ini.z.min_limit chuck-rpm-limit
- In MDI, command an
value above the chuck's limit.Code:Smust stay at the limit whileCode:chuck-rpm-limit.outshows the commanded value.Code:.in
- Jog Z slowly toward the chuck. Motion must stop at the chuck's Z limit.
- Restart LinuxCNC. The same chuck must be green again and step 2 must show the same values.
- Edit: type into the table, use "Add Chuck" / "Remove Chuck", then "Save Changes". Save validates all numbers and rewrites
. A row with invalid data aborts the save with a message.Code:chucks.json
- Select: pick a chuck in the dropdown or click its row. The info line shows max RPM, Z limit, diameter, jaws and weight. Nothing is applied yet.
- Activate: "Activate Chuck" runs this sequence:
- Plausibility check against the INI and
. On failure: error dialog, nothing applied.Code:Z_LIMIT_FLOOR
- Confirmation dialog showing the two limits.
-
for the Z pin, then the RPM pin. Each return code is checked.Code:halcmd setp
- Only if both succeeded: green row and
written.Code:current_chuck.json
- Plausibility check against the INI and
- Startup: the tab loads
, selects the saved chuck and, withCode:chucks.json, re-runs steps 1, 3 and 4 without the dialog.Code:AUTO_APPLY_ON_START
- It clamps the command, not the spindle. A drive fault, a wrong analog scale or a runaway VFD can still overspeed the chuck. Real overspeed protection needs independent monitoring of the encoder speed, or a drive-side speed limit.
- The clamp is silent.
with a 1500 RPM chuck runs at 1500 RPM without a warning. Surface speed and feed per rev change accordingly.Code:S2000
- The operator must select the right chuck. The system cannot detect which chuck is mounted.
- The fail-safe default only helps if it is low. Set
in the HAL file to your weakest chuck.Code:chuck-rpm-limit.max
- Limits apply until the next activation or restart. Changing a chuck's row and saving does not re-apply it; activate again.
- Keep hardware limit switches and E-stop in the drive enable chain. If LinuxCNC or the GUI hangs, only hardware stops the machine.
Code:
QComboBox
Code:
__len__()
Code:
if not self.combo: return
Code:
is None
Code:
is not None
Code:
QLayout
Code:
halcompile
Code:
.min
Code:
.max
Code:
motion.spindle-max-speed
Code:
os.system()
Code:
halcmd
Code:
.ui
Code:
saveTableBtn_2
Code:
halcmd setp
Code:
_
Code:
-
Code:
LEDIN_00
Code:
qtpyvcp.LEDIN-00.on
Code:
halcmd show pin qtpyvcp
Code:
.ui
Code:
chuckComboBox
Code:
activateChuckBtn
Code:
saveTableBtn
Code:
addChuckBtn
Code:
deleteChuckBtn
Code:
chuckTable
Code:
lblMaxRpm
Code:
lblZLimit
Code:
lblDiameter
Code:
lblJaws
Code:
lblWeight
Code:
chuckComboBox
Code:
.ui
Code:
horizontalLayout
Please Log in to join the conversation.
- tommylight
-
- Away
- Administrator
-
Less
More
- Posts: 22009
- Thank you received: 3
2 weeks 2 days ago #350269
by tommylight
Replied by tommylight on topic Lathe Chuck Table
That is a loooong post, thank you.
Please Log in to join the conversation.
2 weeks 2 days ago #350280
by anfänger
Replied by anfänger on topic Lathe Chuck Table
I hope this way it might help someone if he wants the same feature. Or improve it.
I think it might be interesting to see what other have as cutom features, so one knows whats possible and might be handy.
I think it might be interesting to see what other have as cutom features, so one knows whats possible and might be handy.
Please Log in to join the conversation.
Time to create page: 0.080 seconds
