Import LinuxCNC source tree

This commit is contained in:
Wang Dequan
2026-08-20 06:17:39 +08:00
commit 2c814634c3
9429 changed files with 10556013 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
Simulation of a Mill-Turn machine
This shows the use of switchable kinematics for a machine with 3 linear cartesian joints (XYZ) and one rotary joint (A) where the rotary (A) can be used as an axis and as a spindle. Switching the kinematic between a mill configuration and a lathe configuration can be done using M-codes in MDI-mode or inside a GCODE-program (M428 for milling / M429 for turning).
After loading the config and homing the configuration is set to milling (M428).
SOFTLIMITS: Axis-Softlimits are defined in the usual [AXIS_n]-section of the INI file. 'MIN_LIMIT' and 'MAX_LIMIT' are used for the default kinematic (mill). For the alternative kinematic (turn) additional entries 'MIN_LIMIT_TURN' and 'MAX_LIMIT_TURN' are used for the required axis (x,y and z). Note that the 'set coords " "' entry in ./mcodes/M128 and ./mcodes/M129 has to contain the required axis (set coords "x y z"). Because the home position of the Y axis has been set up to be in the center of the axis, the softlimits for Y are identical for both kinematics so switching them is not strictly necessary in this case but has been included for the user to experiment.
Also note that M128 and M129 are not meant to be called directly by the user but are called from inside M428/M429 codes and that because of the forced synchronization in M128/M129 the motion planner cannot "see" limit violations beyond the next kinematic switch. Only after the M128/M129 command has been executed will the following gcode (up to the next kinematic switch) be checked for limit violations.
Note that, switching of velocity and acceleration settings can be handled in the same manner as the softlimits.
VISMACH: Due to limitations of vismach, turning tools will only show correctly if tooloffset for X and Z are identical. Other offsets can be used and will be calculated correctly for the toolpath but the graphical tool representation will not be correct in vismach visualization. Also mill-bits are not shown cylindrical but as a triangle.
M428 will:
1. Set the kinematic to 'mill' - mode
x : joint0
y : joint1
z : joint2
a : joint3
so the gcode commands:
'g0x10' moves joint0
'g0z10' moves joint2
2. Load the softlimits as defined in 'MIN_LIMIT' and 'MAX_LIMIT' of [AXIS_n]-section of the INI file (for AXIS_X and AXIS_Z)
3. Set the G59.1 home offset to X-290 Y0 Z-160 A0 (this can be changed in ./remaps/428remap.ngc)
4. Activate G59.1 offset
5. Force a synchronization
M428 will:
1. Set the kinematic to 'turn' - mode
x : joint2
y : -joint1
z : joint0
a : joint3
so the gcode commands:
'g0x10' moves joint2
'g0z10' moves joint0
2. Load the softlimits as defined in 'MIN_LIMIT_TURN' and 'MAX_LIMIT_TURN' of [AXIS_n]-section of the INI file (for AXIS_X and AXIS_Z)
3. Set the G59.2 home offset to X-160 Y0 Z-290 A0 (this can be changed in ./remaps/429remap.ngc)
4. Activate G59.2 offset
5. Force a synchronization

View File

@@ -0,0 +1,212 @@
(setup work offsets to run sim w/o .var file)
G10 L2 P1 X-160 Y0 Z-230 (setup G54 for mill)
G10 L2 P2 X-275 Y0 Z-140 (setup G55 for turn)
(actual code starts here)
G21
G40
G64
M429 (turning)
G18 G8
G54
T05 M6 G43
G00 X20 Z25
G00 X13.5 Z1.0 S1000 M3
Z0.488
G94 G01 X-1.0 F1000.0
Z0.975
G00 X0.383 Z1.269
X13.5
Z0.0
G01 X-1.0
Z0.488
G00 X0.383 Z0.782
X13.5
Z1.0
Z2.0
X11.237
G01 Z-34.973 F1000.0
X12.2 Z-35.95
Z-37.95
X12.625
G00 X13.625 Z-36.95
Z2.0
X9.849
G01 Z-19.832
G00 X10.849 Z-18.832
Z2.0
X8.461
G01 Z-19.832
X9.849
G00 X10.849 Z-18.832
Z2.0
X7.073
G01 Z-10.296
G00 X8.073 Z-9.296
Z2.0
X5.685
G01 Z-8.784
G03 X7.073 Z-10.296 I-0.98513 K-2.29772
G00 X8.073 Z-9.296
Z2.0
X4.297
G01 Z-8.582
X4.7
G03 X5.685 Z-8.784 I-0.0 K-2.5
G00 X6.685 Z-7.784
Z2.0
X2.909
G01 Z-0.559
G00 X3.909 Z0.441
Z2.0
X1.521
G01 Z0.829
X2.909 Z-0.559
G00 X4.909 Z1.441
Z0.441
X2.909
G01 Z-0.559
X3.2 Z-0.85
Z-4.15
X2.909 Z-4.654
Z-8.11
G02 X4.2 Z-8.582 I1.29082 K1.52767
G01 X4.297
G00 X5.297 Z-7.582
Z-4.654
X3.909
G01 X2.909
X2.468 Z-5.418
G02 X2.2 Z-6.418 I1.73205 K-1.0
G01 Z-6.582
G02 X2.909 Z-8.11 I2.0 K0.0
G00 X3.909 Z-7.11
X7.073
Z-9.296
G01 Z-10.296
G03 X7.2 Z-11.082 I-2.3731 K-0.78638
G01 Z-11.382
G03 X7.073 Z-12.168 I-2.5 K0.0
G01 Z-19.832
X8.461
G00 X9.461 Z-18.832
Z-12.168
X8.073
G01 X7.073
G03 X6.485 Z-13.132 I-2.3731 K0.78638
G02 X5.685 Z-14.204 I3.57071 K-3.5
G01 Z-18.76
G02 X6.485 Z-19.832 I4.37094 K2.42793
G01 X7.073
G00 X8.073 Z-18.832
Z-14.204
X6.685
G01 X5.685
G02 X5.058 Z-16.482 I4.37075 K-2.42793
G02 X5.685 Z-18.76 I4.99775 K0.15
G00 X6.685 Z-17.76
X9.849
Z-18.832
G01 Z-19.832
X10.2
Z-20.132
X9.849 Z-20.74
Z-24.42
G00 X10.849 Z-23.42
Z-20.74
G01 X9.849
X8.787 Z-22.58
X9.849 Z-24.42
G00 X10.849 Z-23.42
X9.849
G01 Z-24.42
X10.2 Z-25.028
Z-27.328
G02 X9.849 Z-28.029 I5.70735 K-3.29514
G01 Z-32.917
G02 X11.214 Z-34.95 I6.0583 K2.594
G01 X11.237 Z-34.973
G00 X12.237 Z-33.973
Z-28.029
X10.849
G01 X9.849
G02 X9.319 Z-30.473 I6.05858 K-2.594
G02 X9.849 Z-32.917 I6.58858 K0.15
G00 X10.849 Z-31.917
Z-29.029
X11.237
Z2.0
X0.534 Z3.241
G01 X0.202 Z3.041 F150.0
G02 X1.081 Z0.919 I3.0 K0.0
G01 X3.0 Z-1.0
Z-4.0
X2.268 Z-5.268
G02 X2.0 Z-6.268 I1.73205 K-1.0
G01 Z-6.732
G02 X4.0 Z-8.732 I2.0 K0.0
G01 X4.5
G03 X6.285 Z-12.982 I-0.0 K-2.5
G02 Z-19.982 I3.57071 K-3.5
G01 X10.0
X8.5 Z-22.58
X10.0 Z-25.178
Z-27.178
G02 X11.014 Z-35.1 I5.70735 K-3.29514
G01 X12.0 Z-36.1
Z-38.1
G00 X15.0
Z10.0
M428 (milling)
g55
T10 m6 G43
g21 g17 g64 g90
s3400 m3
g0 z10
g0 x5 y0
g2 x-5 y0 i-5 j0 z-1 f500
g2 x5 y0 i5 j0 z-2
g2 x-5 y0 i-5 j0 z-3
g2 x5 y0 i5 j0 z-4
g2 x-5 y0 i-5 j0 z-4
g0 z10
g0 a90
g0 x5 y0
g2 x-5 y0 i-5 j0 z-1
g2 x5 y0 i5 j0 z-2
g2 x-5 y0 i-5 j0 z-3
g2 x5 y0 i5 j0 z-4
g2 x-5 y0 i-5 j0 z-4
g0 z10
g0 a180
g0 x5 y0
g2 x-5 y0 i-5 j0 z-1
g2 x5 y0 i5 j0 z-2
g2 x-5 y0 i-5 j0 z-3
g2 x5 y0 i5 j0 z-4
g2 x-5 y0 i-5 j0 z-4
g0 z10
g0 a270
g0 x5 y0
g2 x-5 y0 i-5 j0 z-1
g2 x5 y0 i5 j0 z-2
g2 x-5 y0 i-5 j0 z-3
g2 x5 y0 i5 j0 z-4
g2 x-5 y0 i-5 j0 z-4
g0 z10
g0 a360
M428 (milling)
G54
G0 X0 Z100 A0
M2
%

View File

@@ -0,0 +1,24 @@
#!/usr/bin/tclsh
# change axis limits to MILL limits
set switchkins_pin 3 ;# agree with inifile
set coords "x y z" ;# agree with inifile
package require Linuxcnc ;# must be before Hal
emc_init -ini $::env(INI_FILE_NAME) -quick
package require Hal
parse_ini $::env(INI_FILE_NAME)
# Check if correct kinematic is active
if {[hal getp kinstype.is-0] == "FALSE"} {
puts "kinematic does not match! Are you calling M128 instead of M428?"
exit 1
}
# RESTORE INI axis limits
foreach l $coords {
set L [string toupper $l]
catch {hal setp ini.$l.min_limit [set ::AXIS_[set L](MIN_LIMIT)]}
catch {hal setp ini.$l.max_limit [set ::AXIS_[set L](MAX_LIMIT)]}
catch {hal setp ini.$l.min_velocity [set ::AXIS_[set L](MAX_VELOCITY)]}
catch {hal setp ini.$l.max_acceleration [set ::AXIS_[set L](MAX_ACCELERATION)]}
}

View File

@@ -0,0 +1,24 @@
#!/usr/bin/tclsh
# change axis limits to TURN limits
set switchkins_pin 3 ;# agree with inifile
set coords "x y z" ;# axis declared must provide MIN_LIMIT_TURN and MAX_LIMIT_TURN in inifile
package require Linuxcnc ;# must be before Hal
emc_init -ini $::env(INI_FILE_NAME) -quick
package require Hal
parse_ini $::env(INI_FILE_NAME)
# Check if correct kinematic is active
if {[hal getp kinstype.is-1] == "FALSE"} {
puts "kinematic does not match! Are you calling M129 instead of M429?"
exit 1
}
# RESTORE INI axis limits
foreach l $coords {
set L [string toupper $l]
catch {hal setp ini.$l.min_limit [set ::AXIS_[set L](MIN_LIMIT_TURN)]}
catch {hal setp ini.$l.max_limit [set ::AXIS_[set L](MAX_LIMIT_TURN)]}
catch {hal setp ini.$l.min_velocity [set ::AXIS_[set L](MAX_VELOCITY)]}
catch {hal setp ini.$l.max_acceleration [set ::AXIS_[set L](MAX_ACCELERATION)]}
}

View File

@@ -0,0 +1,7 @@
net :mill-button <= pyvcp.mill-button => halui.mdi-command-00
net :turn-button <= pyvcp.turn-button => halui.mdi-command-01
net :kinstype.is-0 <= kinstype.is-0 => pyvcp.multilabel.0.legend0
net :kinstype.is-1 <= kinstype.is-1 => pyvcp.multilabel.0.legend1
net :vismach-clear <= pyvcp.vismach-clear => vismach.plotclear

View File

@@ -0,0 +1,16 @@
# start millturn vismach addition
loadusr -W millturngui
# "wire" linuxcnc pins to joints defined in vismach file
net j0 <= joint.0.pos-fb => millturngui.jointX
net j1 <= joint.1.pos-fb => millturngui.jointY
net j2 <= joint.2.pos-fb => millturngui.jointZ
net j3 <= joint.3.pos-fb => millturngui.jointA
# tool input
net tool_len <= motion.tooloffset.z => millturngui.toollength
net tool-x-offs <= motion.tooloffset.x => millturngui.tool-x-offset
net tool_rad <= halui.tool.diameter => millturngui.tooldiameter
# kinematic input
net :kinstype.is-0 => millturngui.millkins

View File

@@ -0,0 +1 @@
pin+ini.x.max_limit pin+ini.x.min_limit pin+ini.y.max_limit pin+ini.y.min_limit pin+ini.z.max_limit pin+ini.z.min_limit pin+kinstype.is-0 pin+kinstype.is-1

View File

@@ -0,0 +1,145 @@
[APPLICATIONS]
APP = halshow ./millturn.halshow
[EMC]
VERSION = 1.1
MACHINE = millturn (mm)
DEBUG = 0
[KINS]
KINEMATICS = millturn
JOINTS= 4
[HAL]
HALUI = halui
HALFILE = LIB:basic_sim.tcl
HALFILE = millturn.hal
HALCMD = net :kinstype-select <= motion.analog-out-03 => motion.switchkins-type
POSTGUI_HALFILE = millturn-postgui.hal
[RS274NGC]
USER_M_PATH = ./mcodes
PARAMETER_FILE = millturn.var
SUBROUTINE_PATH = ./remap_subs
HAL_PIN_VARS = 1
REMAP = M428 modalgroup=10 ngc=428remap
REMAP = M429 modalgroup=10 ngc=429remap
# Set startup offsets
RS274NGC_STARTUP_CODE = G10 L2 P7 X-290 Y0 Z-160 A0 G59.1
[HALUI]
# MDI-COMMANDS 00, 01 (remapped) for switching kinematics and limits:
# M428: mill (kinstype==0 startupDEFAULT)
# M429: turn (kinstype==1)
MDI_COMMAND = M428
MDI_COMMAND = M429
# MDI-COMMANDS 02, 03 are for altering limits when switching
# Note that M129 and M129 are not meant to be called directly.
MDI_COMMAND = M128
MDI_COMMAND = M129
[DISPLAY]
DISPLAY = axis
GEOMETRY = XYZA
CYCLE_TIME = 0.200
POSITION_OFFSET = RELATIVE
POSITION_FEEDBACK = ACTUAL
DEFAULT_LINEAR_VELOCITY = 60.0
DEFAULT_ANGULAR_VELOCITY = 40.0
MAX_FEED_OVERRIDE = 2.0
PROGRAM_PREFIX = ./
INTRO_GRAPHIC = linuxcnc.gif
INTRO_TIME = 5
PYVCP = millturn.xml
EDITOR = geany
OPEN_FILE = example.ngc
[TASK]
TASK = milltask
CYCLE_TIME = 0.010
[EMCMOT]
EMCMOT = motmod
COMM_TIMEOUT = 1.0
SERVO_PERIOD = 1000000
[TRAJ]
COORDINATES = X Y Z A
LINEAR_UNITS = mm
ANGULAR_UNITS = deg
DEFAULT_LINEAR_VELOCITY = 60.0
DEFAULT_ANGULAR_VELOCITY = 60.0
MAX_LINEAR_VELOCITY = 200.0
MAX_ANGULAR_VELOCITY = 100.0
DEFAULT_LINEAR_ACCELERATION = 200.0
MAX_LINEAR_ACCELERATION = 400.0
[EMCIO]
TOOL_TABLE = millturn.tbl
[JOINT_0]
TYPE = LINEAR
MAX_VELOCITY = 60.0
MAX_ACCELERATION = 400.0
MIN_LIMIT = -300
MAX_LIMIT = 300
HOME_SEQUENCE = 0
HOME_OFFSET = 0
HOME = 0
[JOINT_1]
TYPE = LINEAR
MAX_VELOCITY = 60.0
MAX_ACCELERATION = 400.0
MIN_LIMIT = -100
MAX_LIMIT = 100
HOME_OFFSET = 0.0
HOME_SEQUENCE = 0
HOME = 0
[JOINT_2]
TYPE = LINEAR
MAX_VELOCITY = 60.0
MAX_ACCELERATION = 400.0
MIN_LIMIT = -240
MAX_LIMIT = 0
HOME_OFFSET = 0.0
HOME_SEQUENCE = 0
HOME = 0
[JOINT_3]
TYPE = ANGULAR
MAX_VELOCITY = 60.0
MAX_ACCELERATION = 400.0
HOME_OFFSET = 0.0
HOME_SEQUENCE = 0
HOME = 0.001
[AXIS_X]
MAX_VELOCITY = 60.0
MAX_ACCELERATION = 400.0
# define softlimits for default kinematic (mill)
MIN_LIMIT = -300
MAX_LIMIT = 300
# define softlimits for alternate kinematic (turn)
MIN_LIMIT_TURN = -240
MAX_LIMIT_TURN = 0
[AXIS_Y]
MAX_VELOCITY = 60.0
MAX_ACCELERATION = 400.0
# define softlimits for default kinematic (mill)
MIN_LIMIT = -100
MAX_LIMIT = 100
# define softlimits for alternate kinematic (turn)
MIN_LIMIT_TURN = -100
MAX_LIMIT_TURN = 100
[AXIS_Z]
MAX_VELOCITY = 60.0
MAX_ACCELERATION = 400.0
# define softlimits for default kinematic (mill)
MIN_LIMIT = -240
MAX_LIMIT = 0
# define softlimits for alternate kinematic (turn)
MIN_LIMIT_TURN = -300
MAX_LIMIT_TURN = 300
[AXIS_A]
MAX_VELOCITY = 60.0
MAX_ACCELERATION = 400.0

View File

@@ -0,0 +1,11 @@
T1 P1 X30 Z30 D0.1 I95.000000 J155.000000 Q1
T2 P2 X40 Z40 D0.1 I85.000000 J25.000000 Q2
T3 P3 X50 Z50 D0.1 I275.000000 J335.000000 Q3
T4 P4 X30 Z30 D0.1 I265.000000 J205.000000 Q4
T5 P5 X40 Z40 D0.1 I210.000000 J150.000000 Q5
T6 P6 X50 Z50 D0.1 I120.000000 J60.000000 Q6
T7 P7 X30 Z30 D0.1 I-30.000000 J30.000000 Q7
T8 P8 X40 Z40 D0.1 I240.000000 J300.000000 Q8
T9 P9 X50 Z50 D0.1 Q9
T10 P10 Z50 D5 ;5 mm end mill
T11 P11 Z80 D10

View File

@@ -0,0 +1,34 @@
millturn usage:
For additional information see the README in the millturn folder.
1) startup (after homing) the simulation is in mill mode as configured in millturn.ini (mm-based) with 3 cartesian linear joints (XYZ) and 1 rotary joint (A).
2) pyvcp buttons are provided to switch between mill and turn kinematics. The buttons issue remapped commands M428,M429.
These commands
a) set the motion.switchkins-type pin and
b) force a synchronization using a motion input read command.
c) set softlimits according to values set in millturn.ini [AXIS_X] and [AXIS_Z] section.
3) when set for mill, default assignments are:
x : joint0
y : joint1
z : joint2
a : joint3
so the gcode commands:
'g0x10' moves joint0
'g0z10' moves joint2
4) when set for turn, assignments are:
x : joint2
y : -joint1
z : joint0
a : joint3
so the gcode commands:
'g0x10' moves joint2
'g0z10' moves joint0

View File

@@ -0,0 +1,43 @@
<?xml version='1.0' encoding='UTF-8'?>
<pyvcp>
<vbox>
<relief>"ridge"</relief>
<bd>5</bd>
<label>
<text>"millturn"</text>
<relief>RIDGE</relief>
<bd>3</bd>
</label>
<multilabel>
<legends>["MILL", "TURN"]</legends>
<font>("DejaVu Sans Mono",16)</font>
<bg>"black"</bg>
<fg>"yellow"</fg>
</multilabel>
<button>
<halpin>"mill-button"</halpin>
<text>"MILL"</text>
<bd>3</bd>
</button>
<button>
<halpin>"turn-button"</halpin>
<text>"TURN"</text>
<bd>3</bd>
</button>
</vbox>
<vbox>
<relief>"ridge"</relief>
<bd>5</bd>
<label>
<text>"Vismach"</text>
<relief>RIDGE</relief>
<bd>3</bd>
</label>
<button>
<halpin>"vismach-clear"</halpin>
<text>"Clear Path"</text>
<bd>3</bd>
</button>
</vbox>
</pyvcp>

View File

@@ -0,0 +1,29 @@
;M428 by remap: select mill kins
o<428remap>sub
#<SWITCHKINS_PIN> = 3 ; set N as required: motion.analog-out-0N
#<kinstype> = 0 ; mill
o1 if [exists [#<_hal[motion.switchkins-type]>]]
o1 else
(debug,M428:Missing)
(debug,STOP)
M2
o1 endif
M66 E0 L0 ; force synch
M68 E#<SWITCHKINS_PIN> Q#<kinstype> ; set kinstype value
M128 ; switch limits
G10 L2 P7 X-290 Y0 Z-160 A0 ; reset home offset
G59.1 ; activate home offset
M66 E0 L0 ; force synch
;(debug, M428: mill)
o2 if [[#<_task> EQ 1] AND [#<_hal[motion.switchkins-type]> NE 0]]
(debug,M428: Wrong motion.switchkins-type)
(debug,or missing hal net to analog-out-0x)
(debug,STOP)
M2
o2 else
o2 endif
o<428remap>endsub

View File

@@ -0,0 +1,29 @@
;M429 by remap: select turn kins
o<429remap>sub
#<SWITCHKINS_PIN> = 3 ; set N as required: motion.analog-out-0N
#<kinstype> = 1 ; turn kins
o1 if [exists [#<_hal[motion.switchkins-type]>]]
o1 else
(debug,M429:Missing [RS274NGC]FEATURE==8)
(debug,STOP)
M2
o1 endif
M66 E0 L0 ; force synch
M68 E#<SWITCHKINS_PIN> Q#<kinstype> ; set kinstype value
M129 ; switch limits
G10 L2 P8 X-160 Y0 Z-290 A0 ; reset home offset
G59.2 ; activate home offset
M66 E0 L0 ; force synch
;(debug, M429: turn)
o2 if [[#<_task> EQ 1] AND [#<_hal[motion.switchkins-type]> NE 1]]
(debug,M429:Wrong motion.switchkins-type)
(debug,or missing hal net to analog-out-0x)
(debug,STOP)
M2
o2 else
o2 endif
o<429remap>endsub