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,18 @@
This is a simulation of a 2-spindle lathe to demonstrate the multispindle patch.
up to 8 spindles are supported, set by [TRAJ]SPINDLES in the INI and a
num_spindles modparam to motmod. These _must_ agree with each other.
Most spindle-related commands now take an extra "$" word to say which spindle
to apply them to.
Examples
S1000 $1 - set the speed of spindle 1 to 1000
M3 S100 $0 - set the speed of spindle 0 to 100
G33 X10 K1.5 $1 - make a move synchronised to spindle 1.
G33.2 Z-1 K1 $0 - rigid tap synchronised to spindle 0.
M51 P0 $6 - disable speed override on spindle 6. M48 and M49 operate on all.

View File

@@ -0,0 +1,51 @@
# core HAL config file for simulation
# first load all the RT modules that will be needed
# kinematics
loadrt [KINS]KINEMATICS
# motion controller, get name and thread periods from ini file
loadrt [EMCMOT]EMCMOT base_period_nsec=[EMCMOT]BASE_PERIOD servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[KINS]JOINTS num_spindles=[TRAJ]SPINDLES
# load 6 differentiators (for velocity and accel signals
loadrt ddt names=ddt_x,ddt_xv,ddt_y,ddt_yv,ddt_z,ddt_zv
# load additional blocks
loadrt hypot names=vel_xy,vel_xyz
# add motion controller functions to servo thread
addf motion-command-handler servo-thread
addf motion-controller servo-thread
# link the differentiator functions into the code
addf ddt_x servo-thread
addf ddt_xv servo-thread
addf ddt_y servo-thread
addf ddt_yv servo-thread
addf ddt_z servo-thread
addf ddt_zv servo-thread
addf vel_xy servo-thread
addf vel_xyz servo-thread
# create HAL signals for position commands from motion module
# loop position commands back to motion module feedback
net Xpos joint.0.motor-pos-cmd => joint.0.motor-pos-fb ddt_x.in
net Ypos joint.1.motor-pos-cmd => joint.1.motor-pos-fb ddt_y.in
net Zpos joint.2.motor-pos-cmd => joint.2.motor-pos-fb ddt_z.in
# send the position commands thru differentiators to
# generate velocity and accel signals
net Xvel ddt_x.out => ddt_xv.in vel_xy.in0
net Xacc <= ddt_xv.out
net Yvel ddt_y.out => ddt_yv.in vel_xy.in1
net Yacc <= ddt_yv.out
net Zvel ddt_z.out => ddt_zv.in vel_xyz.in0
net Zacc <= ddt_zv.out
# Cartesian 2- and 3-axis velocities
net XYvel vel_xy.out => vel_xyz.in1
net XYZvel <= vel_xyz.out
# estop loopback
net estop-loop iocontrol.0.user-enable-out iocontrol.0.emc-enable-in
# create signals for tool loading loopback
net tool-prep-loop iocontrol.0.tool-prepare iocontrol.0.tool-prepared
net tool-change-loop iocontrol.0.tool-change iocontrol.0.tool-changed

View File

@@ -0,0 +1,109 @@
# counting the spindle encoder in software
loadrt encoder names=encoder_0,encoder_1
# simulate the encoder
loadrt sim_encoder names=sim_encoder_0,sim_encoder_1
loadrt limit2 names=limit_speed
addf limit_speed servo-thread
#######################################################
# Beginning of threading related stuff
#######################################################
# spindle speed control
net spindle.0.cmd spindle.0.speed-out => sim_encoder_0.speed
net spindle.1.cmd spindle.1.speed-out => sim_encoder_1.speed
# simulate spindle mass
setp limit_speed.maxv 500.0 # rpm/second
# spindle encoder 0
# connect encoder signals to encoder counter
net spindle-phase-A sim_encoder_0.phase-A => encoder_0.phase-A
net spindle-phase-B sim_encoder_0.phase-B => encoder_0.phase-B
net spindle-phase-Z sim_encoder_0.phase-Z => encoder_0.phase-Z
# assume 120 ppr = 480 counts/rev for the spindle
setp sim_encoder_0.ppr 120
# iocontrol output is in rpm, but sim-encoder speed is rps
setp sim_encoder_0.scale 60
# scale encoder output to read in revolutions
# (that way thread pitches can be straightforward,
# a 20 tpi thread would multiply the encoder output
# by 1/20, etc)
setp encoder_0.position-scale 480
# encoder reset control
# hook up motion controller's sync output
net spindle-index-enable spindle.0.index-enable <=> encoder_0.index-enable
# report our revolution count to the motion controller
net spindle.0.pos encoder_0.position => spindle.0.revs
# spindle encoder 1
# connect encoder signals to encoder counter
net spindle-phase-A1 sim_encoder_1.phase-A => encoder_1.phase-A
net spindle-phase-B1 sim_encoder_1.phase-B => encoder_1.phase-B
net spindle-phase-Z1 sim_encoder_1.phase-Z => encoder_1.phase-Z
# assume 120 ppr = 480 counts/rev for the spindle
setp sim_encoder_1.ppr 120
# iocontrol output is in rpm, but sim-encoder speed is rps
setp sim_encoder_1.scale 60
# scale encoder output to read in revolutions
# (that way thread pitches can be straightforward,
# a 20 tpi thread would multiply the encoder output
# by 1/20, etc)
setp encoder_1.position-scale 480
# encoder reset control
# hook up motion controller's sync output
net spindle-index-enable spindle.1.index-enable <=> encoder_0.index-enable
# report our revolution count to the motion controller
net spindle.1.pos encoder_1.position => spindle.1.revs
# for spindle velocity estimate
loadrt lowpass names=lowpass_velocity.0,lowpass_velocity.1
loadrt scale names=scale_to_rpm.0,scale_to_rpm.1
net spindle-rps-raw.0 encoder_0.velocity lowpass_velocity.0.in
net spindle-rps-filtered.0 lowpass_velocity.0.out scale_to_rpm.0.in spindle.0.speed-in
net spindle-rpm-filtered.0 scale_to_rpm.0.out
setp scale_to_rpm.0.gain 60
setp lowpass_velocity.0.gain .07
addf lowpass_velocity.0 servo-thread
addf scale_to_rpm.0 servo-thread
net spindle-rps-raw.1 encoder_1.velocity lowpass_velocity.1.in
net spindle-rps-filtered.1 lowpass_velocity.1.out scale_to_rpm.1.in spindle.1.speed-in
net spindle-rpm-filtered.1 scale_to_rpm.1.out
setp scale_to_rpm.1.gain 60
setp lowpass_velocity.1.gain .07
addf lowpass_velocity.1 servo-thread
addf scale_to_rpm.1 servo-thread
# for at-speed detection
loadrt near names=near_speed.0,near_speed.1
addf near_speed.0 servo-thread
setp near_speed.0.scale 1.1
setp near_speed.0.difference 10
net spindle.0.cmd => near_speed.0.in1
net spindle-rpm-filtered.0 => near_speed.0.in2
net spindle-at-speed.0 near_speed.0.out spindle.0.at-speed
net spindle.0-fwd <= spindle.0.forward
addf near_speed.1 servo-thread
setp near_speed.1.scale 1.1
setp near_speed.1.difference 10
net spindle.1.cmd => near_speed.1.in1
net spindle-rpm-filtered.1 => near_speed.1.in2
net spindle-at-speed.1 near_speed.1.out spindle.1.at-speed
net spindle.1-fwd <= spindle.1.forward
addf encoder.capture-position servo-thread
addf sim-encoder.update-speed servo-thread
addf sim-encoder.make-pulses base-thread
addf encoder.update-counters base-thread

View File

@@ -0,0 +1,195 @@
# EMC controller parameters for a simulated machine.
# General note: Comments can either be preceded with a # or ; - either is
# acceptable, although # is in keeping with most linux config files.
# General section -------------------------------------------------------------
[EMC]
# Version of this INI file
VERSION = 1.1
# Name of machine, for use with display, etc.
MACHINE = LinuxCNC-HAL-SIM-LATHE
# Debug level, 0 means no messages. See src/emc/nml_int/emcglb.h for others
# DEBUG = 0x7FFFFFFF
DEBUG = 0
# Sections for display options ------------------------------------------------
[DISPLAY]
# Name of display program, e.g., xlinuxcnc
DISPLAY = axis
PYVCP = lathe.xml
LATHE = 1
#EDITOR = geany
# Cycle time, in seconds, that display will sleep between polls
CYCLE_TIME = 0.100
# Path to help file
HELP_FILE = doc/help.txt
# Initial display setting for position, RELATIVE or MACHINE
POSITION_OFFSET = RELATIVE
# Initial display setting for position, COMMANDED or ACTUAL
POSITION_FEEDBACK = ACTUAL
# Highest value that will be allowed for feed override, 1.0 = 100%
MAX_FEED_OVERRIDE = 1.2
MAX_SPINDLE_OVERRIDE = 1.0
# Prefix to be used
PROGRAM_PREFIX = ../../nc_files
OPEN_FILE = ../../nc_files/examples/lathe_pawn.ngc
# Introductory graphic
INTRO_GRAPHIC = linuxcnc.gif
INTRO_TIME = 5
USER_COMMAND_FILE = ~/.axisrc
[FILTER]
PROGRAM_EXTENSION = .png,.gif,.jpg Grayscale Depth Image
PROGRAM_EXTENSION = .py Python Script
png = image-to-gcode
gif = image-to-gcode
jpg = image-to-gcode
py = python3
# Task controller section -----------------------------------------------------
[RS274NGC]
# File containing interpreter variables
PARAMETER_FILE = sim-lathe.var
# Motion control section ------------------------------------------------------
[EMCMOT]
EMCMOT = motmod
# Timeout for comm to emcmot, in seconds
COMM_TIMEOUT = 1.0
# Interval between tries to emcmot, in seconds
COMM_WAIT = 0.010
# Base task period, in nano-seconds - this is the fastest thread in the machine
BASE_PERIOD = 50000
# Servo task period, in nano-seconds - will be rounded to an integer multiple
# of BASE_PERIOD
SERVO_PERIOD = 1000000
# Hardware Abstraction Layer section --------------------------------------------------
[TASK]
# Name of task controller program, e.g., milltask
TASK = milltask
# Cycle time, in seconds, that task controller will sleep between polls
CYCLE_TIME = 0.001
# Part program interpreter section --------------------------------------------
[HAL]
# The run script first uses halcmd to execute any HALFILE
# files, and then to execute any individual HALCMD commands.
#
# list of hal config files to run through halcmd
# files are executed in the order in which they appear
HALFILE = core_sim.hal
HALFILE = axis_manualtoolchange.hal
HALFILE = simulated_home.hal
HALFILE = lathe.hal
# list of halcmd commands to execute
# commands are executed in the order in which they appear
#HALCMD = save neta
# Single file that is executed after the GUI has started. Only supported by
# AXIS at this time (only AXIS creates a HAL component of its own)
POSTGUI_HALFILE = lathe_postgui.hal
[TRAJ]
SPINDLES = 2
COORDINATES = X Z
LINEAR_UNITS = inch
ANGULAR_UNITS = degree
CYCLE_TIME = 0.010
DEFAULT_VELOCITY = 1.0
MAX_LINEAR_VELOCITY = 3.333334
DEFAULT_ACCELERATION = 20.0
MAX_ACCELERATION = 20.0
NO_FORCE_HOMING = 1
# Axes sections ---------------------------------------------------------------
# First axis
[EMCIO]
# tool table file
TOOL_TABLE = lathe.tbl
TOOL_CHANGE_POSITION = 2 0 1
TOOL_CHANGE_WITH_SPINDLE_ON = 1
[KINS]
KINEMATICS = trivkins
JOINTS = 3
[AXIS_X]
MIN_LIMIT = -10.0
MAX_LIMIT = 10.0
MAX_VELOCITY = 3.333334
MAX_ACCELERATION = 20.0
[JOINT_0]
TYPE = LINEAR
HOME = 0.000
MAX_VELOCITY = 3.333334
MAX_ACCELERATION = 20.0
BACKLASH = 0.000
INPUT_SCALE = 4000
OUTPUT_SCALE = 1.000
MIN_LIMIT = -10.0
MAX_LIMIT = 10.0
FERROR = 0.050
MIN_FERROR = 0.010
HOME_OFFSET = 1.0
HOME_SEARCH_VEL = 5.0
HOME_LATCH_VEL = 1.0
HOME_USE_INDEX = NO
HOME_IGNORE_LIMITS = NO
HOME_SEQUENCE = 0
[AXIS_Z]
MIN_LIMIT = -2.0
MAX_LIMIT = 4.0
MAX_VELOCITY = 3.333334
MAX_ACCELERATION = 20.0
[JOINT_1]
# JOINT_1: not used, home immediately:
HOME_SEARCH_VEL = 0
HOME_LATCH_VEL = 0
HOME_USE_INDEX = NO
HOME_SEQUENCE = 0
[JOINT_2]
TYPE = LINEAR
HOME = 0.0
MAX_VELOCITY = 3.333334
MAX_ACCELERATION = 20.0
BACKLASH = 0.000
INPUT_SCALE = 4000
OUTPUT_SCALE = 1.000
MIN_LIMIT = -2.0
MAX_LIMIT = 4.0
FERROR = 0.050
MIN_FERROR = 0.010
HOME_OFFSET = 1.0
HOME_SEARCH_VEL = 5.0
HOME_LATCH_VEL = 1.0
HOME_USE_INDEX = NO
HOME_IGNORE_LIMITS = NO
HOME_SEQUENCE = 1
# section for main IO controller parameters -----------------------------------

View File

@@ -0,0 +1,31 @@
<?xml version='1.0' encoding='UTF-8'?>
<pyvcp>
<vbox>
<vbox>
<label>
<text>"Spindle 0 speed:"</text>
</label>
<bar>
<halpin>"spindle.0.speed"</halpin>
<max_>5000</max_>
</bar>
<hbox>
<led halpin="spindle.0.at-speed" on_color="yellow" off_color="black"/>
<label text="At Speed"/>
</hbox>
</vbox>
<vbox>
<label>
<text>"Spindle 1 speed:"</text>
</label>
<bar>
<halpin>"spindle.1.speed"</halpin>
<max_>5000</max_>
</bar>
<hbox>
<led halpin="spindle.1.at-speed" on_color="yellow" off_color="black"/>
<label text="At Speed"/>
</hbox>
</vbox>
</vbox>
</pyvcp>

View File

@@ -0,0 +1,4 @@
net spindle-rpm-filtered.0 => pyvcp.spindle.0.speed
net spindle-at-speed.0 => pyvcp.spindle.0.at-speed
net spindle-rpm-filtered.1 => pyvcp.spindle.1.speed
net spindle-at-speed.1 => pyvcp.spindle.1.at-speed