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,5 @@
This is the config for the stepper-driven Sherline lathe which is generously on loan from NIST.
It has spindle speed control by analog input, which is driven by software-generated PWM on a parallel port pin. The motors are driven with step/dir and the spindle encoder (for synchronized motion/threading) is counted by software on the parallel port too.
This all makes for a fully functional lathe using simple hardware. The power is all in HAL; the hardware is just a single parallel port interface and simple stepper drivers.

View File

@@ -0,0 +1,212 @@
# EMC controller parameters for generic controller. Make these what you need
# for your system.
# General note: Comments can either be preceded with a # or ; - either is
# acceptable, although # is in keeping with most linux config files.
# Settings with a + at the front of the comment are likely needed to get
# changed by the user.
# Settings with a - at the front are highly unneeded to be changed
###############################################################################
# General section
###############################################################################
[EMC]
#- Version of this INI file
VERSION = 1.1
#+ Name of machine, for use with display, etc.
MACHINE = LinuxCNC-NIST-LATHE-IN
#+ Debug level, 0 means no messages. See src/emc/nml_int/emcglb.h for others
DEBUG = 0
# DEBUG = 0x00000007
# DEBUG = 0x7FFFFFFF
###############################################################################
# Sections for display options
###############################################################################
[DISPLAY]
#+ Name of display program, e.g., axis
DISPLAY = axis
# DISPLAY = tklinuxcnc
# Cycle time, in seconds, that display will sleep between polls
LATHE = 1
CYCLE_TIME = 0.200
#- 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.4
#- Prefix to be used
PROGRAM_PREFIX = ../../nc_files/
#- Introductory graphic
INTRO_GRAPHIC = linuxcnc.gif
INTRO_TIME = 5
# Editor to be used with Axis
#EDITOR = geany
###############################################################################
# Task controller section
###############################################################################
[FILTER]
#No Content
[RS274NGC]
#- File containing interpreter variables
PARAMETER_FILE = nist-lathe.var
###############################################################################
# Motion control section
###############################################################################
[EMCMOT]
#- Name of the motion controller to use (only one exists for nontrivkins)
EMCMOT = motmod
#- Timeout for comm to emcmot, in seconds
COMM_TIMEOUT = 1.0
#+ Base task period, in nanosecs - this is the fastest thread in the machine
BASE_PERIOD = 20000
#- Servo task period, in nanosecs - will be rounded to an int 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.010
###############################################################################
# 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 = nist-lathe.hal
#- list of halcmd commands to execute
# commands are executed in the order in which they appear
#HALCMD = save neta
###############################################################################
# Trajectory planner section
###############################################################################
[HALUI]
#No Content
[TRAJ]
#+ machine specific settings
# COORDINATES = X Y Z R P W
COORDINATES = X Y Z
HOME = 0 0 0
LINEAR_UNITS = inch
ANGULAR_UNITS = degree
DEFAULT_LINEAR_VELOCITY = .5
MAX_LINEAR_VELOCITY = .5
DEFAULT_LINEAR_ACCELERATION = 20.0
MAX_LINEAR_ACCELERATION = 20.0
###############################################################################
# Axes sections
###############################################################################
#+ First axis
[EMCIO]
#- tool table file
TOOL_TABLE = nist-lathe.tbl
[KINS]
KINEMATICS = trivkins
JOINTS = 3
[AXIS_X]
MIN_LIMIT = -0.54
MAX_LIMIT = 1.11
MAX_VELOCITY = 0.383333
MAX_ACCELERATION = 5.0
[JOINT_0]
TYPE = LINEAR
HOME = 0.5
MAX_VELOCITY = 0.383333
# NOTE: the step generator module applies its own limits to
# acceleration and velocity. We have discovered that it needs
# to have a little "headroom" over the accel by the trajectory
# planner, otherwise it can fall slightly behind during accel
# and later overshoot as it catches up. In the long term we
# hope to come up with a clean fix for this problem. In the
# meantime, please set STEPGEN_MAXACCEL below to a few percent
# higher than the regular acceleration limit MAX_ACCELERATION
MAX_ACCELERATION = 5.0
STEPGEN_MAXACCEL = 7.7
BACKLASH = 0.000
SCALE = -8000
OUTPUT_SCALE = 1.000
MIN_LIMIT = -0.54
MAX_LIMIT = 1.11
FERROR = 0.050
MIN_FERROR = 0.010
HOME_OFFSET = .1111
HOME_SEARCH_VEL = -0.5
HOME_LATCH_VEL = -0.025
HOME_USE_INDEX = NO
HOME_IGNORE_LIMITS = NO
HOME_SEQUENCE=1
#+ Second axis
[AXIS_Y]
MIN_LIMIT = -10.0
MAX_LIMIT = 10.0
MAX_VELOCITY = 1.0
MAX_ACCELERATION = 12.0
[JOINT_1]
TYPE = LINEAR
HOME = 0.000
MAX_VELOCITY = 1.0
MAX_ACCELERATION = 12.0
STEPGEN_MAXACCEL = 13.0
BACKLASH = 0.000
SCALE = 4000
OUTPUT_SCALE = 1.000
MIN_LIMIT = -10.0
MAX_LIMIT = 10.0
FERROR = 0.050
MIN_FERROR = 0.010
HOME_OFFSET = 0.0
HOME_SEARCH_VEL = 0.0
HOME_LATCH_VEL = 0.0
HOME_USE_INDEX = NO
HOME_IGNORE_LIMITS = NO
#+ Third axis
[AXIS_Z]
MIN_LIMIT = -0.001
MAX_LIMIT = 4.0
MAX_VELOCITY = 0.433333
MAX_ACCELERATION = 5.0
[JOINT_2]
TYPE = LINEAR
HOME = 1.0
MAX_VELOCITY = 0.433333
MAX_ACCELERATION = 5.0
STEPGEN_MAXACCEL = 5.7
BACKLASH = 0.000
SCALE = -8000
OUTPUT_SCALE = 1.000
MIN_LIMIT = -0.001
MAX_LIMIT = 4.0
FERROR = 0.050
MIN_FERROR = 0.010
HOME_OFFSET = 0.5
HOME_SEARCH_VEL = -0.5
HOME_LATCH_VEL = -0.025
HOME_USE_INDEX = NO
HOME_IGNORE_LIMITS = NO
HOME_SEQUENCE = 0
###############################################################################
# section for main IO controller parameters
###############################################################################

View File

@@ -0,0 +1,245 @@
# HAL config file for MAX NC test machine
#######################################################
# first load all the HAL modules we're going to need
#######################################################
# kinematics
loadrt [KINS]KINEMATICS
# main motion controller module
loadrt [EMCMOT]EMCMOT base_period_nsec=[EMCMOT]BASE_PERIOD servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[KINS]JOINTS
# using steppers....
loadrt stepgen step_type=0,0,0
# I/O thru the parport
loadrt hal_parport cfg="0x0378"
# counting the spindle counter in software
loadrt counter num_chan=1
# misc blocks needed to do fun things
loadrt ddt count=6
# spindle speed pwm
loadrt pwmgen output_type=0
# spindle speed feedback
loadrt lowpass count=1
loadrt mult2 count=1
loadrt scale count=1
#######################################################
# add realtime functions to the threads
# first the high speed thread
#######################################################
# first we read parport inputs
addf parport.0.read base-thread
# update counter
addf counter.update-counters base-thread
# generate step and dir signals
addf stepgen.make-pulses base-thread
# generate spindle pwm
addf pwmgen.make-pulses base-thread
# write to outputs
addf parport.0.write base-thread
# now the servo thread
########################################################
# capture axis and spindle positions
addf stepgen.capture-position servo-thread
addf counter.capture-position servo-thread
# process motion commands coming from user space
addf motion-command-handler servo-thread
# run main motion controller
addf motion-controller servo-thread
# differentiators to make vel and acc signals
addf ddt.0 servo-thread
addf ddt.1 servo-thread
addf ddt.2 servo-thread
addf ddt.3 servo-thread
addf ddt.4 servo-thread
addf ddt.5 servo-thread
# other misc blocks
addf scale.0 servo-thread
addf pwmgen.update servo-thread
# update output info, axis and spindle
addf stepgen.update-freq servo-thread
addf lowpass.0 servo-thread
addf mult2.0 servo-thread
#######################################################
# interconnections
#
# first, the basic stepper machine connections
#######################################################
# connect position commands from motion module to step generator
net Xpos-cmd <= joint.0.motor-pos-cmd
net Xpos-cmd => stepgen.0.position-cmd
net Ypos-cmd <= joint.1.motor-pos-cmd
net Ypos-cmd => stepgen.1.position-cmd
net Zpos-cmd <= joint.2.motor-pos-cmd
net Zpos-cmd => stepgen.2.position-cmd
# connect position feedback from step generators
# to motion module
net Xpos-fb <= stepgen.0.position-fb
net Xpos-fb => joint.0.motor-pos-fb
net Ypos-fb <= stepgen.1.position-fb
net Ypos-fb => joint.1.motor-pos-fb
net Zpos-fb <= stepgen.2.position-fb
net Zpos-fb => joint.2.motor-pos-fb
# connect enable signals for step generators
net Xen <= joint.0.amp-enable-out
net Xen => stepgen.0.enable
net Yen <= joint.1.amp-enable-out
net Yen => stepgen.1.enable
net Zen <= joint.2.amp-enable-out
net Zen => stepgen.2.enable
# connect signals to step pulse generator outputs
net Xstep <= stepgen.0.step
net Xdir <= stepgen.0.dir
net Ystep <= stepgen.1.step
net Ydir <= stepgen.1.dir
net Zstep <= stepgen.2.step
net Zdir <= stepgen.2.dir
#############################################################################
# Spindle Speed
# The spindle goes forward only
net spindle-forward <= spindle.0.forward
net spindle-forward => pwmgen.0.enable
# PID is not used to give closed-loop spindle speed control, because at the
# highest speeds the software-based counter cannot keep up (note: with 'counter',
# it can)
# Instead, this offset and scale have been determined empirically
# -- if these numbers are accurate, then top speed at this gearing is about
# 1200 rpm
#
# gain = 1/1128 ~ .00089
# offset = .07
# PWM Measured RPM
# 25% 200
# 50% 482
# 60% 595
setp scale.0.gain .00089
setp scale.0.offset .07
net spindle-speed-cmd <= spindle.0.speed-out
net spindle-speed-cmd => scale.0.in
net spindle-speed-pwm <= scale.0.out
net spindle-speed-pwm => pwmgen.0.value
# Spindle speed feedback -- spindle-speed-fb-rpm can be metered or scoped
# but beware that at the highest speeds the software-based counter cannot
# keep up, and the speed is estimated incorrectly
# The gain of the lowpass filter is a trade-off: Higher numbers track spindle
# speed better when the speed changes. Lower numbers give a more steady
# estimate of average spindle speed when the speed is nominally constant
setp lowpass.0.gain 0.01
net spindle-speed-fb-raw <= counter.0.velocity
net spindle-speed-fb-raw => lowpass.0.in
net spindle-speed-fb-filtered <= lowpass.0.out
setp mult2.0.in0 60
net spindle-speed-fb-filtered mult2.0.in1
net spindle-speed-fb-rpm mult2.0.out
#############################################################################
# create a signal for the 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
# create a signal for "spindle on"
net spindle_on <= spindle.0.on
# connect physical pins to the signals
net Xstep => parport.0.pin-03-out
net Xdir => parport.0.pin-02-out
net Ystep => parport.0.pin-05-out
net Ydir => parport.0.pin-04-out
net Zstep => parport.0.pin-07-out
net Zdir => parport.0.pin-06-out
# amp enable (active lo)
#linksp Xen => parport.0.pin-01-out
#setp parport.0.pin-01-out-invert 1
# spindle enable
net spindle_on => parport.0.pin-01-out
setp parport.0.pin-01-out-invert 1
net pwm pwmgen.0.pwm => parport.0.pin-14-out
#######################################################
# set scaling and other parameters of the basic machine
# set stepgen module scaling - get values from ini file
setp stepgen.0.position-scale [JOINT_0]SCALE
setp stepgen.1.position-scale [JOINT_1]SCALE
setp stepgen.2.position-scale [JOINT_2]SCALE
# set stepgen module accel limits - get values from ini file
# jmk said to set these to ini value + 5% to avoid stepgen bug
setp stepgen.0.maxaccel [JOINT_0]STEPGEN_MAXACCEL
setp stepgen.1.maxaccel [JOINT_1]STEPGEN_MAXACCEL
setp stepgen.2.maxaccel [JOINT_2]STEPGEN_MAXACCEL
# end of basic machine
net homeswitches <= parport.0.pin-10-in
net homeswitches => joint.0.home-sw-in
net homeswitches => joint.2.home-sw-in
#######################################################
# Beginning of threading-related stuff
#######################################################
# spindle counter
# connect encoder signals to counter counter
# B is not used because it is the counter module, not encoder
net spindle-phase-A => counter.0.phase-A
net spindle-phase-Z => counter.0.phase-Z
net spindle-phase-A <= parport.0.pin-11-in
net spindle-phase-B <= parport.0.pin-12-in
net spindle-phase-Z <= parport.0.pin-13-in
# (that way thread pitches can be straightforward,
# a 20 tpi thread would multiply the counter output
# by 1/20, etc)
setp counter.0.position-scale 1024
# hook up motion controller's spindle indexing pin
net spindle-index-enable <= spindle.0.index-enable
net spindle-index-enable <=> counter.0.index-enable
# report our revolution count to the motion controller
net spindle-pos <= counter.0.position
net spindle-pos => spindle.0.revs
#######################################################
# make vel and accel sigs for testing
#######################################################
# send the position commands thru differentiators to
# generate velocity and accel signals (for testing)
# define the signals, and hook them up
net Xpos-cmd => ddt.0.in
net Xvel <= ddt.0.out
net Xvel => ddt.1.in
net Xacc <= ddt.1.out
net Ypos-cmd => ddt.2.in
net Yvel <= ddt.2.out
net Yvel => ddt.3.in
net Yacc <= ddt.3.out
net Zpos-cmd => ddt.4.in
net Zvel <= ddt.4.out
net Zvel => ddt.5.in
net Zacc <= ddt.5.out

View File

@@ -0,0 +1,9 @@
T1 P1 D0.100000 Z+0.100000 I+95.000000 J+155.000000 Q1 ;
T2 P2 D0.100000 I+85.000000 J+25.000000 Q2 ;
T3 P3 D0.100000 I+275.000000 J+335.000000 Q3 ;
T4 P4 D0.100000 I+265.000000 J+205.000000 Q4 ;
T5 P5 D0.100000 I+210.000000 J+150.000000 Q5 ;
T6 P6 D0.100000 X+0.500000 Z+0.500000 I+120.000000 J+60.000000 Q6 ;
T7 P7 D0.100000 I-30.000000 J+30.000000 Q7 ;
T8 P8 D0.100000 I+240.000000 J+300.000000 Q8 ;
T9 P9 D0.100000 Q9 ;